Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event#30 - don't allow multiple waitlist registrations #16358

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,8 @@ public static function checkRegistration($fields, $form, $isAdditional = FALSE)
}
$participant->is_test = 0;
$participant->find();
$statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
// Event#30 - Anyone whose status type has `is_counted` OR is on the waitlist should be considered as registered.
$statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1') + CRM_Event_PseudoConstant::participantStatus(NULL, "name = 'On waitlist'");
while ($participant->fetch()) {
if (array_key_exists($participant->status_id, $statusTypes)) {
if (!$isAdditional && !$form->_values['event']['allow_same_participant_emails']) {
Expand All @@ -1196,8 +1197,9 @@ public static function checkRegistration($fields, $form, $isAdditional = FALSE)
if ($form->_pcpId) {
$registerUrl .= '&pcpId=' . $form->_pcpId;
}

$status = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've received this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', [1 => $registerUrl]);
$registrationType = (CRM_Event_PseudoConstant::getKey('CRM_Event_BAO_Participant', 'participant_status_id', 'On waitlist') == $participant->status_id) ? 'waitlisted' : 'registered';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this late, but this is a good example of an incorrect use of "ts". It's impossible to translate a string like this, even if the individual words were in "ts" (because of grammar).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$status = ts("It looks like you are already %1 for this event. If you want to change your registration, or you feel that you've received this message in error, please contact the site administrator.", [1 => $registrationType]);
$status .= ' ' . ts('You can also <a href="%1">register another participant</a>.', [1 => $registerUrl]);
CRM_Core_Session::singleton()->setStatus($status, ts('Oops.'), 'alert');
$url = CRM_Utils_System::url('civicrm/event/info',
"reset=1&id={$form->_values['event']['id']}&noFullMsg=true"
Expand Down
40 changes: 40 additions & 0 deletions tests/phpunit/CRM/Event/Form/Registration/RegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,44 @@ public function testMinValueForPriceSet() {
$this->checkArrayEquals($expectedResult, $errors);
}

/**
* event#30
*/
public function testDoubleWaitlistRegistration() {
// By default, waitlist participant statuses are disabled (which IMO is poor UX).
$sql = "UPDATE civicrm_participant_status_type SET is_active = 1";
CRM_Core_DAO::executeQuery($sql);

// Create an event, fill its participant slots.
$event = $this->eventCreate([
'has_waitlist' => 1,
'max_participants' => 1,
'start_date' => 20351021,
'end_date' => 20351023,
'registration_end_date' => 20351015,
]);
$this->participantCreate(['event_id' => $event['id']]);

// Add someone to the waitlist.
$waitlistContact = $this->individualCreate();

$firstWaitlist = $this->participantCreate(['event_id' => $event['id'], 'contact_id' => $waitlistContact, 'status_id' => 'On waitlist']);

// We should now have two participants.
$this->callAPISuccessGetCount('Participant', ['event_id' => $event['id']], 2);

$form = new CRM_Event_Form_Registration_Register();
$form->controller = new CRM_Core_Controller();
$form->set('id', $event['id']);
$form->set('cid', $waitlistContact);
// We SHOULD get an error when double registering a waitlisted user.
try {
$form->preProcess();
}
catch (CRM_Core_Exception_PrematureExitException $e) {
return;
}
$this->fail('Waitlisted users shouldn\'t be allowed to re-register.');
}

}