CRM-15172 - Add chainSelect method to CRM_Core_Form
[civicrm-core.git] / CRM / Core / Page / AJAX / Location.php
index 1527af263aa509c0d4f5969bf17cba06f1008f82..d4e126ae97c15c027a2349aa0c4f6112f86e267c 100644 (file)
@@ -200,69 +200,11 @@ class CRM_Core_Page_AJAX_Location {
   }
 
   static function jqState() {
-    if (empty($_GET['_value'])) {
-      CRM_Utils_System::civiExit();
-    }
-    $countries = (array) $_GET['_value'];
-    $elements = array();
-    $list = &$elements;
-    foreach ($countries as $val) {
-      $result = CRM_Core_PseudoConstant::stateProvinceForCountry($val);
-
-      // Option-groups for multiple countries
-      if ($result && count($countries) > 1) {
-        $elements[] = array(
-          'name' => CRM_Core_PseudoConstant::country($val, FALSE),
-          'children' => array(),
-        );
-        $list = &$elements[count($elements)-1]['children'];
-      }
-      foreach ($result as $id => $name) {
-        $list[] = array(
-          'name' => $name,
-          'value' => $id,
-        );
-      }
-    }
-    $placeholder = array(array('value' => '', 'name' => $elements ? ts('- select -') : ts('- N/A -')));
-    echo json_encode(array_merge($placeholder, $elements));
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output(CRM_Core_BAO_Location::getChainSelectValues($_GET['_value'], 'country'));
   }
 
   static function jqCounty() {
-    $elements = array();
-    if (!isset($_GET['_value']) || CRM_Utils_System::isNull($_GET['_value'])) {
-      $elements = array(
-        array('name' => ts('Choose state first'), 'value' => '')
-      );
-    }
-    else {
-      $states = (array) $_GET['_value'];
-      $list = &$elements;
-      foreach ($states as $val) {
-        $result = CRM_Core_PseudoConstant::countyForState($val);
-
-        // Option-groups for multiple countries
-        if ($result && count($states) > 1) {
-          $elements[] = array(
-            'name' => CRM_Core_PseudoConstant::stateProvince($val, FALSE),
-            'children' => array(),
-          );
-          $list = &$elements[count($elements)-1]['children'];
-        }
-        foreach ($result as $id => $name) {
-          $list[] = array(
-            'name' => $name,
-            'value' => $id,
-          );
-        }
-      }
-      $placeholder = array(array('value' => '', 'name' => $elements ? ts('- select -') : ts('- N/A -')));
-      $elements = array_merge($placeholder, $elements);
-    }
-
-    echo json_encode($elements);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_JSON::output(CRM_Core_BAO_Location::getChainSelectValues($_GET['_value'], 'stateProvince'));
   }
 
   static function getLocBlock() {