/**
  * @return \yii\db\ActiveQuery
  */
 public function getCity()
 {
     return $this->hasOne(ReceivedCity::className(), ['code' => 'city_code']);
 }
Beispiel #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCity()
 {
     return $this->hasMany(ReceivedCity::className(), ['country_code' => 'code'])->with('translations');
 }
 public function actionCityAlias()
 {
     $this->stdout('Generate alias: City.' . PHP_EOL, Console::FG_GREEN);
     $language = ReceivedLanguage::find()->indexBy('id')->asArray()->all();
     $city = ReceivedCity::find()->indexBy('code')->all();
     $translations = ReceivedCityTranslation::find()->asArray()->all();
     $translation = [];
     foreach ($translations as $value) {
         $alias = $this->translit($value['name']);
         if ($value['language_id'] == 3 || $value['language_id'] == 9) {
             $translation[$value['city_code']][$value['language_id']] = $alias;
         } else {
             $translation[$value['city_code']][$value['language_id']] = preg_replace('~[^a-z0-9_-]~i', '*', $alias);
         }
     }
     $count = count($city);
     Console::startProgress(0, $count);
     $count_ = 0;
     foreach ($city as $value) {
         $value->alias_de = $value->alias;
         $value->alias_en = $value->alias;
         $value['alias_zh-CN'] = $value->alias;
         $value->alias_tr = $value->alias;
         $value->alias_ru = $value->alias;
         $value->alias_fr = $value->alias;
         $value->alias_es = $value->alias;
         $value->alias_it = $value->alias;
         $value->alias_th = $value->alias;
         foreach ($translation[$value->code] as $key => $_value) {
             if ($_value != '') {
                 switch ($language[$key]['code']) {
                     case 'de':
                         $value->alias_de = $_value;
                         break;
                     case 'en':
                         $value->alias_en = $_value;
                         break;
                         //                        case 'zh-CN':
                         //                            $value['alias_zh-CN'] = $_value;
                         //                            break;
                     //                        case 'zh-CN':
                     //                            $value['alias_zh-CN'] = $_value;
                     //                            break;
                     case 'tr':
                         $value->alias_tr = $_value;
                         break;
                     case 'ru':
                         $value->alias_ru = $_value;
                         break;
                     case 'fr':
                         $value->alias_fr = $_value;
                         break;
                     case 'es':
                         $value->alias_es = $_value;
                         break;
                     case 'it':
                         $value->alias_it = $_value;
                         break;
                         //                        case 'th':
                         //                            $value->alias_th = $_value;
                         //                            break;
                 }
             }
         }
         if (!$value->save()) {
             print_r($value->attributes);
             print_r($value->errors);
             return Controller::EXIT_CODE_ERROR;
         }
         Console::updateProgress(++$count_, $count);
     }
     Console::endProgress();
     return Controller::EXIT_CODE_NORMAL;
 }
Beispiel #4
0
 public static function getDirection($params = [])
 {
     // VarDumper::dump($params,1);
     $params['language_id'] = TFA::$info['language_id'];
     self::$params = array_merge(self::$params, $params);
     $query = ReceivedDirection::find()->asArray();
     $dataProvider = new ActiveDataProvider(['query' => $query->with('iata')->with(['from' => function ($query) {
         /** @var $query \yii\db\ActiveQuery */
         if (!empty(self::$params['language_id'])) {
             $query->with(['translations' => function ($query) {
                 /** @var $query \yii\db\ActiveQuery */
                 $query->andFilterWhere(['language_id' => self::$params['language_id']])->indexBy('language_id');
             }]);
         }
         $query->with(['country' => function ($query) {
             /** @var $query \yii\db\ActiveQuery */
             if (!empty(self::$params['language_id'])) {
                 $query->with(['translations' => function ($query) {
                     /** @var $query \yii\db\ActiveQuery */
                     $query->andFilterWhere(['language_id' => self::$params['language_id']])->indexBy('language_id');
                 }]);
             }
         }]);
         //                    $query->with(['airports' => function ($query) {
         //                        /** @var $query \yii\db\ActiveQuery */
         //                        if (!empty(self::$params['language_id'])) {
         //                            $query->with(['translations' => function ($query) {
         //                                /** @var $query \yii\db\ActiveQuery */
         //                                $query->andFilterWhere(['language_id' => self::$params['language_id']])->indexBy('language_id');
         //                            }]);
         //                        }
         //                    }]);
     }])->with(['to' => function ($query) {
         /** @var $query \yii\db\ActiveQuery */
         if (!empty(self::$params['language_id'])) {
             $query->with(['translations' => function ($query) {
                 /** @var $query \yii\db\ActiveQuery */
                 $query->andFilterWhere(['language_id' => self::$params['language_id']])->indexBy('language_id');
             }]);
         }
         $query->with(['country' => function ($query) {
             /** @var $query \yii\db\ActiveQuery */
             if (!empty(self::$params['language_id'])) {
                 $query->with(['translations' => function ($query) {
                     /** @var $query \yii\db\ActiveQuery */
                     $query->andFilterWhere(['language_id' => self::$params['language_id']])->indexBy('language_id');
                 }]);
             }
         }]);
         //                    $query->with(['airports' => function ($query) {
         //                        /** @var $query \yii\db\ActiveQuery */
         //                        if (!empty(self::$params['language_id'])) {
         //                            $query->with(['translations' => function ($query) {
         //                                /** @var $query \yii\db\ActiveQuery */
         //                                $query->andFilterWhere(['language_id' => self::$params['language_id']])->indexBy('language_id');
         //                            }]);
         //                        }
         //                    }]);
     }]), 'pagination' => ['pageSize' => self::$params['pageSize'], 'pageSizeParam' => false], 'sort' => ['defaultOrder' => ['popularity' => SORT_DESC], 'attributes' => ['popularity', 'iata_code', 'city_to_code']]]);
     if (!empty(self::$params['country_from_alias'])) {
         $county = ReceivedCity::find()->select(['t1.code'])->asArray()->from(['t1' => 'received_city', 't2' => 'received_country'])->where('t1.country_code = t2.code AND t2.alias_' . TFA::$info['language']['code'] . '=:alias', [':alias' => self::$params['country_from_alias']])->all();
         $city_code = [];
         foreach ($county as $value) {
             $city_code[] = $value['code'];
         }
         $city_code = array_unique($city_code);
         $query->andFilterWhere(['city_from_code' => $city_code]);
     } elseif (!empty(self::$params['city_from_alias'])) {
         $city = ReceivedCity::find()->select('code')->where(['alias_' . TFA::$info['language']['code'] => self::$params['city_from_alias']])->asArray()->all();
         $city_code = [];
         foreach ($city as $value) {
             $city_code[] = $value['code'];
         }
         $city_code = array_unique($city_code);
         if ($city_code) {
             $query->andFilterWhere(['city_from_code' => $city_code]);
         }
     } elseif (!empty(self::$params['city_from_code'])) {
         $query->andFilterWhere(['city_from_code' => self::$params['city_from_code']]);
     }
     if (!empty(self::$params['country_to_alias'])) {
         $county = ReceivedCity::find()->select(['t1.code'])->asArray()->from(['t1' => 'received_city', 't2' => 'received_country'])->where('t1.country_code = t2.code AND t2.alias_' . TFA::$info['language']['code'] . '=:alias', [':alias' => self::$params['country_to_alias']])->all();
         $city_code = [];
         foreach ($county as $value) {
             $city_code[] = $value['code'];
         }
         $city_code = array_unique($city_code);
         $query->andFilterWhere(['city_to_code' => $city_code]);
     } elseif (!empty(self::$params['city_to_alias'])) {
         $city = ReceivedCity::find()->where(['alias_' . TFA::$info['language']['code'] => self::$params['city_to_alias']])->asArray()->all();
         $city_code = [];
         foreach ($city as $value) {
             $city_code[] = $value['code'];
         }
         $city_code = array_unique($city_code);
         if ($city_code) {
             $query->andFilterWhere(['city_to_code' => $city_code]);
         }
     } elseif (!empty(self::$params['city_to_code'])) {
         $query->andFilterWhere(['city_to_code' => self::$params['city_to_code']]);
     }
     if (!empty(self::$params['iata_code'])) {
         $query->andFilterWhere(['iata_code' => self::$params['iata_code']]);
     }
     if (self::$params['direction_all'] === false) {
         $query->groupBy(['city_to_code', 'city_from_code']);
     }
     $dataProvider->query = $query;
     return $dataProvider;
 }