Ejemplo n.º 1
0
 public function actionAirportAlias()
 {
     $this->stdout('Generate alias: Airport.' . PHP_EOL, Console::FG_GREEN);
     $language = ReceivedLanguage::find()->indexBy('id')->asArray()->all();
     $airport = ReceivedAirport::find()->indexBy('code')->all();
     $translations = ReceivedAirportTranslation::find()->asArray()->all();
     $translation = [];
     foreach ($translations as $value) {
         $alias = $this->translit($value['name']);
         if ($value['language_id'] == 3 || $value['language_id'] == 9) {
             $translation[$value['airport_code']][$value['language_id']] = $alias;
         } else {
             $translation[$value['airport_code']][$value['language_id']] = preg_replace('~[^a-z0-9_-]~i', '*', $alias);
         }
     }
     $count = count($airport);
     Console::startProgress(0, $count);
     $count_ = 0;
     foreach ($airport 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;
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTranslations()
 {
     return $this->hasMany(ReceivedAirportTranslation::className(), ['airport_code' => 'code'])->where(['language_id' => \common\components\TFA::$info['language_id']])->indexBy('language_id');
 }