Skip to content

Commit

Permalink
Merge pull request #16358 from MegaphoneJon/event-30
Browse files Browse the repository at this point in the history
event#30 - don't allow multiple waitlist registrations
  • Loading branch information
yashodha authored Jan 24, 2020
2 parents 864483f + ed66ac4 commit af58774
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
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';
$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.');
}

}

0 comments on commit af58774

Please sign in to comment.