Flatten array
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 23 Sep 2023 20:52:51 +0000 (09:52 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 23 Sep 2023 20:54:46 +0000 (09:54 +1300)
This array is being built up with an unnecessary layer

CRM/Event/Form/EventFees.php

index 4755e31e7c5d909fe410fc97edfa9b1d0afd8d53..19df7f16719e6b223409cc69d3cbe907fb0124a1 100644 (file)
@@ -61,10 +61,10 @@ class CRM_Event_Form_EventFees {
       $details = [];
       CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities);
       if (!empty($details[$form->_eventId]['financial_type_id'])) {
-        $defaults[$form->_pId]['financial_type_id'] = $details[$form->_eventId]['financial_type_id'];
+        $defaults['financial_type_id'] = $details[$form->_eventId]['financial_type_id'];
       }
       if (!empty($details[$form->_eventId]['confirm_email_text'])) {
-        $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text'];
+        $defaults['receipt_text'] = $details[$form->_eventId]['confirm_email_text'];
       }
     }
 
@@ -82,54 +82,54 @@ class CRM_Event_Form_EventFees {
           }
         }
 
-        if ($form->_discountId && !empty($discounts[$defaults[$form->_pId]['discount_id']])) {
-          $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]);
+        if ($form->_discountId && !empty($discounts[$defaults['discount_id']])) {
+          $form->assign('discount', $discounts[$defaults['discount_id']]);
         }
 
-        $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
-        $form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]));
+        $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults));
+        $form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults));
       }
-      $defaults[$form->_pId]['send_receipt'] = 0;
+      $defaults['send_receipt'] = 0;
     }
     else {
-      $defaults[$form->_pId]['send_receipt'] = (strtotime(CRM_Utils_Array::value('start_date', $details[$form->_eventId])) >= time()) ? 1 : 0;
-      $defaults[$form->_pId]['receive_date'] = date('Y-m-d H:i:s');
+      $defaults['send_receipt'] = (strtotime(CRM_Utils_Array::value('start_date', $details[$form->_eventId])) >= time()) ? 1 : 0;
+      $defaults['receive_date'] = date('Y-m-d H:i:s');
     }
 
     //CRM-11601 we should keep the record contribution
     //true by default while adding participant
     if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent) {
-      $defaults[$form->_pId]['record_contribution'] = 1;
+      $defaults['record_contribution'] = 1;
     }
 
     //CRM-13420
     if (empty($defaults['payment_instrument_id'])) {
-      $defaults[$form->_pId]['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
+      $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     if ($form->_mode) {
       $config = CRM_Core_Config::singleton();
       // set default country from config if no country set
-      if (empty($defaults[$form->_pId]["billing_country_id-{$form->_bltID}"])) {
-        $defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry;
+      if (empty($defaults["billing_country_id-{$form->_bltID}"])) {
+        $defaults["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry;
       }
 
       if (empty($defaults["billing_state_province_id-{$form->_bltID}"])) {
-        $defaults[$form->_pId]["billing_state_province_id-{$form->_bltID}"] = $config->defaultContactStateProvince;
+        $defaults["billing_state_province_id-{$form->_bltID}"] = $config->defaultContactStateProvince;
       }
 
       $billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId);
-      $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults);
+      $defaults = array_merge($defaults, $billingDefaults);
     }
 
     // if user has selected discount use that to set default
     if (isset($form->_discountId)) {
-      $defaults[$form->_pId]['discount_id'] = $form->_discountId;
+      $defaults['discount_id'] = $form->_discountId;
 
       //hack to set defaults for already selected discount value
       if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) {
-        $form->_originalDiscountId = $defaults[$form->_pId]['discount_id'];
+        $form->_originalDiscountId = $defaults['discount_id'];
         if ($form->_originalDiscountId) {
-          $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId;
+          $defaults['discount_id'] = $form->_originalDiscountId;
         }
       }
       $discountId = $form->_discountId;
@@ -147,7 +147,7 @@ class CRM_Event_Form_EventFees {
 
     if (($form->_action == CRM_Core_Action::ADD) && $form->_eventId && $discountId) {
       // this case is for add mode, where we show discount automatically
-      $defaults[$form->_pId]['discount_id'] = $discountId;
+      $defaults['discount_id'] = $discountId;
     }
 
     if ($priceSetId) {
@@ -162,7 +162,7 @@ class CRM_Event_Form_EventFees {
       )) {
         $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId);
         if (!empty($priceSetValues)) {
-          $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues);
+          $defaults = array_merge($defaults, $priceSetValues);
         }
       }
 
@@ -175,33 +175,33 @@ class CRM_Event_Form_EventFees {
               }
 
               if ($val['html_type'] == 'CheckBox') {
-                $defaults[$form->_pId]["price_{$key}"][$keys] = 1;
+                $defaults["price_{$key}"][$keys] = 1;
               }
               else {
-                $defaults[$form->_pId]["price_{$key}"] = $keys;
+                $defaults["price_{$key}"] = $keys;
               }
             }
           }
         }
       }
 
-      $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
+      $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults));
       if ($form->_action == CRM_Core_Action::UPDATE) {
-        $fee_level = $defaults[$form->_pId]['fee_level'];
+        $fee_level = $defaults['fee_level'];
         CRM_Event_BAO_Participant::fixEventLevel($fee_level);
         $form->assign('fee_level', $fee_level);
-        $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
+        $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults));
       }
     }
 
     //CRM-4453
-    if (!empty($defaults[$form->_pId]['participant_fee_currency'])) {
-      $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']);
+    if (!empty($defaults['participant_fee_currency'])) {
+      $form->assign('fee_currency', $defaults['participant_fee_currency']);
     }
 
     // CRM-4395
     if ($contriId = $form->get('onlinePendingContributionId')) {
-      $defaults[$form->_pId]['record_contribution'] = 1;
+      $defaults['record_contribution'] = 1;
       $contribution = new CRM_Contribute_DAO_Contribution();
       $contribution->id = $contriId;
       $contribution->find(TRUE);
@@ -212,10 +212,10 @@ class CRM_Event_Form_EventFees {
         'receive_date',
         'total_amount',
       ] as $f) {
-        $defaults[$form->_pId][$f] = $contribution->$f;
+        $defaults[$f] = $contribution->$f;
       }
     }
-    return $defaults[$form->_pId];
+    return $defaults;
   }
 
   /**