From 78e174ea26bd0f74724a8137a0c95dbc9e60da66 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 17 Dec 2022 12:17:45 +1300 Subject: [PATCH] Post code-divide tidy-up Follow up to https://github.com/civicrm/civicrm-core/pull/25184 --- CRM/Contribute/Form/ContributionBase.php | 73 ++---------------------- 1 file changed, 5 insertions(+), 68 deletions(-) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index c917eb7daa62..108dfca4587a 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -360,8 +360,7 @@ public function preProcess() { // get price info // CRM-5095 - $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id); - $this->initSet($this, 'civicrm_contribution_page', FALSE, $priceSetId); + $this->initSet($this); // this avoids getting E_NOTICE errors in php $setNullFields = [ @@ -509,15 +508,11 @@ public function preProcess() { * * @param CRM_Core_Form $form * Form entity id. - * @param string $entityTable - * @param bool $doNotIncludeExpiredFields - * @param int $priceSetId - * Price Set ID * * @todo - removed unneeded code from previously-shared function */ - private function initSet(&$form, $entityTable = 'civicrm_event', $doNotIncludeExpiredFields = FALSE, $priceSetId = NULL) { - + private function initSet($form) { + $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id); //check if price set is is_config if (is_numeric($priceSetId)) { if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config') && $form->getVar('_name') != 'Participant') { @@ -527,29 +522,7 @@ private function initSet(&$form, $entityTable = 'civicrm_event', $doNotIncludeEx // get price info if ($priceSetId) { if ($form->_action & CRM_Core_Action::UPDATE) { - $entityId = $entity = NULL; - - switch ($entityTable) { - case 'civicrm_event': - $entity = 'participant'; - if (in_array(CRM_Utils_System::getClassName($form), ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register'])) { - $entityId = $form->_id; - } - else { - $entityId = $form->_participantId; - } - break; - - case 'civicrm_contribution_page': - case 'civicrm_contribution': - $entity = 'contribution'; - $entityId = $form->_id; - break; - } - - if ($entityId && $entity) { - $form->_values['line_items'] = CRM_Price_BAO_LineItem::getLineItems($entityId, $entity); - } + $form->_values['line_items'] = CRM_Price_BAO_LineItem::getLineItems($form->_id, 'contribution'); $required = FALSE; } else { @@ -557,46 +530,10 @@ private function initSet(&$form, $entityTable = 'civicrm_event', $doNotIncludeEx } $form->_priceSetId = $priceSetId; - $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, $required, $doNotIncludeExpiredFields); + $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, $required); $form->_priceSet = $priceSet[$priceSetId] ?? NULL; $form->_values['fee'] = $form->_priceSet['fields'] ?? NULL; - //get the price set fields participant count. - if ($entityTable == 'civicrm_event') { - //get option count info. - $form->_priceSet['optionsCountTotal'] = CRM_Price_BAO_PriceSet::getPricesetCount($priceSetId); - if ($form->_priceSet['optionsCountTotal']) { - $optionsCountDetails = []; - if (!empty($form->_priceSet['fields'])) { - foreach ($form->_priceSet['fields'] as $field) { - foreach ($field['options'] as $option) { - $count = CRM_Utils_Array::value('count', $option, 0); - $optionsCountDetails['fields'][$field['id']]['options'][$option['id']] = $count; - } - } - } - $form->_priceSet['optionsCountDetails'] = $optionsCountDetails; - } - - //get option max value info. - $optionsMaxValueTotal = 0; - $optionsMaxValueDetails = []; - - 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); - $optionsMaxValueDetails['fields'][$field['id']]['options'][$option['id']] = $maxVal; - $optionsMaxValueTotal += $maxVal; - } - } - } - - $form->_priceSet['optionsMaxValueTotal'] = $optionsMaxValueTotal; - if ($optionsMaxValueTotal) { - $form->_priceSet['optionsMaxValueDetails'] = $optionsMaxValueDetails; - } - } $form->set('priceSetId', $form->_priceSetId); $form->set('priceSet', $form->_priceSet); }