From 6d715e3e524814171a9173d3bd025c40548fe91f Mon Sep 17 00:00:00 2001 From: colemanw Date: Fri, 13 Oct 2023 19:42:35 -0400 Subject: [PATCH] CRM/Event - Refactor unnecessary uses of CRM_Utils_Array::value --- CRM/Event/BAO/Event.php | 2 +- CRM/Event/BAO/Participant.php | 2 +- CRM/Event/Form/ManageEvent/EventInfo.php | 12 ++++++------ CRM/Event/Form/ManageEvent/Fee.php | 4 ++-- CRM/Event/Form/ManageEvent/Registration.php | 20 ++++++++++---------- CRM/Event/Form/Participant.php | 10 +++++----- CRM/Event/Form/Registration.php | 4 ++-- CRM/Event/Form/Registration/Register.php | 14 +++++++------- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 4fcbb99cef..6f843c7742 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -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)) { diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 9018edaec5..6e872c468e 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -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; diff --git a/CRM/Event/Form/ManageEvent/EventInfo.php b/CRM/Event/Form/ManageEvent/EventInfo.php index c2b896f001..0fd442b025 100644 --- a/CRM/Event/Form/ManageEvent/EventInfo.php +++ b/CRM/Event/Form/ManageEvent/EventInfo.php @@ -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 diff --git a/CRM/Event/Form/ManageEvent/Fee.php b/CRM/Event/Form/ManageEvent/Fee.php index 52eb1eb987..381448517d 100644 --- a/CRM/Event/Form/ManageEvent/Fee.php +++ b/CRM/Event/Form/ManageEvent/Fee.php @@ -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) { diff --git a/CRM/Event/Form/ManageEvent/Registration.php b/CRM/Event/Form/ManageEvent/Registration.php index 4d28895320..7b51f7281d 100644 --- a/CRM/Event/Form/ManageEvent/Registration.php +++ b/CRM/Event/Form/ManageEvent/Registration.php @@ -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: diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index d05dbc9a04..9b833fdba4 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -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, diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index b33f7ee18e..b49d006669 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -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; } diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 8694361327..a3614cfba5 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -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); -- 2.25.1