Пример #1
0
 public function actionCity()
 {
     $this->stdout('Request API: Cities.', Console::FG_GREEN);
     $data = TravelPayoutsApi::getCities();
     $_count = count($data);
     $this->stdout(' Get: ' . $_count . ' Cities.' . PHP_EOL, Console::FG_GREEN);
     Console::startProgress(0, $_count);
     $count = 0;
     $count_ = 0;
     foreach ($data as $value) {
         $value->lon = !empty($value->coordinates->lon) ? (string) $value->coordinates->lon : '';
         $value->lat = !empty($value->coordinates->lat) ? (string) $value->coordinates->lat : '';
         $name_translations = $value->name_translations;
         unset($value->name_translations);
         unset($value->coordinates);
         $city = City::find()->where(['code' => $value->code])->one();
         if (!$city) {
             $this->stdout($value->code . ' ', Console::FG_YELLOW);
             $city = new City();
             $city->attributes = (array) $value;
             $local = ['en-GB', 'en-AU', 'en-CA', 'en-NZ', 'en-IE', 'en-SG', 'en-IN'];
             foreach ($name_translations as $_key => $_name) {
                 if (array_search($_key, $local) === false) {
                     $city['name_' . $_key] = trim($_name);
                 }
             }
             if (!$city->save()) {
                 print_r($value);
                 print_r($city->errors);
                 return Controller::EXIT_CODE_ERROR;
             }
             $count++;
         } else {
             Console::updateProgress(++$count_, $_count);
         }
     }
     Console::endProgress();
     $this->stdout(PHP_EOL . 'Added: ' . $count . ' Cities.' . PHP_EOL, Console::FG_BLUE);
     return Controller::EXIT_CODE_NORMAL;
 }
Пример #2
0
 public function actionCity()
 {
     $this->stdout('Request API: Cities.', Console::FG_GREEN);
     $data = TravelPayoutsApi::getCities();
     $_count = count($data);
     $this->stdout(' Get: ' . $_count . ' Cities.' . PHP_EOL, Console::FG_GREEN);
     Console::startProgress(0, $_count);
     $count = 0;
     $count_ = 0;
     foreach ($data as $value) {
         $value->coordinates_lon = !empty($value->coordinates->lon) ? (string) $value->coordinates->lon : '';
         $value->coordinates_lat = !empty($value->coordinates->lat) ? (string) $value->coordinates->lat : '';
         $name_translations = $value->name_translations;
         unset($value->name_translations);
         unset($value->coordinates);
         $city = ReceivedCity::find()->where(['code' => $value->code])->one();
         if (!$city) {
             $this->stdout($value->code . ' ', Console::FG_YELLOW);
             $city = new ReceivedCity();
             $city->attributes = (array) $value;
             $city->alias = $this->translit($value->name);
             if (!$city->save()) {
                 print_r($value);
                 print_r($city->errors);
                 return Controller::EXIT_CODE_ERROR;
             }
             $count++;
         } else {
             Console::updateProgress(++$count_, $_count);
         }
         $this->setTranslations($value->code, $name_translations, "City");
     }
     Console::endProgress();
     $this->stdout(PHP_EOL . 'Added: ' . $count . ' Cities.' . PHP_EOL, Console::FG_BLUE);
     return Controller::EXIT_CODE_NORMAL;
 }