diff --git a/backend/controllers/CatalogController.php b/backend/controllers/CatalogController.php new file mode 100644 index 0000000..f848427 --- /dev/null +++ b/backend/controllers/CatalogController.php @@ -0,0 +1,142 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all Catalog models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SearchCatalog(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Catalog model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Catalog model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Catalog(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) + { + return $this->redirect(['view', 'id' => $model->id]); + } + else + { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Catalog model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_lang = CatalogLang::find() + ->where(['catalog' => $id, 'lang_id' => 1]) + ->one(); +//die(); + if ($model->load(Yii::$app->request->post())) + { + + //var_dump($model->title);die(); + echo $model_lang->title = $model->title; + + //var_dump($model->save());die(); + $model->save(); + $model_lang->save(); + + return $this->redirect(['view', 'id' => $model->id]); + } + else + { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Catalog model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Catalog model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Catalog the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Catalog::findOne($id)) !== null) + { + return $model; + } + else + { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/SearchCatalog.php b/backend/models/SearchCatalog.php new file mode 100644 index 0000000..3721f44 --- /dev/null +++ b/backend/models/SearchCatalog.php @@ -0,0 +1,101 @@ + $query, + ]); + + // + поиск по title + $dataProvider->setSort([ + 'attributes' => [ + 'id', + 'title' => [ + 'asc' => ['title' => SORT_ASC], + 'desc' => ['title' => SORT_DESC], + 'label' => 'title', + 'default' => SORT_ASC + ] + ] + ]); + + $this->load($params); + + if (!$this->validate()) + { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + + // + поиск по title + $query->joinWith(['catalog_i18n']); + + return $dataProvider; + } + + $query->andFilterWhere([ + 'id' => $this->id, + 'parent_id' => $this->parent_id, + 'type' => $this->type, + 'subtype' => $this->subtype, + 'status' => $this->status, + 'sort' => $this->sort, + ]); + + $query->andFilterWhere(['like', 'cover', $this->cover]) + ->andFilterWhere(['like', 'options', $this->options]); + + // + поиск по title + $query->joinWith(['relationTable' => function ($q) + { + //$q->where("catalog_i18n.title LIKE '%". $this->title . "%'"); + $q->where(['like', 'catalog_i18n.title', $this->title]); + }]); + + return $dataProvider; + } +} diff --git a/backend/views/catalog/_form.php b/backend/views/catalog/_form.php new file mode 100644 index 0000000..d37774e --- /dev/null +++ b/backend/views/catalog/_form.php @@ -0,0 +1,37 @@ + + +
+ = Html::a(Yii::t('app', 'Create Catalog'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'parent_id', + 'title', + 'type', + 'subtype', + // 'options', + // 'status', + // 'sort', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + ++ = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'parent_id', + 'type', + 'subtype', + 'cover', + 'options', + 'status', + 'sort', + ], + ]) ?> + +