[REF] return determination of whether to show expired fields to the calling function
authoreileen <emcnaughton@wikimedia.org>
Fri, 22 Nov 2019 21:01:24 +0000 (10:01 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 22 Nov 2019 21:01:24 +0000 (10:01 +1300)
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
CRM/Event/Form/Registration.php

index a9e0233231e58b5a4561653ba681b91d88c782ad..4172825564e27bd68c5677e093e9bfa2eb171e9c 100644 (file)
@@ -136,6 +136,11 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
     return $defaults;
   }
 
+  /**
+   * Build form.
+   *
+   * @throws \CRM_Core_Exception
+   */
   public function buildQuickForm() {
 
     $statuses = CRM_Event_PseudoConstant::participantStatus();
@@ -152,7 +157,8 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
 
     //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 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
     return $errors;
   }
 
+  /**
+   * Post process form.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
+   */
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
 
index 87c8e7b7cbf7cb89e2c61ec0b4cb14429fded371..a4e3be15a7b8beabcf292f4429ba4d8236dca911 100644 (file)
@@ -600,10 +600,12 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    *
    * @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 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
       $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'