/**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProjectCategorySecond::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'locale', $this->locale]);
     return $dataProvider;
 }
 /**
  * Finds the ProjectCategorySecond model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ProjectCategorySecond the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ProjectCategorySecond::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#3
0
 /**
  * Updates an existing Project 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 = Project::getLocaleInstance($key);
         $dataModel = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one();
         $dataModel->categoriesList = $this->getCategoriesListIds($dataModel->id);
         $dataModel->categoriesListSecond = $this->getCategoriesListSecondIds($dataModel->id);
         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->attributes = $firstModel->attributes;
             $currentModel->attachments = $firstModel->attachments;
             $currentModel->thumbnail = $firstModel->thumbnail;
             $currentModel->categoriesList = $firstModel->categoriesList;
             $currentModel->categoriesListSecond = $firstModel->categoriesListSecond;
             $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()) && Project::multiSave($model)) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'categories' => \yii\helpers\ArrayHelper::map(ProjectCategory::find()->active()->all(), 'id', 'title'), 'categoriesSecond' => \yii\helpers\ArrayHelper::map(ProjectCategorySecond::find()->active()->all(), 'id', 'title'), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }