// Code cleaning

This commit is contained in:
Damien Metzger committed 2013-07-23 09:50:26 +02:00
1 parent 9169995adc
commit 07e3354d0e
1 file changed
+14 -11
+14 -11
View File
@@ -121,19 +121,22 @@ class CountryCore extends ObjectModel
public static function getCountries($id_lang, $active = false, $contain_states = false, $list_states = true) public static function getCountries($id_lang, $active = false, $contain_states = false, $list_states = true)
{ {
$countries = array(); $countries = array();
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT cl.*,c.*, cl.`name` country, z.`name` zone $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
FROM `'._DB_PREFIX_.'country` c '.Shop::addSqlAssociation('country', 'c').' SELECT cl.*,c.*, cl.`name` country, z.`name` zone
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country` AND cl.`id_lang` = '.(int)$id_lang.') FROM `'._DB_PREFIX_.'country` c '.Shop::addSqlAssociation('country', 'c').'
LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = c.`id_zone`) LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country` AND cl.`id_lang` = '.(int)$id_lang.')
WHERE 1'.($active ? ' AND c.active = 1' : '').($contain_states ? ' AND c.`contains_states` = '.(int)$contain_states : '').' LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = c.`id_zone`)
ORDER BY cl.name ASC') as $country) WHERE 1'.($active ? ' AND c.active = 1' : '').($contain_states ? ' AND c.`contains_states` = '.(int)$contain_states : '').'
$countries[$country['id_country']] = $country; ORDER BY cl.name ASC');
foreach ($result as $row)
$countries[$row['id_country']] = $row;
if ($list_states) if ($list_states)
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'state` ORDER BY `name` ASC') as $state) {
if (isset($countries[$state['id_country']])) /* Does not keep the state if its country has been disabled and not selected */ $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'state` ORDER BY `name` ASC');
if ($state['active'] == 1) foreach ($result as $row)
$countries[$state['id_country']]['states'][] = $state; if (isset($countries[$row['id_country']]) && $row['active'] == 1) /* Does not keep the state if its country has been disabled and not selected */
$countries[$row['id_country']]['states'][] = $row;
return $countries; return $countries;
} }