From: Eileen McNaughton Date: Sat, 23 May 2015 09:06:55 +0000 (+1200) Subject: Put function to assign billing type onto core_form due to frequency of functionality X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8345c9d3a78cb83ec6ca4b19cacdcf230a173a6f;p=civicrm-core.git Put function to assign billing type onto core_form due to frequency of functionality --- diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index b698b30c9c..f7cc453199 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -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 */ diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index facfe84459..ba850bd534 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -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); diff --git a/CRM/Contribute/Form/UpdateBilling.php b/CRM/Contribute/Form/UpdateBilling.php index ae33a8a464..0241423f9b 100644 --- a/CRM/Contribute/Form/UpdateBilling.php +++ b/CRM/Contribute/Form/UpdateBilling.php @@ -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); diff --git a/CRM/Core/BAO/Location.php b/CRM/Core/BAO/Location.php index e12c0398eb..cfc74cd982 100644 --- a/CRM/Core/BAO/Location.php +++ b/CRM/Core/BAO/Location.php @@ -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. */ diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index d5e95ef433..d101520685 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -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. * diff --git a/CRM/Event/Cart/Form/Cart.php b/CRM/Event/Cart/Form/Cart.php index a8413db421..f7a8742030 100644 --- a/CRM/Event/Cart/Form/Cart.php +++ b/CRM/Event/Cart/Form/Cart.php @@ -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) { diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 432a01bbdd..55566e1b3a 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -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);