From 3a54ba1af1ff2adb1ccaee334d34714ce61fa8b9 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 30 Jan 2023 12:17:25 +1300 Subject: [PATCH] Move form specific code to the form This function is only called from the one form & the properties are likewise only touched by the form so they 'belong' to that form & should be private for clarity --- CRM/Contribute/Form/AbstractEditPayment.php | 29 --------------------- CRM/Contribute/Form/Contribution.php | 17 ++++++++++++ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 59c30d96ac..3c687182d1 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -86,18 +86,6 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { */ protected $entity; - /** - * The id of the premium that we are proceessing. - * - * @var int - */ - public $_premiumID = NULL; - - /** - * @var CRM_Contribute_DAO_ContributionProduct - */ - public $_productDAO = NULL; - /** * The id of the note * @@ -351,23 +339,6 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { CRM_Custom_Form_CustomData::setDefaultValues($this); } - /** - * @param int $id - * @todo - this function is a long way, non standard of saying $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->id = $id; $dao->find(); - */ - public function assignPremiumProduct($id) { - $sql = " -SELECT * -FROM civicrm_contribution_product -WHERE contribution_id = {$id} -"; - $dao = CRM_Core_DAO::executeQuery($sql); - if ($dao->fetch()) { - $this->_premiumID = $dao->id; - $this->_productDAO = $dao; - } - } - /** * @return array * Array of valid processors. The array resembles the DB table but also has 'object' as a key diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 36df356ceb..e1fe1e7aef 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -2134,4 +2134,21 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return $this->getSubmittedValue('price_set_id'); } + /** + * @param int $id + * @todo - this function is a long way, non standard of saying $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->id = $id; $dao->find(); + */ + private function assignPremiumProduct($id): void { + $sql = " +SELECT * +FROM civicrm_contribution_product +WHERE contribution_id = {$id} +"; + $dao = CRM_Core_DAO::executeQuery($sql); + if ($dao->fetch()) { + $this->_premiumID = $dao->id; + $this->_productDAO = $dao; + } + } + } -- 2.25.1