Esempio n. 1
0
 /**
  * Updates an existing About model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $firstAbout = $this->findAbout($id);
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentAbout = About::getLocaleInstance($key);
         $dataAbout = $currentAbout::find()->andWhere(['locale_group_id' => $firstAbout->locale_group_id, 'locale' => $key])->one();
         $dataAbout->categoriesList = $this->getCategoriesListIds($dataAbout->id);
         if (!empty($dataAbout->domain)) {
             $dataAbout->domain = explode(',', $dataAbout->domain);
         }
         $abouts[$key] = $dataAbout;
         if (!$abouts[$key]) {
             $currentAbout->attributes = $firstAbout->attributes;
             $currentAbout->attachments = $firstAbout->attachments;
             $currentAbout->thumbnail = $firstAbout->thumbnail;
             //TODO: thumbnail copy fix
             $currentAbout->categoriesList = $firstAbout->categoriesList;
             //$currentAbout->video = $firstAbout->video;
             $currentAbout->locale_group_id = $firstAbout->locale_group_id;
             $currentAbout->locale = $key;
             $currentAbout->title = 'title ' . $key . ' ' . time();
             $currentAbout->descripton = $firstAbout->description;
             $currentAbout->price = $firstAbout->price;
             $currentAbout->slug = '';
             $abouts[$key] = $currentAbout;
         }
     }
     $about = new MultiModel(['models' => $abouts]);
     if ($about->load(Yii::$app->request->post()) && About::multiSave($about)) {
         return $this->redirect(['index']);
     } else {
         switch ($firstAbout->on_scenario) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'update';
         }
         return $this->render($viewName, ['model' => $about, 'categories' => AboutCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }