From ea5e2a9ee5cd1843f87a4aba067e7ceee890d92f Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 14 Aug 2023 13:19:35 +1200 Subject: [PATCH] Remove use of sometimes-php8-warning causing _quickFonconfig property (use isQuickConfig() function) --- CRM/Event/Form/Participant.php | 54 ++++++++++++++++++------ CRM/Event/Form/Registration/Register.php | 11 ----- CRM/Price/BAO/PriceSet.php | 7 +-- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index b7dca4db6d..8829f46e6a 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -46,17 +46,12 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment */ public $_values; - /** - * The values for the quickconfig for priceset. - * - * @var bool - */ - public $_quickConfig = NULL; - /** * Price Set ID, if the new price set method is used * * @var int + * + * @internal use getPriceSetID(). */ public $_priceSetId; @@ -936,9 +931,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment if (!empty($params['contact_id'])) { $this->_contactID = $this->_contactId = $params['contact_id']; } - if ($this->_priceSetId && $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { - $this->_quickConfig = $isQuickConfig; - } if ($this->_id) { $params['id'] = $this->_id; @@ -1315,7 +1307,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment if (is_array($value) && $value != 'skip') { foreach ($value as $lineKey => $line) { //10117 update the line items for participants if contribution amount is recorded - if ($this->_quickConfig && !empty($params['total_amount']) && + if ($this->isQuickConfig() && !empty($params['total_amount']) && ($params['status_id'] != array_search('Partially paid', $participantStatus)) ) { $line['unit_price'] = $line['line_total'] = $params['total_amount']; @@ -1617,7 +1609,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment //lineitems with the financial type selected in form $submittedFinancialType = $params['financial_type_id'] ?? NULL; $isPaymentRecorded = $params['record_contribution'] ?? NULL; - if ($isPaymentRecorded && $this->_quickConfig && $submittedFinancialType) { + if ($isPaymentRecorded && $this->isQuickConfig() && $submittedFinancialType) { foreach ($lineItem[0] as &$values) { $values['financial_type_id'] = $submittedFinancialType; } @@ -1625,7 +1617,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $params['fee_level'] = $params['amount_level']; $contributionParams['total_amount'] = $params['amount']; - if ($this->_quickConfig && !empty($params['total_amount']) && + if ($this->isQuickConfig() && !empty($params['total_amount']) && $params['status_id'] != array_search('Partially paid', $participantStatus) ) { $params['fee_amount'] = $params['total_amount']; @@ -1655,7 +1647,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment if (isset($participantCount)) { $this->assign('pricesetFieldsCount', $participantCount); } - $this->assign('lineItem', empty($lineItem[0]) || $this->_quickConfig ? FALSE : $lineItem); + $this->assign('lineItem', empty($lineItem[0]) || $this->isQuickConfig() ? FALSE : $lineItem); } else { $this->assign('amount_level', $params['amount_level']); @@ -2285,4 +2277,38 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_ return $this->_discountId ?: NULL; } + /** + * Get the Price Set ID in use. + * + * @return int|null + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * @noinspection PhpDocMissingThrowsInspection + * @noinspection PhpUnhandledExceptionInspection + */ + public function getPriceSetID(): ?int { + if ($this->_priceSetId === NULL) { + if ($this->getDiscountID()) { + $this->_priceSetId = (int) CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $this->getDiscountID(), 'price_set_id'); + } + else { + $this->_priceSetId = (int) CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->getEventID()); + } + $this->set('priceSetId', $this->_priceSetId); + } + return $this->_priceSetId ?: NULL; + } + + /** + * Is the price set quick config. + * + * @return bool + */ + public function isQuickConfig(): bool { + return $this->getPriceSetID() && CRM_Price_BAO_PriceSet::isQuickConfig($this->getPriceSetID()); + } + } diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 4098f96725..98e12e1f13 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -34,13 +34,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { protected $_waitlistMsg; protected $_requireApprovalMsg; - /** - * Deprecated parameter that we hope to remove. - * - * @var bool - */ - public $_quickConfig; - /** * Skip duplicate check. * @@ -596,10 +589,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { //format price set fields across option full. self::formatFieldsForOptionFull($form); - - if (!empty($form->_priceSet['is_quick_config'])) { - $form->_quickConfig = $form->_priceSet['is_quick_config']; - } $form->add('hidden', 'priceSetId', $form->_priceSetId); // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 4b7a7a8854..3a1a4f642d 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -814,12 +814,7 @@ WHERE id = %1"; $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly); $form->_priceSet = $priceSet[$priceSetId] ?? NULL; $validPriceFieldIds = array_keys($form->_priceSet['fields']); - $form->_quickConfig = $quickConfig = 0; - if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) { - $quickConfig = 1; - } - - $form->assign('quickConfig', $quickConfig); + $form->assign('quickConfig', (int) CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')); // Mark which field should have the auto-renew checkbox, if any. CRM-18305 if (!empty($form->_membershipTypeValues) && is_array($form->_membershipTypeValues)) { -- 2.25.1