From 7b64dc81c27149fc83b6416ada19043f245d5d59 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 29 Mar 2017 09:53:01 +1300 Subject: [PATCH] Towards CRM-20328 extract dedupe code to function --- CRM/Event/Form/Registration/Register.php | 60 ++++++++++++++---------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 6bc629a735..cfc52eb683 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -79,6 +79,41 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { */ public $_paymentFields = array(); + /** + * Get the contact id for the registration. + * + * @param array $fields + * @param CRM_Core_Form $self + * @param bool $isAdditional + * + * @return int|null + */ + protected static function getRegistrationContactID($fields, $self, $isAdditional) { + + $contactID = NULL; + if (!$isAdditional) { + $contactID = $self->getContactID(); + } + if (!$contactID && is_array($fields) && $fields) { + + //CRM-14134 use Unsupervised rule for everyone + $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual'); + + // disable permission based on cache since event registration is public page/feature. + $dedupeParams['check_permission'] = FALSE; + + // find event dedupe rule + if (CRM_Utils_Array::value('dedupe_rule_group_id', $self->_values['event'], 0) > 0) { + $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'Unsupervised', array(), $self->_values['event']['dedupe_rule_group_id']); + } + else { + $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'Unsupervised'); + } + $contactID = CRM_Utils_Array::value(0, $ids); + } + return $contactID; + } + /** * Set variables up before form is built. */ @@ -1157,30 +1192,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { return FALSE; } - $contactID = NULL; - $session = CRM_Core_Session::singleton(); - if (!$isAdditional) { - $contactID = $self->getContactID(); - } - - if (!$contactID && is_array($fields) && $fields) { - - //CRM-14134 use Unsupervised rule for everyone - $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual'); - - // disable permission based on cache since event registration is public page/feature. - $dedupeParams['check_permission'] = FALSE; - - // find event dedupe rule - if (CRM_Utils_Array::value('dedupe_rule_group_id', $self->_values['event'], 0) > 0) { - $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'Unsupervised', array(), $self->_values['event']['dedupe_rule_group_id']); - } - else { - $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'Unsupervised'); - } - $contactID = CRM_Utils_Array::value(0, $ids); - - } + $contactID = self::getRegistrationContactID($fields, $self, $isAdditional); if ($returnContactId) { // CRM-7377 -- 2.25.1