CRM-17256 use consistent retrieval of billing location type id
authoreileenmcnaugton <eileen@fuzion.co.nz>
Tue, 13 Oct 2015 09:02:07 +0000 (22:02 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Tue, 13 Oct 2015 09:02:07 +0000 (22:02 +1300)
CRM/Contact/BAO/Contact.php
CRM/Contribute/BAO/ContributionPage.php
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Core/BAO/Location.php
CRM/Core/Form.php
CRM/Core/Payment.php
CRM/Core/Payment/BaseIPN.php
api/v3/Profile.php

index ea564123be0a51bbf751777619a37e26b18cb510..7c007ef37866a7ba0d8746cfb35bf0d57cc61737 100644 (file)
@@ -2000,9 +2000,7 @@ ORDER BY civicrm_email.is_primary DESC";
       $defaultLocationId = $defaultLocation->id;
     }
 
-    // get the billing location type
-    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-    $billingLocationTypeId = array_search('Billing', $locationTypes);
+    $billingLocationTypeId = CRM_Core_BAO_LocationType::getBilling();
 
     $blocks = array('email', 'phone', 'im', 'openid');
 
index 5d86d79a4a6d44d3d3f61031f47a77e03ad81c2a..24be98770ef6d07ecf1ffd30a6f713c490637d69 100644 (file)
@@ -274,8 +274,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
 
       // get the billing location type
       if (!array_key_exists('related_contact', $values)) {
-        $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-        $billingLocationTypeId = array_search('Billing', $locationTypes);
+        $billingLocationTypeId = CRM_Core_BAO_LocationType::getBilling();
       }
       else {
         // presence of related contact implies onbehalf of org case,
index 461987e889b9cd3970508259f61edee1f4af8242..7d302e84614b3bf85217d880206f4e6b8dc0cd1a 100644 (file)
@@ -1260,12 +1260,10 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
         TRUE, NULL, FALSE, TRUE
       );
       // set email in the template here
-      // get the billing location type
-      $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-      $billingLocationTypeId = array_search('Billing', $locationTypes);
 
-      if ($billingLocationTypeId) {
-        list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id, FALSE, $billingLocationTypeId);
+      if (CRM_Core_BAO_LocationType::getBilling()) {
+        list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id,
+          FALSE, CRM_Core_BAO_LocationType::getBilling());
       }
       // get primary location email if no email exist( for billing location).
       if (!$email) {
index 3a0b04c500c14bd34e79cb460b64e8d4344c5e04..9451db3e400b5d85dbc2dd1f514a5e10c1319d79 100644 (file)
@@ -92,26 +92,6 @@ 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 e22c212549e1cc66939622021d8077ff856cb5bf..9a99b67fc3191aeff7c6b841a5615f56ff91a7e2 100644 (file)
@@ -647,7 +647,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * @throws CRM_Core_Exception
    */
   public function assignBillingType() {
-    $this->_bltID = CRM_Core_BAO_Location::getBillingLocationId();
+    $this->_bltID = CRM_Core_BAO_LocationType::getBilling();
     $this->set('bltID', $this->_bltID);
     $this->assign('bltID', $this->_bltID);
   }
index 3c8a67637cd0a16d6f43e0f02a91637f4318b4e4..48bad78010ae06199818453f4707a4cbaf6704f8 100644 (file)
@@ -561,7 +561,13 @@ abstract class CRM_Core_Payment {
    *
    * @return array
    */
-  public function getBillingAddressFields($billingLocationID) {
+  public function getBillingAddressFields($billingLocationID = NULL) {
+    if (!$billingLocationID) {
+      // Note that although the billing id is passed around the forms the idea that it would be anything other than
+      // the result of the function below doesn't seem to have eventuated.
+      // So taking this as a param is possibly something to be removed in favour of the standard default.
+      $billingLocationID = CRM_Core_BAO_LocationType::getBilling();
+    }
     if ($this->_paymentProcessor['billing_mode'] != 1 && $this->_paymentProcessor['billing_mode'] != 3) {
       return array();
     }
@@ -585,7 +591,13 @@ abstract class CRM_Core_Payment {
    * @return array
    *    Array of metadata for address fields.
    */
-  public function getBillingAddressFieldsMetadata($billingLocationID) {
+  public function getBillingAddressFieldsMetadata($billingLocationID = NULL) {
+    if (!$billingLocationID) {
+      // Note that although the billing id is passed around the forms the idea that it would be anything other than
+      // the result of the function below doesn't seem to have eventuated.
+      // So taking this as a param is possibly something to be removed in favour of the standard default.
+      $billingLocationID = CRM_Core_BAO_LocationType::getBilling();
+    }
     $metadata = array();
     $metadata['billing_first_name'] = array(
       'htmlType' => 'text',
index da88369673ca931b981244b79cf3897e02d4bc23..7aec4e12a5e84c88fc3a9d622f3272b9bfc4ded6 100644 (file)
@@ -457,11 +457,7 @@ class CRM_Core_Payment_BaseIPN {
    * @return bool
    */
   public function getBillingID(&$ids) {
-    // get the billing location type
-    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-    // CRM-8108 remove the ts around the Billing location type
-    //$ids['billing'] =  array_search( ts('Billing'),  $locationTypes );
-    $ids['billing'] = array_search('Billing', $locationTypes);
+    $ids['billing'] = CRM_Core_BAO_LocationType::getBilling();
     if (!$ids['billing']) {
       CRM_Core_Error::debug_log_message(ts('Please set a location type of %1', array(1 => 'Billing')));
       echo "Failure: Could not find billing location type<p>";
index c8da6a50e43d415ccb1c8a745ecc1803850c51aa..992dfad7c95ec0d945b979d27a23bc7575cec671 100644 (file)
@@ -372,8 +372,7 @@ function civicrm_api3_profile_apply($params) {
  */
 function _civicrm_api3_profile_getbillingpseudoprofile(&$params) {
 
-  $locations = civicrm_api3('address', 'getoptions', array('field' => 'location_type_id', 'context' => 'validate'));
-  $locationTypeID = array_search('Billing', $locations['values']);
+  $locationTypeID = CRM_Core_BAO_LocationType::getBilling();
 
   if (empty($params['contact_id'])) {
     $config = CRM_Core_Config::singleton();