Move form specific code to the form
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 29 Jan 2023 23:17:25 +0000 (12:17 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 6 Feb 2023 03:34:55 +0000 (16:34 +1300)
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
CRM/Contribute/Form/Contribution.php

index 59c30d96ac0d821672e468411a52899e23da79d8..3c687182d13e1cde784c187ef395fc4f821b4135 100644 (file)
@@ -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
index 36df356cebffe73cd6e275ed28424243c58cea9b..e1fe1e7aeff3ab6a1d8511e8807adb1474826730 100644 (file)
@@ -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;
+    }
+  }
+
 }