From c5e02dc5ff4e9d4cbabab0f50301df6da0483092 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Thu, 11 Apr 2013 23:03:42 -0400 Subject: [PATCH] copy of batch-countrystatecounty for 4.3 --- CRM/Contact/Form/Task/Batch.php | 23 +++++++++++++++++++++++ CRM/Core/BAO/Address.php | 8 +++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/Form/Task/Batch.php b/CRM/Contact/Form/Task/Batch.php index 98deb93f52..1af75b4657 100644 --- a/CRM/Contact/Form/Task/Batch.php +++ b/CRM/Contact/Form/Task/Batch.php @@ -67,6 +67,12 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { * when not to reset sort_name */ protected $_preserveDefault = TRUE; + + /** + * the internal QF names for the state/country/county fields + */ + + protected $_stateCountryCountyFields = array(); /** * build all the data structures needed to build the form @@ -139,11 +145,21 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { 'organization_name', 'household_name', ); + + $stateCountryMap = array(); foreach ($this->_contactIds as $contactId) { $profileFields = $this->_fields; CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId); foreach ($profileFields as $name => $field) { + + // Link state to country, county to state per location per contact + list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); + if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') { + $stateCountryMap["$index-$contactId"][$prefixName] = "field_{$contactId}_{$field['name']}"; + $this->_stateCountryCountyFields["$index-$contactId"][$prefixName] = "field[{$contactId}][{$field['name']}]"; + } + CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId); if (in_array($field['name'], $preserveDefaultsArray)) { @@ -151,6 +167,10 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { } } } + + CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); + + $this->assign('fields', $this->_fields); @@ -191,6 +211,9 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { } $this->assign('sortName', $sortName); + + // now fix all state country selectors + CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults, $this->_stateCountryCountyFields); return $defaults; } diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 23ecb75ebd..a3bf099b0d 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -663,11 +663,13 @@ ORDER BY civicrm_address.is_primary DESC, civicrm_address.location_type_id DESC, $config->stateCountryMap = array_merge($config->stateCountryMap, $stateCountryMap); } - static function fixAllStateSelects(&$form, &$defaults) { + static function fixAllStateSelects(&$form, $defaults, $batchFieldNames = false) { $config = CRM_Core_Config::singleton(); + + $map = is_array($batchFieldNames) ? $batchFieldNames : $config->stateCountryMap; - if (!empty($config->stateCountryMap)) { - foreach ($config->stateCountryMap as $index => $match) { + if (!empty($map)) { + foreach ($map as $index => $match) { if ( array_key_exists('state_province', $match) && array_key_exists('country', $match) -- 2.25.1