Index: branches/5.2.x/core/units/helpers/country_states_helper.php =================================================================== diff -u -N -r14628 -r14820 --- branches/5.2.x/core/units/helpers/country_states_helper.php (.../country_states_helper.php) (revision 14628) +++ branches/5.2.x/core/units/helpers/country_states_helper.php (.../country_states_helper.php) (revision 14820) @@ -1,6 +1,6 @@ getCountryStateId($country_iso, DESTINATION_TYPE_COUNTRY); + $states = $this->getStates($country_iso); - if (!$country_id) { - return ; + if ( !$states ) { + return; } - // don't use GetVar('m_lang') since it's always equals to default language on editing form in admin - $current_language = $this->Application->Phrases->LanguageId; - $primary_language = $this->Application->GetDefaultLanguageId(); - - $sql = 'SELECT IF(l' . $current_language . '_Name = "", l' . $primary_language . '_Name, l' . $current_language . '_Name) AS Name, IsoCode - FROM ' . $this->Application->getUnitOption('country-state', 'TableName') . ' - WHERE (Type = ' . DESTINATION_TYPE_STATE . ') AND (StateCountryId = ' . $country_id . ') - ORDER BY Name ASC'; - $cache[$country_iso] = $this->Conn->GetCol($sql, 'IsoCode'); + $cache[$country_iso] = $states; } $field_options = $object->GetFieldOptions($state_field); @@ -96,6 +88,32 @@ } /** + * Returns list of given country states + * + * @param string $country_iso + * @return Array + */ + public function getStates($country_iso) + { + $country_id = $this->getCountryStateId($country_iso, DESTINATION_TYPE_COUNTRY); + + if ( !$country_id ) { + return Array (); + } + + // don't use GetVar('m_lang') since it's always equals to default language on editing form in admin + $current_language = $this->Application->Phrases->LanguageId; + $primary_language = $this->Application->GetDefaultLanguageId(); + + $sql = 'SELECT IF(l' . $current_language . '_Name = "", l' . $primary_language . '_Name, l' . $current_language . '_Name) AS Name, IsoCode + FROM ' . $this->Application->getUnitOption('country-state', 'TableName') . ' + WHERE (Type = ' . DESTINATION_TYPE_STATE . ') AND (StateCountryId = ' . $country_id . ') + ORDER BY Name ASC'; + + return $this->Conn->GetCol($sql, 'IsoCode'); + } + + /** * Returns valid state ISO code for state name and country code passed * * @param string $state_name Index: branches/5.2.x/core/units/country_states/country_state_eh.php =================================================================== diff -u -N -r14628 -r14820 --- branches/5.2.x/core/units/country_states/country_state_eh.php (.../country_state_eh.php) (revision 14628) +++ branches/5.2.x/core/units/country_states/country_state_eh.php (.../country_state_eh.php) (revision 14820) @@ -1,6 +1,6 @@ Array ('self' => true), + ); + + $this->permMapping = array_merge($this->permMapping, $permissions); + } + /** * Applies edit picker filters * @@ -114,4 +125,22 @@ return ; } } + + /** + * Returns given country states in JSON format + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnGetStatesJSON(kEvent &$event) + { + $event->status = kEvent::erSTOP; + + $cs_helper =& $this->Application->recallObject('CountryStatesHelper'); + /* @var $cs_helper kCountryStatesHelper */ + + $states = $cs_helper->getStates( (string)$this->Application->GetVar('country_iso') ); + echo json_encode($states); + } }