Skip to content

Commit

Permalink
refs #24151, add hook and change event check registration limit rule
Browse files Browse the repository at this point in the history
  • Loading branch information
jimyhuang committed Nov 27, 2018
1 parent b248b99 commit c0bb58d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 48 deletions.
4 changes: 2 additions & 2 deletions CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ static function showHideRegistrationLink($values) {
if ($roleId = CRM_Utils_Array::value('default_role_id', $values['event'])) {
$params['role_id'] = $roleId;
}
$alreadyRegistered = self::checkRegistration($params);
$alreadyRegistered = self::alreadyRegistered($params);
}

if (CRM_Utils_Array::value('allow_same_participant_emails', $values['event']) ||
Expand All @@ -1770,7 +1770,7 @@ static function showHideRegistrationLink($values) {
* @return boolean $alreadyRegistered true/false
* @access public
*/
function checkRegistration($params) {
function alreadyRegistered($params) {
$alreadyRegistered = FALSE;
if (!CRM_Utils_Array::value('contact_id', $params)) {
return $alreadyRegistered;
Expand Down
9 changes: 2 additions & 7 deletions CRM/Event/Form/Registration/AdditionalParticipant.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,7 @@ static function formRule($fields, $files, $self) {
require_once 'CRM/Event/Form/Registration/Register.php';
$isRegistered = CRM_Event_Form_Registration_Register::checkRegistration($fields, $self, TRUE);
if ($isRegistered) {
if ($self->_values['event']['allow_same_participant_emails']) {
$errors['_qf_default'] = ts('A person is already registered for this event.');
}
else {
$errors["email-{$self->_bltID}"] = ts('A person with this email address is already registered for this event.');
}
$errors['_qf_default'] = ts('A person is already registered for this event.');
}

//get the complete params.
Expand Down Expand Up @@ -498,7 +493,7 @@ public function postProcess() {

if (!$this->_allowConfirmation) {
// check if the participant is already registered
$params['contact_id'] = CRM_Event_Form_Registration_Register::checkRegistration($params, $this, TRUE, TRUE);
$params['contact_id'] = CRM_Event_Form_Registration_Register::getRegistrationContactID($params, $this, TRUE);
}

// if waiting is enabled
Expand Down
72 changes: 34 additions & 38 deletions CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ public function postProcess() {
$params['is_primary'] = 1;
if (!$this->_allowConfirmation) {
// check if the participant is already registered
$params['contact_id'] = self::checkRegistration($params, $this, FALSE, TRUE);
$params['contact_id'] = self::getRegistrationContactID($params, $this, FALSE);
}

if (CRM_Utils_Array::value('image_URL', $params)) {
Expand Down Expand Up @@ -1406,54 +1406,32 @@ public function processRegistration($params, $contactID = NULL) {
*
* @param array $fields the input form values(anonymous user)
* @param array $self event data
* @param boolean $isAdditional if it's additional participant
*
* @return void
* @access public
*/
function checkRegistration($fields, &$self, $isAdditional = FALSE, $returnContactId = FALSE) {
// CRM-3907, skip check for preview registrations
// CRM-4320 participant need to walk wizard
if (!$returnContactId && ($self->_mode == 'test' || $self->_allowConfirmation)) {
function checkRegistration($fields, &$self, $isAdditional = FALSE) {
if ($self->_mode == 'test') {
return FALSE;
}

$contactID = NULL;
$session = CRM_Core_Session::singleton();
if (!$isAdditional) {
$contactID = parent::getContactID();
}

if (!$contactID &&
is_array($fields) &&
!empty($fields)
) {

//CRM-6996
//as we are allowing w/ same email address,
//lets check w/ other contact params.
$params = $fields;
$contactID = self::getRegistrationContactID($fields, $self, $isAdditional);

// respect dedupe rule for all registeration. pervent too email centeralized registeration
// unset email from dedupe params for 'additional participant wizard' case only
if (isset($params["email-{$self->_bltID}"]) && $isAdditional) {
unset($params["email-{$self->_bltID}"]);
}
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');

// disable permission based on cache since event registration is public page/feature.
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
$contactID = CRM_Utils_Array::value(0, $ids);
// implement hook for change registrion check
CRM_Utils_Hook::checkRegistration($contactID, $fields, $self, $isAdditional, $result);
if (!empty($result)) {
return $result;
}

if ($returnContactId) {
// CRM-7377
// return contactID if contact already exists
return $contactID;
// skip check when confirm by mail link
if ($self->_allowConfirmation) {
return FALSE;
}

if ($contactID) {
$session = CRM_Core_Session::singleton();

// check if contact exists but email not the same
if (isset($fields['_qf_default']) && $fields['cms_create_account']) {
$dao = new CRM_Core_DAO_UFMatch();
Expand Down Expand Up @@ -1494,15 +1472,33 @@ function checkRegistration($fields, &$self, $isAdditional = FALSE, $returnContac
}

if ($isAdditional) {
$status = ts("Oops. It looks like this participant is already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.");
$session->setStatus($status);
return $participant->id;
}
}
}
}
}

public static function getRegistrationContactID($fields, $self, $isAdditional){
$contactID = NULL;
if (!$isAdditional) {
$contactID = $self->getContactID();
}
if (!$contactID && is_array($fields) && !empty($fields)) {
//CRM-6996
//as we are allowing w/ same email address,
//lets check w/ other contact params.
$params = $fields;
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');

// disable permission based on cache since event registration is public page/feature.
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
$contactID = CRM_Utils_Array::value(0, $ids);
}
return $contactID;
}

public function getTitle() {
return ts('Register for Event');
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Page/EventInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function run() {
'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']),
);

if (CRM_Event_BAO_Event::checkRegistration($params)) {
if (CRM_Event_BAO_Event::alreadyRegistered($params)) {
$statusMessage = ts("Oops. It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.");
}
elseif ($hasWaitingList) {
Expand Down
15 changes: 15 additions & 0 deletions CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,5 +1015,20 @@ static function validateTaxReceipt($contributionId, &$receipt) {
2, &$contributionId, &$receipt, &$null, &$null, &$null, 'civicrm_validateTaxReceipt'
));
}

/**
* Add registration validation here
*
* @param $contributionId
*/
static function checkRegistration($contactID, $fields, $self, $isAdditional, &$result){
$config = CRM_Core_Config::singleton();
require_once (str_replace('_', DIRECTORY_SEPARATOR, $config->userHookClass) . '.php');
$null = &CRM_Core_DAO::$_nullObject;

return call_user_func_array(array($config->userHookClass, 'invoke'), array(
5, &$contactID, &$fields, &$self, &$isAdditional, &$result, 'civicrm_checkRegistration'
));
}
}

0 comments on commit c0bb58d

Please sign in to comment.