Пример #1
0
 /**
  * Creates a new Country model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Country();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates a new Country model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Country();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', Yii::t('app', 'Saved'));
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #3
0
 public function actionCountry()
 {
     $this->stdout('Request API: Countries.', Console::FG_GREEN);
     $data = TravelPayoutsApi::getCountries();
     $_count = count($data);
     $this->stdout(' Get: ' . $_count . ' Countries.' . PHP_EOL, Console::FG_GREEN);
     Console::startProgress(0, $_count);
     $count = 0;
     $count_ = 0;
     foreach ($data as $value) {
         $name_translations = $value->name_translations;
         unset($value->name_translations);
         $country = Country::find()->where(['code' => $value->code])->one();
         if (!$country) {
             $this->stdout($value->code . ' ', Console::FG_YELLOW);
             $country = new Country();
             $country->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) {
                     $country['name_' . $_key] = trim($_name);
                 }
             }
             if (!$country->save()) {
                 print_r($value);
                 print_r($country->errors);
                 return Controller::EXIT_CODE_ERROR;
             }
             $count++;
         } else {
             Console::updateProgress(++$count_, $_count);
         }
     }
     Console::endProgress();
     $this->stdout(PHP_EOL . 'Added: ' . $count . ' Countries.' . PHP_EOL, Console::FG_BLUE);
     return Controller::EXIT_CODE_NORMAL;
 }