From 0b50eca0a61f81e13961fc94dc004224d147ce94 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 7 Sep 2016 18:04:41 +1200 Subject: [PATCH] CRM-19351 Standardise calls to assign billing details to the template --- CRM/Contribute/Form/AdditionalInfo.php | 28 ++++--------------- CRM/Contribute/Form/AdditionalPayment.php | 28 ++++--------------- CRM/Contribute/Form/ContributionBase.php | 29 ++++--------------- CRM/Core/Form.php | 27 ++++++++++++++++++ CRM/Dedupe/Merger.php | 4 +-- CRM/Event/Form/Participant.php | 34 ++++------------------- CRM/Event/Form/Registration.php | 18 +----------- CRM/Member/Form.php | 19 ------------- CRM/Member/Form/Membership.php | 20 +++---------- CRM/Member/Form/MembershipRenewal.php | 20 +++---------- 10 files changed, 58 insertions(+), 169 deletions(-) diff --git a/CRM/Contribute/Form/AdditionalInfo.php b/CRM/Contribute/Form/AdditionalInfo.php index 0609f843b5..02e3c28e29 100644 --- a/CRM/Contribute/Form/AdditionalInfo.php +++ b/CRM/Contribute/Form/AdditionalInfo.php @@ -382,29 +382,11 @@ class CRM_Contribute_Form_AdditionalInfo { $form->assign('ccContribution', $ccContribution); if ($ccContribution) { - //build the name. - $name = CRM_Utils_Array::value('billing_first_name', $params); - if (!empty($params['billing_middle_name'])) { - $name .= " {$params['billing_middle_name']}"; - } - $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $params); - $name = trim($name); - $form->assign('billingName', $name); - - //assign the address formatted up for display - $addressParts = array( - "street_address" => "billing_street_address-{$form->_bltID}", - "city" => "billing_city-{$form->_bltID}", - "postal_code" => "billing_postal_code-{$form->_bltID}", - "state_province" => "state_province-{$form->_bltID}", - "country" => "country-{$form->_bltID}", - ); - - $addressFields = array(); - foreach ($addressParts as $name => $field) { - $addressFields[$name] = CRM_Utils_Array::value($field, $params); - } - $form->assign('address', CRM_Utils_Address::format($addressFields)); + $form->assignBillingName($params); + $form->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters( + $params, + $form->_bltID + )); $date = CRM_Utils_Date::format($params['credit_card_exp_date']); $date = CRM_Utils_Date::mysqlToIso($date); diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index bbfcc709c5..bdf78d7083 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -526,28 +526,12 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $this->_params['invoiceID'] = $this->_params['invoice_id']; } - // billing name and Address - $name = CRM_Utils_Array::value('billing_first_name', $params); - if (!empty($params['billing_middle_name'])) { - $name .= " {$params['billing_middle_name']}"; - } - $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $params); - $name = trim($name); - $this->assign('billingName', $name); - - //assign the address formatted up for display - $addressParts = array( - "street_address" => "billing_street_address-{$this->_bltID}", - "city" => "billing_city-{$this->_bltID}", - "postal_code" => "billing_postal_code-{$this->_bltID}", - "state_province" => "state_province-{$this->_bltID}", - "country" => "country-{$this->_bltID}", - ); - $addressFields = array(); - foreach ($addressParts as $name => $field) { - $addressFields[$name] = CRM_Utils_Array::value($field, $params); - } - $this->assign('address', CRM_Utils_Address::format($addressFields)); + $this->assignBillingName($params); + $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters( + $params, + $this->_bltID + )); + $date = CRM_Utils_Date::format($params['credit_card_exp_date']); $date = CRM_Utils_Date::mysqlToIso($date); $this->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $params)); diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 697eb6c996..23e946600b 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -467,14 +467,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { * Assign the minimal set of variables to the template. */ public function assignToTemplate() { - $name = CRM_Utils_Array::value('billing_first_name', $this->_params); - if (!empty($this->_params['billing_middle_name'])) { - $name .= " {$this->_params['billing_middle_name']}"; - } - $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $this->_params); - $name = trim($name); - $this->assign('billingName', $name); - $this->set('name', $name); + $this->set('name', $this->assignBillingName($this->_params)); $this->assign('paymentProcessor', $this->_paymentProcessor); $vars = array( @@ -526,22 +519,10 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } } - // assign the address formatted up for display - $addressParts = array( - "street_address-{$this->_bltID}", - "city-{$this->_bltID}", - "postal_code-{$this->_bltID}", - "state_province-{$this->_bltID}", - "country-{$this->_bltID}", - ); - - $addressFields = array(); - foreach ($addressParts as $part) { - list($n, $id) = explode('-', $part); - $addressFields[$n] = CRM_Utils_Array::value('billing_' . $part, $this->_params); - } - - $this->assign('address', CRM_Utils_Address::format($addressFields)); + $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters( + $this->_params, + $this->_bltID + )); if (!empty($this->_params['onbehalf_profile_id']) && !empty($this->_params['onbehalf'])) { $this->assign('onBehalfName', $this->_params['organization_name']); diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index f85032dd29..59c864b0a0 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -2282,4 +2282,31 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } } + /** + * Assign billing name to the template. + * + * @param array $params + * Form input params, default to $this->_params. + */ + public function assignBillingName($params = array()) { + $name = ''; + if (empty($params)) { + $params = $this->_params; + } + if (!empty($params['billing_first_name'])) { + $name = $params['billing_first_name']; + } + + if (!empty($params['billing_middle_name'])) { + $name .= " {$params['billing_middle_name']}"; + } + + if (!empty($params['billing_last_name'])) { + $name .= " {$params['billing_last_name']}"; + } + $name = trim($name); + $this->assign('billingName', $name); + return $name; + } + } diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index a286b2115f..99e83a470d 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1167,16 +1167,14 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m // Collect existing fields from both 'main' and 'other' contacts first // This allows us to match up location/types when building the table rows foreach ($mergeTargets as $moniker => $cid) { - $cnt = 1; $searchParams = array( - 'version' => 3, 'contact_id' => $cid, // CRM-17556 Order by field-specific criteria 'options' => array( 'sort' => $blockInfo['sortString'], ), ); - $values = civicrm_api($blockName, 'get', $searchParams); + $values = civicrm_api3($blockName, 'get', $searchParams); if ($values['count']) { $cnt = 0; foreach ($values['values'] as $index => $value) { diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 06b04f8d65..cd783ac251 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1541,35 +1541,11 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params)); } if ($this->_mode) { - if (!empty($params['billing_first_name'])) { - $name = $params['billing_first_name']; - } - - if (!empty($params['billing_middle_name'])) { - $name .= " {$params['billing_middle_name']}"; - } - - if (!empty($params['billing_last_name'])) { - $name .= " {$params['billing_last_name']}"; - } - $this->assign('billingName', $name); - - // assign the address formatted up for display - $addressParts = array( - "street_address-{$this->_bltID}", - "city-{$this->_bltID}", - "postal_code-{$this->_bltID}", - "state_province-{$this->_bltID}", - "country-{$this->_bltID}", - ); - $addressFields = array(); - foreach ($addressParts as $part) { - list($n, $id) = explode('-', $part); - if (isset($this->_params['billing_' . $part])) { - $addressFields[$n] = $this->_params['billing_' . $part]; - } - } - $this->assign('address', CRM_Utils_Address::format($addressFields)); + $this->assignBillingName($params); + $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters( + $this->_params, + $this->_bltID + )); $date = CRM_Utils_Date::format($params['credit_card_exp_date']); $date = CRM_Utils_Date::mysqlToIso($date); diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 933cd49999..9d9eddde34 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -467,23 +467,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { } } - // assign the address formatted up for display - $addressParts = array( - "street_address-{$this->_bltID}", - "city-{$this->_bltID}", - "postal_code-{$this->_bltID}", - "state_province-{$this->_bltID}", - "country-{$this->_bltID}", - ); - $addressFields = array(); - foreach ($addressParts as $part) { - list($n, $id) = explode('-', $part); - if (isset($params['billing_' . $part])) { - $addressFields[$n] = CRM_Utils_Array::value('billing_' . $part, $params); - } - } - - $this->assign('address', CRM_Utils_Address::format($addressFields)); + $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters($params, $this->_bltID)); // The concept of contributeMode is deprecated. if ($this->_contributeMode == 'direct' && empty($params['is_pay_later'])) { diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 6c0e5eddf6..222fcb4c8f 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -430,25 +430,6 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { return $formValues; } - /** - * Assign billing name to the template. - */ - protected function assignBillingName() { - $name = ''; - if (!empty($this->_params['billing_first_name'])) { - $name = $this->_params['billing_first_name']; - } - - if (!empty($this->_params['billing_middle_name'])) { - $name .= " {$this->_params['billing_middle_name']}"; - } - - if (!empty($this->_params['billing_last_name'])) { - $name .= " {$this->_params['billing_last_name']}"; - } - $this->assign('billingName', $name); - } - /** * Wrapper function for unit tests. * diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 194fe67801..ae9dd38535 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1004,22 +1004,10 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $form->assign('customValues', $customValues); if ($form->_mode) { - // assign the address formatted up for display - $addressParts = array( - "street_address-{$form->_bltID}", - "city-{$form->_bltID}", - "postal_code-{$form->_bltID}", - "state_province-{$form->_bltID}", - "country-{$form->_bltID}", - ); - $addressFields = array(); - foreach ($addressParts as $part) { - list($n, $id) = explode('-', $part); - if (isset($form->_params['billing_' . $part])) { - $addressFields[$n] = $form->_params['billing_' . $part]; - } - } - $form->assign('address', CRM_Utils_Address::format($addressFields)); + $form>assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters( + $form->_params, + $form->_bltID + )); $date = CRM_Utils_Date::format($form->_params['credit_card_exp_date']); $date = CRM_Utils_Date::mysqlToIso($date); diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 1de8b075d7..319b30023f 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -688,22 +688,10 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date)); $this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date)); if ($this->_mode) { - // assign the address formatted up for display - $addressParts = array( - "street_address-{$this->_bltID}", - "city-{$this->_bltID}", - "postal_code-{$this->_bltID}", - "state_province-{$this->_bltID}", - "country-{$this->_bltID}", - ); - $addressFields = array(); - foreach ($addressParts as $part) { - list($n) = explode('-', $part); - if (isset($this->_params['billing_' . $part])) { - $addressFields[$n] = $this->_params['billing_' . $part]; - } - } - $this->assign('address', CRM_Utils_Address::format($addressFields)); + $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters( + $this->_params, + $this->_bltID + )); $this->assign('contributeMode', 'direct'); $this->assign('isAmountzero', 0); $this->assign('is_pay_later', 0); -- 2.25.1