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 @@ + + +
+ + + + field($model, 'title')->textInput() ?> + + field($model, 'parent_id')->textInput() ?> + + field($model, 'type')->textInput() ?> + + field($model, 'subtype')->textInput() ?> + + field($model, 'cover')->textInput(['maxlength' => true]) ?> + + field($model, 'options')->textInput() ?> + + field($model, 'status')->textInput() ?> + + field($model, 'sort')->textInput() ?> + +
+ isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/catalog/_search.php b/backend/views/catalog/_search.php new file mode 100644 index 0000000..c683ad8 --- /dev/null +++ b/backend/views/catalog/_search.php @@ -0,0 +1,41 @@ + + + diff --git a/backend/views/catalog/create.php b/backend/views/catalog/create.php new file mode 100644 index 0000000..f90279e --- /dev/null +++ b/backend/views/catalog/create.php @@ -0,0 +1,21 @@ +title = Yii::t('app', 'Create Catalog'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Catalogs'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/catalog/index.php b/backend/views/catalog/index.php new file mode 100644 index 0000000..596e462 --- /dev/null +++ b/backend/views/catalog/index.php @@ -0,0 +1,41 @@ +title = Yii::t('app', 'Catalogs'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'parent_id', + 'title', + 'type', + 'subtype', + // 'options', + // 'status', + // 'sort', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + +
diff --git a/backend/views/catalog/update.php b/backend/views/catalog/update.php new file mode 100644 index 0000000..57abb5b --- /dev/null +++ b/backend/views/catalog/update.php @@ -0,0 +1,23 @@ +title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Catalog', +]) . ' ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Catalogs'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/catalog/view.php b/backend/views/catalog/view.php new file mode 100644 index 0000000..4af9fa6 --- /dev/null +++ b/backend/views/catalog/view.php @@ -0,0 +1,42 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Catalogs'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'parent_id', + 'type', + 'subtype', + 'cover', + 'options', + 'status', + 'sort', + ], + ]) ?> + +
diff --git a/common/models/Catalog.php b/common/models/Catalog.php new file mode 100644 index 0000000..d26551b --- /dev/null +++ b/common/models/Catalog.php @@ -0,0 +1,71 @@ + 32], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'parent_id' => Yii::t('app', 'Parent ID'), + 'type' => Yii::t('app', 'Type'), + 'subtype' => Yii::t('app', 'Subtype'), + 'cover' => Yii::t('app', 'Cover'), + 'options' => Yii::t('app', 'Options'), + 'status' => Yii::t('app', 'Status'), + 'sort' => Yii::t('app', 'Sort'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getRelationTable() + { + return $this->hasOne(CatalogLang::className(), ['catalog' => 'id']); + } + + public function getTitle() + { + return $this->relationTable->title; + } + +} diff --git a/common/models/CatalogLang.php b/common/models/CatalogLang.php new file mode 100644 index 0000000..8e31fa3 --- /dev/null +++ b/common/models/CatalogLang.php @@ -0,0 +1,60 @@ + 1024], + [['alias'], 'string', 'max' => 128], + [['meta_title', 'meta_keywords', 'meta_description', 'full_alias'], 'string', 'max' => 255], + [['alias', 'lang_id'], 'unique', 'targetAttribute' => ['alias', 'lang_id'], 'message' => 'The combination of Lang ID and Alias has already been taken.'] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'catalog' => Yii::t('app', 'Catalog'), + 'lang_id' => Yii::t('app', 'Lang ID'), + 'title' => Yii::t('app', 'Title'), + 'alias' => Yii::t('app', 'Alias'), + 'meta_title' => Yii::t('app', 'Meta Title'), + 'meta_keywords' => Yii::t('app', 'Meta Keywords'), + 'meta_description' => Yii::t('app', 'Meta Description'), + 'full_alias' => Yii::t('app', 'Full Alias'), + ]; + } +} -- libgit2 0.21.4