CRM/Event - Refactor unnecessary uses of CRM_Utils_Array::value
authorcolemanw <coleman@civicrm.org>
Fri, 13 Oct 2023 23:42:35 +0000 (19:42 -0400)
committercolemanw <coleman@civicrm.org>
Mon, 16 Oct 2023 11:43:17 +0000 (07:43 -0400)
CRM/Event/BAO/Event.php
CRM/Event/BAO/Participant.php
CRM/Event/Form/ManageEvent/EventInfo.php
CRM/Event/Form/ManageEvent/Fee.php
CRM/Event/Form/ManageEvent/Registration.php
CRM/Event/Form/Participant.php
CRM/Event/Form/Registration.php
CRM/Event/Form/Registration/Register.php

index 4fcbb99cef8a4a136291f72a4d8425fc547ae033..6f843c7742c038c72165f31709557e479975eaae 100644 (file)
@@ -2019,7 +2019,7 @@ WHERE  ce.loc_block_id = $locBlockId";
     $participant = new CRM_Event_DAO_Participant();
     $participant->copyValues($params);
 
-    $participant->is_test = CRM_Utils_Array::value('is_test', $params, 0);
+    $participant->is_test = $params['is_test'] ?? 0;
     $participant->selectAdd();
     $participant->selectAdd('status_id');
     if ($participant->find(TRUE) && array_key_exists($participant->status_id, $statusTypes)) {
index 9018edaec5ce39f874763885e53f141cff8aed3d..6e872c468e0afac3f00688a45f44545f46eaf157 100644 (file)
@@ -546,7 +546,7 @@ INNER JOIN  civicrm_price_field field       ON ( value.price_field_id = field.id
       if ($lineItem->html_type == 'Text') {
         $count *= $lineItem->qty;
       }
-      $optionsCount[$lineItem->valueId] = $count + CRM_Utils_Array::value($lineItem->valueId, $optionsCount, 0);
+      $optionsCount[$lineItem->valueId] = $count + ($optionsCount[$lineItem->valueId] ?? 0);
     }
 
     return $optionsCount;
index c2b896f00100b3296008c69aeba1a8bf5b72de6d..0fd442b025dc3f34a25289960187c3fb7047f552 100644 (file)
@@ -217,12 +217,12 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent {
     //format params
     $params['start_date'] = $params['start_date'] ?? NULL;
     $params['end_date'] = $params['end_date'] ?? NULL;
-    $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, FALSE);
-    $params['is_map'] = CRM_Utils_Array::value('is_map', $params, FALSE);
-    $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
-    $params['is_public'] = CRM_Utils_Array::value('is_public', $params, FALSE);
-    $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE);
-    $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE);
+    $params['has_waitlist'] = $params['has_waitlist'] ?? FALSE;
+    $params['is_map'] = $params['is_map'] ?? FALSE;
+    $params['is_active'] = $params['is_active'] ?? FALSE;
+    $params['is_public'] = $params['is_public'] ?? FALSE;
+    $params['is_share'] = $params['is_share'] ?? FALSE;
+    $params['default_role_id'] = $params['default_role_id'] ?? FALSE;
     $params['id'] = $this->_id;
 
     //merge params with defaults from templates
index 52eb1eb987a7a87db753fc1e017d7ac968099d7d..381448517d7aad283db0135533bc8f921f8d8cdd 100644 (file)
@@ -550,8 +550,8 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent {
       $params['payment_processor'] = 'null';
     }
 
-    $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
-    $params['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $params, 0);
+    $params['is_pay_later'] = $params['is_pay_later'] ?? 0;
+    $params['is_billing_required'] = $params['is_billing_required'] ?? 0;
 
     if ($this->_id) {
 
index 4d288953204c4ffae46052c472b25d067871aa60..7b51f7281d0ae9a72fd38159d44c41a2e4e01478 100644 (file)
@@ -33,10 +33,10 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
    * Set variables up before form is built.
    */
   public function preProcess() {
-    $this->_addProfileBottom = CRM_Utils_Array::value('addProfileBottom', $_GET, FALSE);
-    $this->_profileBottomNum = CRM_Utils_Array::value('addProfileNum', $_GET, 0);
-    $this->_addProfileBottomAdd = CRM_Utils_Array::value('addProfileBottomAdd', $_GET, FALSE);
-    $this->_profileBottomNumAdd = CRM_Utils_Array::value('addProfileNumAdd', $_GET, 0);
+    $this->_addProfileBottom = $_GET['addProfileBottom'] ?? FALSE;
+    $this->_profileBottomNum = $_GET['addProfileNum'] ?? 0;
+    $this->_addProfileBottomAdd = $_GET['addProfileBottomAdd'] ?? FALSE;
+    $this->_profileBottomNumAdd = $_GET['addProfileNumAdd'] ?? 0;
 
     parent::preProcess();
     $this->setSelectedChild('registration');
@@ -783,12 +783,12 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
     $params['id'] = $this->_id;
 
     // format params
-    $params['is_online_registration'] = CRM_Utils_Array::value('is_online_registration', $params, FALSE);
+    $params['is_online_registration'] = $params['is_online_registration'] ?? FALSE;
     // CRM-11182
-    $params['is_confirm_enabled'] = CRM_Utils_Array::value('is_confirm_enabled', $params, FALSE);
-    $params['is_multiple_registrations'] = CRM_Utils_Array::value('is_multiple_registrations', $params, FALSE);
-    $params['allow_same_participant_emails'] = CRM_Utils_Array::value('allow_same_participant_emails', $params, FALSE);
-    $params['requires_approval'] = CRM_Utils_Array::value('requires_approval', $params, FALSE);
+    $params['is_confirm_enabled'] = $params['is_confirm_enabled'] ?? FALSE;
+    $params['is_multiple_registrations'] = $params['is_multiple_registrations'] ?? FALSE;
+    $params['allow_same_participant_emails'] = $params['allow_same_participant_emails'] ?? FALSE;
+    $params['requires_approval'] = $params['requires_approval'] ?? FALSE;
 
     // reset is_email confirm if not online reg
     if (!$params['is_online_registration']) {
@@ -922,7 +922,7 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
     self::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple');
 
     $cantDedupe = FALSE;
-    $rgId = CRM_Utils_Array::value('dedupe_rule_group_id', $params, 0);
+    $rgId = $params['dedupe_rule_group_id'] ?? 0;
 
     switch (self::canProfilesDedupe($profileIds, $rgId)) {
       case 0:
index d05dbc9a04a07dc12a35fe93dfa833432ecb4b71..9b833fdba4b3d28dd35ddfa07f091a53f32f7bb1 100644 (file)
@@ -904,7 +904,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       $params["address_name-{$this->_bltID}"]
         = ($params['billing_first_name'] ?? '') . ' ' .
         ($params['billing_middle_name'] ?? '') . ' ' .
-        CRM_Utils_Array::value('billing_last_name', $params);
+         ($params['billing_last_name'] ?? '');
 
       $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
       $fields["address_name-{$this->_bltID}"] = 1;
@@ -1178,7 +1178,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
               }
               $lineItem[$this->_priceSetId][$lineKey] = $line;
             }
-            CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, CRM_Utils_Array::value($num, $contributions, NULL), 'civicrm_participant');
+            CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, $contributions[$num] ?? NULL, 'civicrm_participant');
           }
         }
       }
@@ -1479,7 +1479,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       //also add additional participant's fee level/priceset
       if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
         $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
-        $hasLineItems = CRM_Utils_Array::value('priceSetId', $params, FALSE);
+        $hasLineItems = $params['priceSetId'] ?? FALSE;
         $additionalParticipantDetails = $this->getFeeDetails($additionalIds, $hasLineItems);
       }
     }
@@ -1586,7 +1586,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       'invoice_id' => $params['invoiceID'],
       'currency' => $params['currencyID'],
       'source' => !empty($params['participant_source']) ? $params['participant_source'] : $params['description'],
-      'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0),
+      'is_pay_later' => $params['is_pay_later'] ?? 0,
       'campaign_id' => $params['campaign_id'] ?? NULL,
       'card_type_id' => $params['card_type_id'] ?? NULL,
       'pan_truncation' => $params['pan_truncation'] ?? NULL,
@@ -1673,7 +1673,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         $participantFields['participant_source']['maxlength']
       ),
       'fee_level' => $params['amount_level'] ?? NULL,
-      'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0),
+      'is_pay_later' => $params['is_pay_later'] ?? 0,
       'fee_amount' => $params['fee_amount'] ?? NULL,
       'registered_by_id' => $params['registered_by_id'] ?? NULL,
       'discount_id' => $params['discount_id'] ?? NULL,
index b33f7ee18ef6aa3675b9bb62d44f27a1ab9d5745..b49d0066695ec3ef5c3c0be89b022f59f60f67ee 100644 (file)
@@ -618,7 +618,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
       if (!empty($form->_priceSet['fields'])) {
         foreach ($form->_priceSet['fields'] as $field) {
           foreach ($field['options'] as $option) {
-            $count = CRM_Utils_Array::value('count', $option, 0);
+            $count = $option['count'] ?? 0;
             $optionsCountDetails['fields'][$field['id']]['options'][$option['id']] = $count;
           }
         }
@@ -633,7 +633,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
     if (!empty($form->_priceSet['fields'])) {
       foreach ($form->_priceSet['fields'] as $field) {
         foreach ($field['options'] as $option) {
-          $maxVal = CRM_Utils_Array::value('max_value', $option, 0);
+          $maxVal = $option['max_value'] ?? 0;
           $optionsMaxValueDetails['fields'][$field['id']]['options'][$option['id']] = $maxVal;
           $optionsMaxValueTotal += $maxVal;
         }
index 86943613271b760680eee13dbab9d4a719a3b355..a3614cfba5216d44338b05a9050360caf47969e6 100644 (file)
@@ -329,7 +329,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     if ($this->_allowConfirmation) {
       $this->_contactId = $contactID;
       $this->_discountId = $discountId;
-      $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
+      $forcePayLater = $this->_defaults['is_pay_later'] ?? FALSE;
       $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
       $this->_defaults['is_pay_later'] = $forcePayLater;
 
@@ -754,10 +754,10 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
       }
       foreach ($field['options'] as & $option) {
         $optId = $option['id'];
-        $count = CRM_Utils_Array::value('count', $option, 0);
-        $maxValue = CRM_Utils_Array::value('max_value', $option, 0);
-        $dbTotalCount = CRM_Utils_Array::value($optId, $recordedOptionsCount, 0);
-        $currentTotalCount = CRM_Utils_Array::value($optId, $currentOptionsCount, 0);
+        $count = $option['count'] ?? 0;
+        $maxValue = $option['max_value'] ?? 0;
+        $dbTotalCount = $recordedOptionsCount[$optId] ?? 0;
+        $currentTotalCount = $currentOptionsCount[$optId] ?? 0;
 
         $totalCount = $currentTotalCount + $dbTotalCount;
         $isFull = FALSE;
@@ -769,7 +769,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
           $optionFullIds[$optId] = $optId;
           if ($field['html_type'] != 'Select') {
             if (in_array($optId, $defaultPricefieldIds)) {
-              $optionFullTotalAmount += CRM_Utils_Array::value('amount', $option);
+              $optionFullTotalAmount += $option['amount'] ?? 0;
             }
           }
           else {
@@ -988,7 +988,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     $this->set('is_pay_later', $params['is_pay_later']);
 
     // assign pay later stuff
-    $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
+    $this->_params['is_pay_later'] = $params['is_pay_later'] ?? FALSE;
     $this->assign('is_pay_later', $params['is_pay_later']);
     $this->assign('pay_later_text', $params['is_pay_later'] ? $this->_values['event']['pay_later_text'] : NULL);
     $this->assign('pay_later_receipt', $params['is_pay_later'] ? $this->_values['event']['pay_later_receipt'] : NULL);