Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/country_states_helper.php
Show First 20 Lines • Show All 218 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
return $id; | return $id; | ||||
} | } | ||||
/** | /** | ||||
* Returns 3 symbols ISO code from 2 symbols ISO code or otherwise, when $from_short parameter is used | * Returns 3 symbols ISO code from 2 symbols ISO code or otherwise, when $from_short parameter is used | ||||
* | * | ||||
* @param string $iso_code | * @param string $iso_code ISO code. | ||||
* @param bool $from_short | * @param boolean $from_short From short. | ||||
* | |||||
* @return string | * @return string | ||||
*/ | */ | ||||
function getCountryIso($iso_code, $from_short = false) | public function getCountryIso($iso_code, $from_short = false) | ||||
{ | { | ||||
if ($from_short) { | $cache_key = 'country_iso_mapping[%CountryStateSerial%]'; | ||||
$sql = 'SELECT IsoCode | $cache_value = $this->Application->getCache($cache_key); | ||||
FROM ' . TABLE_PREFIX . 'CountryStates | |||||
WHERE ShortIsoCode = ' . $this->Conn->qstr($iso_code) . ' AND `Type` = ' . DESTINATION_TYPE_COUNTRY; | if ( $cache_value === false ) { | ||||
} | $sql = 'SELECT IsoCode, ShortIsoCode | ||||
else { | |||||
$sql = 'SELECT ShortIsoCode | |||||
FROM ' . TABLE_PREFIX . 'CountryStates | FROM ' . TABLE_PREFIX . 'CountryStates | ||||
WHERE IsoCode = ' . $this->Conn->qstr($iso_code) . ' AND `Type` = ' . DESTINATION_TYPE_COUNTRY; | WHERE `Type` = ' . DESTINATION_TYPE_COUNTRY; | ||||
$cache_value = $this->Conn->GetCol($sql, 'ShortIsoCode'); | |||||
$this->Application->setCache($cache_key, $cache_value); | |||||
} | } | ||||
return $this->Conn->GetOne($sql); | return $from_short ? $cache_value[$iso_code] : array_search($iso_code, $cache_value); | ||||
} | } | ||||
} | } |