copy of batch-countrystatecounty for 4.3
authorAndrew Hunt <andrew@aghstrategies.com>
Fri, 12 Apr 2013 03:03:42 +0000 (23:03 -0400)
committerAndrew Hunt <andrew@aghstrategies.com>
Fri, 12 Apr 2013 03:03:42 +0000 (23:03 -0400)
CRM/Contact/Form/Task/Batch.php
CRM/Core/BAO/Address.php

index 98deb93f52e6333a6e70bd50df271d18ad2ee3a3..1af75b4657f48c8e380dff939d985409ad1f27c0 100644 (file)
@@ -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;
   }
index 23ecb75ebdf3c3a5758672ed5b73a97f401a1682..a3bf099b0d5dfcaf6750edd97ae6800e27054382 100644 (file)
@@ -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)