From 8535cf1ca1962c9623d7c16acdc932f3bceabfcb Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 14 Sep 2020 20:18:09 +1200 Subject: [PATCH] [REF] Start the process of separating the search action from the participant form. A lot code nastiness stems from the overloading of the participant registration form with the search task to register multiples. A more logical structure would be some shared functionality but separate classes. This starts that process, but with only the one property now separated to be a class property rather than a derived one. Later efforts can disentangle which functionality belongs to which class --- CRM/Contact/Task.php | 2 +- CRM/Event/Form/EventFees.php | 3 +- CRM/Event/Form/Participant.php | 11 ++--- CRM/Event/Form/Registration.php | 2 +- CRM/Event/Form/Registration/Register.php | 7 ++-- CRM/Event/Form/Task/Register.php | 40 +++++++++++++++++++ CRM/Price/BAO/PriceSet.php | 2 +- .../CRM/Event/Form/Task/RegisterTest.php | 22 ++++++++++ 8 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 CRM/Event/Form/Task/Register.php create mode 100644 tests/phpunit/CRM/Event/Form/Task/RegisterTest.php diff --git a/CRM/Contact/Task.php b/CRM/Contact/Task.php index 06696a2953..8832759e3c 100644 --- a/CRM/Contact/Task.php +++ b/CRM/Contact/Task.php @@ -234,7 +234,7 @@ class CRM_Contact_Task extends CRM_Core_Task { if (CRM_Core_Permission::access('CiviEvent')) { self::$_tasks[self::ADD_EVENT] = array( 'title' => ts('Register participants for event'), - 'class' => 'CRM_Event_Form_Participant', + 'class' => 'CRM_Event_Form_Task_Register', ); } diff --git a/CRM/Event/Form/EventFees.php b/CRM/Event/Form/EventFees.php index 14be8ec5f6..2b15c288ce 100644 --- a/CRM/Event/Form/EventFees.php +++ b/CRM/Event/Form/EventFees.php @@ -159,6 +159,7 @@ class CRM_Event_Form_EventFees { if (in_array(get_class($form), [ 'CRM_Event_Form_Participant', + 'CRM_Event_Form_Task_Register', 'CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant', ] @@ -173,7 +174,7 @@ class CRM_Event_Form_EventFees { foreach ($form->_priceSet['fields'] as $key => $val) { foreach ($val['options'] as $keys => $values) { if ($values['is_default']) { - if (get_class($form) != 'CRM_Event_Form_Participant' && !empty($values['is_full'])) { + if (!in_array(get_class($form), ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register']) && !empty($values['is_full'])) { continue; } diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 5bf815072a..5697924b87 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -99,11 +99,14 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment /** * Are we operating in "single mode", i.e. adding / editing only - * one participant record, or is this a batch add operation + * one participant record, or is this a batch add operation. + * + * Note the goal is to disentangle all the non-single stuff + * to CRM_Event_Form_Task_Register and discontinue this param. * * @var bool */ - public $_single = FALSE; + public $_single = TRUE; /** * If event is paid or unpaid. @@ -337,8 +340,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment //check the mode when this form is called either single or as //search task action - if ($this->_id || $this->_contactId || $this->_context == 'standalone') { - $this->_single = TRUE; + if ($this->_single) { $this->assign('urlPath', 'civicrm/contact/view/participant'); if (!$this->_id && !$this->_contactId) { $breadCrumbs = [ @@ -379,7 +381,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment } CRM_Contact_Form_Task::preProcessCommon($this); - $this->_single = FALSE; $this->_contactId = NULL; //set ajax path, this used for custom data building diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 4b2692e67b..2d481e486e 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -657,7 +657,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { } } if ($isPaidEvent && empty($form->_values['fee'])) { - if (CRM_Utils_System::getClassName($form) != 'CRM_Event_Form_Participant') { + if (!in_array(CRM_Utils_System::getClassName($form), ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register'])) { CRM_Core_Error::statusBounce(ts('No Fee Level(s) or Price Set is configured for this event.
Click CiviEvent >> Manage Event >> Configure >> Event Fees to configure the Fee Level(s) or Price Set for this event.', [1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId)])); } } diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 88cea65ebd..5d39b2a126 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -577,6 +577,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { if (CRM_Utils_Array::value('visibility', $field) == 'public' || (CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE) || $className == 'CRM_Event_Form_Participant' || + $className === 'CRM_Event_Form_Task_Register' || $className == 'CRM_Event_Form_ParticipantFeeSelection' ) { $fieldId = $field['id']; @@ -589,7 +590,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { //user might modified w/ hook. $options = $field['options'] ?? NULL; - $formClasses = ['CRM_Event_Form_Participant', 'CRM_Event_Form_ParticipantFeeSelection']; + $formClasses = ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register', 'CRM_Event_Form_ParticipantFeeSelection']; if (!is_array($options)) { continue; @@ -636,7 +637,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { //CRM-7632, CRM-6201 $totalAmountJs = NULL; - if ($className == 'CRM_Event_Form_Participant') { + if ($className == 'CRM_Event_Form_Participant' || $className === 'CRM_Event_Form_Task_Register') { $totalAmountJs = ['onClick' => "fillTotalAmount(" . $fee['value'] . ")"]; } @@ -755,7 +756,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } //ignore option full for offline registration. - if ($className == 'CRM_Event_Form_Participant') { + if ($className == 'CRM_Event_Form_Participant' || $className === 'CRM_Event_Form_Task_Register') { $optionFullIds = []; } diff --git a/CRM/Event/Form/Task/Register.php b/CRM/Event/Form/Task/Register.php new file mode 100644 index 0000000000..af434f4fd4 --- /dev/null +++ b/CRM/Event/Form/Task/Register.php @@ -0,0 +1,40 @@ +_id; } else { diff --git a/tests/phpunit/CRM/Event/Form/Task/RegisterTest.php b/tests/phpunit/CRM/Event/Form/Task/RegisterTest.php new file mode 100644 index 0000000000..8af60e2d2f --- /dev/null +++ b/tests/phpunit/CRM/Event/Form/Task/RegisterTest.php @@ -0,0 +1,22 @@ +getFormObject('CRM_Event_Form_Task_Register'); + $this->assertEquals(FALSE, $form->_single); + } + +} -- 2.25.1