protected function _query() { $query = Country::find(); $currentLanguage = substr(Translation::current(), 0, 2); $local = new Expression("'{$currentLanguage}'"); $fallbackLanguage = substr(Translation::fallback(), 0, 2); $fallback = new Expression("'{$fallbackLanguage}'"); $query->leftJoin('country_translation default_label', "(`country`.`iso_2`=`default_label`.`country_id` AND {$fallback}=`default_label`.`language_id`)"); $query->leftJoin('country_translation localised_label', "(`country`.`iso_2`=`localised_label`.`country_id` AND {$local} =`localised_label`.`language_id`)"); $query->select = ['code' => 'iso_2', 'label' => 'CONCAT(IF(localised_label.common_name IS NULL, default_label.common_name,localised_label.common_name),\' (\',iso_2,\')\')', 'has_postcodes' => 'has_postcodes', 'common_name' => 'IF(localised_label.common_name IS NULL, default_label.common_name,localised_label.common_name)', 'official_name' => 'IF(localised_label.official_name IS NULL, default_label.official_name,localised_label.official_name)', 'common' => 'IF(localised_label.common_name IS NULL, default_label.common_name,localised_label.common_name)', 'official' => 'IF(localised_label.official_name IS NULL, default_label.official_name,localised_label.official_name)']; $query->groupBy('code'); return $query; }
public function actionDummyData() { $countries = \humanized\location\models\location\Country::find()->select('iso_2')->asArray()->all(); foreach ($countries as $country) { $countryId = $country['iso_2']; $this->_dummyLocation($countryId, '!UNSET', '0'); $this->_dummyLocation($countryId, '!UNKNOWN', '-1'); } }
public static function getCountryList($params) { return Country::find()->asArray()->all(); }