From 1cb5e2d3ed143a08d30401c1f6f0ef1c11bd3d87 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 23 Nov 2019 10:01:24 +1300 Subject: [PATCH] [REF] return determination of whether to show expired fields to the calling function As part of my efforts to ensure we are consistency creating valid transactions I'm trying to sort out the way we calculate amounts to be re-usable from tests but I feel stymied at every turn by spaghetti code. This unravels a small piece --- CRM/Event/Form/ParticipantFeeSelection.php | 14 +++++++++++++- CRM/Event/Form/Registration.php | 15 +++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CRM/Event/Form/ParticipantFeeSelection.php b/CRM/Event/Form/ParticipantFeeSelection.php index a9e0233231e5..4172825564e2 100644 --- a/CRM/Event/Form/ParticipantFeeSelection.php +++ b/CRM/Event/Form/ParticipantFeeSelection.php @@ -136,6 +136,11 @@ public function setDefaultValues() { return $defaults; } + /** + * Build form. + * + * @throws \CRM_Core_Exception + */ public function buildQuickForm() { $statuses = CRM_Event_PseudoConstant::participantStatus(); @@ -152,7 +157,8 @@ public function buildQuickForm() { //retrieve custom information $this->_values = []; - CRM_Event_Form_Registration::initEventFee($this, $event['id']); + + CRM_Event_Form_Registration::initEventFee($this, $event['id'], $this->_action !== CRM_Core_Action::UPDATE); CRM_Event_Form_Registration_Register::buildAmount($this, TRUE); if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $this->_values))) { @@ -217,6 +223,12 @@ public static function formRule($fields, $files, $self) { return $errors; } + /** + * Post process form. + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + */ public function postProcess() { $params = $this->controller->exportValues($this->_name); diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 87c8e7b7cbf7..a4e3be15a7b8 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -600,10 +600,12 @@ public function buildCustom($id, $name, $viewOnly = FALSE) { * * @param CRM_Core_Form $form * @param int $eventID + * @param bool $includeExpiredFields + * See CRM-16456. * * @throws Exception */ - public static function initEventFee(&$form, $eventID) { + public static function initEventFee(&$form, $eventID, $includeExpiredFields = TRUE) { // get price info // retrive all active price set fields. @@ -612,20 +614,13 @@ public static function initEventFee(&$form, $eventID) { $discountId = $form->_discountId; } - //CRM-16456 get all price field including expired one. - $getAllPriceField = TRUE; - $className = CRM_Utils_System::getClassName($form); - if ($className == 'CRM_Event_Form_ParticipantFeeSelection' && $form->_action == CRM_Core_Action::UPDATE) { - $getAllPriceField = FALSE; - } - if ($discountId) { $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); - CRM_Price_BAO_PriceSet::initSet($form, 'civicrm_event', $getAllPriceField, $priceSetId); + CRM_Price_BAO_PriceSet::initSet($form, 'civicrm_event', $includeExpiredFields, $priceSetId); } else { $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID); - CRM_Price_BAO_PriceSet::initSet($form, 'civicrm_event', $getAllPriceField, $priceSetId); + CRM_Price_BAO_PriceSet::initSet($form, 'civicrm_event', $includeExpiredFields, $priceSetId); } if (property_exists($form, '_context') && ($form->_context == 'standalone'