Put function to assign billing type onto core_form due to frequency of functionality
authorEileen McNaughton <eileen@fuzion.co.nz>
Sat, 23 May 2015 09:06:55 +0000 (21:06 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Sat, 23 May 2015 09:06:55 +0000 (21:06 +1200)
CRM/Contribute/Form/AbstractEditPayment.php
CRM/Contribute/Form/ContributionBase.php
CRM/Contribute/Form/UpdateBilling.php
CRM/Core/BAO/Location.php
CRM/Core/Form.php
CRM/Event/Cart/Form/Cart.php
CRM/Event/Form/Registration.php

index b698b30c9cf91c9cc48b673603e3b5e1fb433ee4..f7cc453199942e57729ca8243fae16c1ebb354b1 100644 (file)
@@ -412,22 +412,6 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
 
   }
 
-  /**
-   * Assign billing type id to bltID.
-   *
-   * @throws CRM_Core_Exception
-   * @return void
-   */
-  public function assignBillingType() {
-    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-    $this->_bltID = array_search('Billing', $locationTypes);
-    if (!$this->_bltID) {
-      throw new CRM_Core_Exception(ts('Please set a location type of %1', array(1 => 'Billing')));
-    }
-    $this->set('bltID', $this->_bltID);
-    $this->assign('bltID', $this->_bltID);
-  }
-
   /**
    * Assign $this->processors, $this->recurPaymentProcessors, and related Smarty variables
    */
index facfe844596435e90b3acd3f6f8b202417ba6764..ba850bd534e4ad76f0d5f7986a956c9974da5924 100644 (file)
@@ -303,16 +303,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
         throw new CRM_Contribute_Exception_InactiveContributionPageException(ts('The page you requested is currently unavailable.'), $this->_id);
       }
 
-      // also check for billing information.
-      // get the billing location type
-      $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-      // CRM-8108 remove ts around Billing location type
-      //$this->_bltID = array_search( ts('Billing'),  $locationTypes );
-      $this->_bltID = array_search('Billing', $locationTypes);
-      if (!$this->_bltID) {
-        CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
-      }
-      $this->set('bltID', $this->_bltID);
+      $this->assignBillingType();
 
       // check for is_monetary status
       $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values);
index ae33a8a464d501a724a204da6deb75d41dafa6e3..0241423f9b33dbf86824e2adde039cb883ea2e9e 100644 (file)
@@ -111,13 +111,7 @@ class CRM_Contribute_Form_UpdateBilling extends CRM_Core_Form {
     }
     $this->assign('paymentProcessor', $this->_paymentProcessor);
 
-    // get the billing location type
-    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-    $this->_bltID = array_search('Billing', $locationTypes);
-    $this->assign('bltID', $this->_bltID);
-    if (!$this->_bltID) {
-      CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
-    }
+    $this->assignBillingType();
 
     $this->assign('frequency_unit', $this->_subscriptionDetails->frequency_unit);
     $this->assign('frequency_interval', $this->_subscriptionDetails->frequency_interval);
index e12c0398ebbdac3593d88dd48ad4b48180807dee..cfc74cd982e0b2e33a233f7955d68f1be313db40 100644 (file)
@@ -94,6 +94,26 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
     return $location;
   }
 
+  /**
+   * Get the ID of the database billing location.
+   *
+   * @return int
+   *   Billing location type id.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public static function getBillingLocationId() {
+    static $billingTypeID = NULL;
+    if ($billingTypeID) {
+      return $billingTypeID;
+    }
+    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
+    $billingTypeID = array_search('Billing', $locationTypes);
+    if (!$billingTypeID) {
+      throw new CRM_Core_Exception(ts('Please set a location type of %1', array(1 => 'Billing')));
+    }
+    return $billingTypeID;
+  }
   /**
    * Creates the entry in the civicrm_loc_block.
    */
index d5e95ef4337eaf4396d74d710be5cbdd90c58350..d10152068599e18ebc33aeab4972801cd2f5c53b 100644 (file)
@@ -620,13 +620,22 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *
    * @param string $title
    *   The title of the form.
-   *
-   * @return void
    */
   public function setTitle($title) {
     $this->_title = $title;
   }
 
+  /**
+   * Assign billing type id to bltID.
+   *
+   * @throws CRM_Core_Exception
+   */
+  public function assignBillingType() {
+    $this->_bltID = CRM_Core_BAO_Location::getBillingLocationId();
+    $this->set('bltID', $this->_bltID);
+    $this->assign('bltID', $this->_bltID);
+  }
+
   /**
    * Setter function for options.
    *
index a8413db4218751732b097b8a622b42716f1ba60e..f7a874203005ba0e2edbf51b1c78b9df0f4e6216 100644 (file)
@@ -19,9 +19,7 @@ class CRM_Event_Cart_Form_Cart extends CRM_Core_Form {
 
     $this->checkWaitingList();
 
-    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-    $this->_bltID = array_search('Billing', $locationTypes);
-    $this->assign('bltID', $this->_bltID);
+    $this->assignBillingType();
 
     $event_titles = array();
     foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) {
index 432a01bbdd59dbb929035eb3912109012a6f53a3..55566e1b3ad17bf99c04325a99439c6b397849a5 100644 (file)
@@ -374,15 +374,8 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
           unset($this->_values['additional_custom_post_id']);
         }
       }
-      // get the billing location type
-      $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-      // CRM-8108 remove ts from Billing as the location type can not be translated in CiviCRM!
-      //$this->_bltID = array_search( ts('Billing'),  $locationTypes );
-      $this->_bltID = array_search('Billing', $locationTypes);
-      if (!$this->_bltID) {
-        CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
-      }
-      $this->set('bltID', $this->_bltID);
+
+      $this->assignBillingType();
 
       if ($this->_values['event']['is_monetary']) {
         CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor);