コード例 #1
0
 /**
  * Updates an existing Block model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $firstModel = $this->findModel($id);
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Block::getLocaleInstance($key);
         $dataModel = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one();
         if (!empty($dataModel->domain)) {
             $dataModel->domain = explode(',', $dataModel->domain);
         }
         $models[$key] = $dataModel;
         if (!$models[$key]) {
             //\yii\helpers\VarDumper::dump($firstModel->attributes,11,1); die();
             $currentModel->locale_group_id = $firstModel->locale_group_id;
             $currentModel->locale = $key;
             $currentModel->title = 'title ' . $key . ' ' . time();
             $currentModel->slug = '';
             $models[$key] = $currentModel;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Block::multiSave($model)) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
コード例 #2
0
 /**
  * @return string|\yii\web\Response
  */
 public function actionIndex()
 {
     $accountModel = new AccountForm();
     $accountModel->setUser(Yii::$app->user->identity);
     $model = new MultiModel(['models' => ['account' => $accountModel, 'profile' => Yii::$app->user->identity->userProfile]]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-success'], 'body' => Yii::t('frontend', 'Your account has been successfully saved')]);
         return $this->refresh();
     }
     return $this->render('index', ['model' => $model]);
 }
コード例 #3
0
 public function actionProfile()
 {
     $profile = Yii::$app->user->identity->userProfile;
     $domain = Yii::$app->user->identity->domain;
     if ($domain == null) {
         $model = new MultiModel(['models' => ['profile' => $profile]]);
     } else {
         $model = new MultiModel(['models' => ['profile' => $profile, 'domain' => $domain]]);
     }
     if ($model->load($_POST) && $model->save()) {
         Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-success'], 'body' => Yii::t('backend', 'Your account has been successfully saved', [], $model->getmodel('profile')->locale)]);
         return $this->refresh();
     }
     return $this->render('profile', ['model' => $model]);
 }
コード例 #4
0
 /**
  * Updates an existing Page model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $firstModel = $this->findModel($id);
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Page::getLocaleInstance($key);
         $models[$key] = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one();
         if (!$models[$key]) {
             $currentModel->attributes = $firstModel->attributes;
             $currentModel->locale_group_id = $firstModel->locale_group_id;
             $currentModel->locale = $key;
             $currentModel->title = 'title ' . $key . ' ' . time();
             $currentModel->slug = '';
             $models[$key] = $currentModel;
         }
     }
     //\yii\helpers\VarDumper::dump($models,11,1); die();
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Page::multiSave($model)) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
コード例 #5
0
 /**
  * Updates an existing AboutPage model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $firstModel = $this->findModel($id);
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = AboutPage::getLocaleInstance($key);
         $dataModel = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one();
         $dataModel->categoriesList = $this->getCategoriesListIds($dataModel->id);
         if (!empty($dataModel->domain)) {
             $dataModel->domain = explode(',', $dataModel->domain);
         }
         $models[$key] = $dataModel;
         if (!$models[$key]) {
             $currentModel->attributes = $firstModel->attributes;
             $currentModel->attachments = $firstModel->attachments;
             $currentModel->thumbnail = $firstModel->thumbnail;
             $currentModel->categoriesList = $firstModel->categoriesList;
             //$currentModel->video = $firstModel->video;
             $currentModel->locale_group_id = $firstModel->locale_group_id;
             $currentModel->locale = $key;
             $currentModel->title = 'title ' . $key . ' ' . time();
             $currentModel->descripton = $firstModel->description;
             $currentModel->about_id = $firstModel->about_id;
             $currentModel->slug = '';
             $models[$key] = $currentModel;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && AboutPage::multiSave($model)) {
         return $this->redirect(['index', 'mid' => $model->getModel(Yii::$app->language)->about_id]);
     } else {
         switch ($firstModel->on_scenario) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'update';
         }
         return $this->render($viewName, ['model' => $model, 'categories' => AboutPageCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
コード例 #6
0
 /**
  * Updates an existing Article model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $firstModel = $this->findModel($id);
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Article::getLocaleInstance($key);
         $dataModel = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one();
         $dataModel->categoriesList = $this->getCategoriesListIds($dataModel->id);
         if (!empty($dataModel->domain)) {
             $dataModel->domain = explode(',', $dataModel->domain);
         }
         $models[$key] = $dataModel;
         if (!$models[$key]) {
             $currentModel->attributes = $firstModel->attributes;
             $currentModel->attachments = $firstModel->attachments;
             $currentModel->thumbnail = $firstModel->thumbnail;
             $currentModel->image = $firstModel->image;
             $currentModel->categoriesList = $firstModel->categoriesList;
             //$currentModel->video = $firstModel->video;
             $currentModel->locale_group_id = $firstModel->locale_group_id;
             $currentModel->locale = $key;
             $currentModel->title = 'title ' . $key . ' ' . time();
             $currentModel->slug = '';
             $models[$key] = $currentModel;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Article::multiSaveUpdate($model)) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
コード例 #7
0
ファイル: PriceController.php プロジェクト: efabrikov/renault
 /**
  * Updates an existing Model model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $firstModel = $this->findModel($id);
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Price::getLocaleInstance($key);
         $dataModel = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one();
         //            $dataModel->categoriesList = $this->getCategoriesListIds($dataModel->id);
         if (!empty($dataModel->domain)) {
             $dataModel->domain = explode(',', $dataModel->domain);
         }
         $models[$key] = $dataModel;
         if (!$models[$key]) {
             $currentModel->model = $value->model;
             $currentModel->version_code = $value->version_code;
             $currentModel->body_type = $value->body_type;
             $currentModel->price = $value->price;
             $currentModel->locale_group_id = $firstModel->locale_group_id;
             $currentModel->locale = $key;
             $models[$key] = $currentModel;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Price::multiSave($model)) {
         return $this->redirect(['index']);
     } else {
         switch ($firstModel->on_scenario) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'update';
         }
         return $this->render($viewName, ['model' => $model, 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
コード例 #8
0
ファイル: Price.php プロジェクト: efabrikov/renault
 public function onImportRow($row, $index, $max_row)
 {
     //        \yii\helpers\VarDumper::dump($row);
     $this->addLog(implode(' / ', $row));
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Price::getLocaleInstance($key);
         $currentModel->locale = $key;
         if (Yii::$app->request->get('scenario')) {
             $currentModel->on_scenario = Yii::$app->request->get('scenario');
         }
         $models[$key] = $currentModel;
     }
     //set data from default model
     //        if (Yii::$app->request->get('locale_group_id')) {
     //
     //            $defaultDomainModels = Price::find()
     //                ->andFilterWhere([
     //                    'domain_id'       => Yii::getAlias('@defaultDomainId'),
     //                    'locale_group_id' => Yii::$app->request->get('locale_group_id')
     //                ])
     //                ->all();
     //
     //            foreach ($defaultDomainModels as $key => $value) {
     //                if (!in_array(
     //                    $value->locale, array_keys(
     //                        Yii::$app->params['availableLocales']
     //                    )
     //                )
     //                ) {
     //                    continue;
     //                };
     //
     //                $models[$value->locale]->model        = $row[0];
     //                $models[$value->locale]->version        = $row[1];
     //                $models[$value->locale]->version_code       = $row[2];
     //                $models[$value->locale]->body_type        = $row[3];
     //                $models[$value->locale]->price       = $row[4];
     //                $arr = ['PriceUkUA' => [
     //                    'model' => $row[0],
     //                    'version' => $row[1],
     //                    'version_code' => $row[2],
     //                    'body_type' => $row[3],
     //                    'price' => $row[4],
     //                    'weight' => '',
     //                    'status' => '1',
     //                ],
     //                    'PriceRuRU' => [
     //                        'model' => '',
     //                        'version' => '',
     //                        'version_code' => '',
     //                        'body_type' => '',
     //                        'price' => '',
     //                        'weight' => '',
     //                        'status' => '0',
     //                    ]];
     //            }
     //        }
     $model = new MultiModel(['models' => $models]);
     $arr = ['PriceUkUA' => ['model' => $row[0], 'version' => $row[1], 'version_code' => $row[2], 'body_type' => $row[3], 'price' => $row[4], 'weight' => '', 'status' => '1'], 'PriceRuRU' => ['model' => '', 'version' => '', 'version_code' => '', 'body_type' => '', 'price' => '', 'weight' => '', 'status' => '0']];
     //        \yii\helpers\VarDumper::dump($arr, 11,1); die();
     if ($model->load($arr) && Price::multiSave($model)) {
         //            return $this->redirect(['index']);
     } else {
         //            switch (Yii::$app->request->get('scenario')) {
         //                case 'extend' :
         //                    $viewName = 'extend';
         //                    break;
         //                default :
         //                    $viewName = 'create';
         //            }
         //            return $this->render($viewName, [
         //                'model'      => $model,
         //
         //                'domains'    => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))
         //            ]);
     }
     return true;
     // return FALSE to stop import
 }