From fa68c38d3a8a0c7dffcdcaf134c77d5a2e2e84ac Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 14 Apr 2016 11:16:12 +0300 Subject: [PATCH] 12.04.16 finish event, service --- backend/config/main.php | 2 ++ backend/controllers/SeoCategoryController.php | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/controllers/SeoDynamicController.php | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/layouts/main-sidebar.php | 9 ++++++++- backend/views/seo-category/_form.php | 27 +++++++++++++++++++++++++++ backend/views/seo-category/_search.php | 33 +++++++++++++++++++++++++++++++++ backend/views/seo-category/create.php | 21 +++++++++++++++++++++ backend/views/seo-category/index.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/seo-category/update.php | 23 +++++++++++++++++++++++ backend/views/seo-category/view.php | 38 ++++++++++++++++++++++++++++++++++++++ backend/views/seo-dynamic/_form.php | 37 +++++++++++++++++++++++++++++++++++++ backend/views/seo-dynamic/_search.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ backend/views/seo-dynamic/create.php | 22 ++++++++++++++++++++++ backend/views/seo-dynamic/index.php | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/seo-dynamic/update.php | 24 ++++++++++++++++++++++++ backend/views/seo-dynamic/view.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ backend/views/seo/_form.php | 31 +++++++++++++++++++++++++++++++ backend/views/seo/_search.php | 37 +++++++++++++++++++++++++++++++++++++ backend/views/seo/create.php | 21 +++++++++++++++++++++ backend/views/seo/index.php | 37 +++++++++++++++++++++++++++++++++++++ backend/views/seo/update.php | 23 +++++++++++++++++++++++ backend/views/seo/view.php | 40 ++++++++++++++++++++++++++++++++++++++++ common/models/SeoCategory.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/SeoCategorySearch.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/SeoDynamic.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/SeoDynamicSearch.php | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m160412_133944_create_seo_category.php | 30 ++++++++++++++++++++++++++++++ console/migrations/m160413_112158_create_seo_dynamic.php | 39 +++++++++++++++++++++++++++++++++++++++ frontend/views/event/index.php | 5 +++++ frontend/views/event/view.php | 7 +++++-- frontend/views/layouts/main.php | 21 ++++++++++++++++++++- frontend/widgets/Seo.php | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 32 files changed, 1339 insertions(+), 13 deletions(-) create mode 100644 backend/controllers/SeoCategoryController.php create mode 100644 backend/controllers/SeoDynamicController.php create mode 100644 backend/views/seo-category/_form.php create mode 100644 backend/views/seo-category/_search.php create mode 100644 backend/views/seo-category/create.php create mode 100644 backend/views/seo-category/index.php create mode 100644 backend/views/seo-category/update.php create mode 100644 backend/views/seo-category/view.php create mode 100644 backend/views/seo-dynamic/_form.php create mode 100644 backend/views/seo-dynamic/_search.php create mode 100644 backend/views/seo-dynamic/create.php create mode 100644 backend/views/seo-dynamic/index.php create mode 100644 backend/views/seo-dynamic/update.php create mode 100644 backend/views/seo-dynamic/view.php create mode 100644 backend/views/seo/_form.php create mode 100644 backend/views/seo/_search.php create mode 100644 backend/views/seo/create.php create mode 100644 backend/views/seo/index.php create mode 100644 backend/views/seo/update.php create mode 100644 backend/views/seo/view.php create mode 100644 common/models/SeoCategory.php create mode 100644 common/models/SeoCategorySearch.php create mode 100644 common/models/SeoDynamic.php create mode 100644 common/models/SeoDynamicSearch.php create mode 100644 console/migrations/m160412_133944_create_seo_category.php create mode 100644 console/migrations/m160413_112158_create_seo_dynamic.php diff --git a/backend/config/main.php b/backend/config/main.php index cb6ead6..03589cf 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -61,6 +61,8 @@ return [ 'rules' => [ 'slider-image///' => 'slider-image/', 'slider-image//' => 'slider-image/', + 'seo-dynamic///' => 'seo-dynamic/', + 'seo-dynamic//' => 'seo-dynamic/', ] diff --git a/backend/controllers/SeoCategoryController.php b/backend/controllers/SeoCategoryController.php new file mode 100644 index 0000000..be8b432 --- /dev/null +++ b/backend/controllers/SeoCategoryController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all SeoCategory models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SeoCategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single SeoCategory model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new SeoCategory model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new SeoCategory(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->seo_category_id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing SeoCategory 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); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->seo_category_id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing SeoCategory 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 SeoCategory model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return SeoCategory the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = SeoCategory::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/SeoDynamicController.php b/backend/controllers/SeoDynamicController.php new file mode 100644 index 0000000..e6edd30 --- /dev/null +++ b/backend/controllers/SeoDynamicController.php @@ -0,0 +1,130 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all SeoDynamic models. + * @return mixed + */ + public function actionIndex($seo_category_id) + { + $searchModel = new SeoDynamicSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'seo_category_id' => $seo_category_id + ]); + } + + /** + * Displays a single SeoDynamic model. + * @param integer $id + * @return mixed + */ + public function actionView($seo_category_id, $id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + 'seo_category_id' => $seo_category_id + ]); + } + + /** + * Creates a new SeoDynamic model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate($seo_category_id) + { + $model = new SeoDynamic(); + + if ($model->load(Yii::$app->request->post())) { + $model->seo_category_id = $seo_category_id; + $model->save(); + return $this->redirect(['index', 'seo_category_id' => $model->seo_category_id]); + } else { + return $this->render('create', [ + 'model' => $model, + 'seo_category_id' => $seo_category_id + ]); + } + } + + /** + * Updates an existing SeoDynamic model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($seo_category_id,$id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['index', 'seo_category_id' => $model->seo_category_id]); + } else { + return $this->render('update', [ + 'model' => $model, + 'seo_category_id' => $seo_category_id + ]); + } + } + + /** + * Deletes an existing SeoDynamic model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($seo_category_id,$id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index','seo_category_id'=> $seo_category_id]); + } + + /** + * Finds the SeoDynamic model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return SeoDynamic the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = SeoDynamic::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/views/layouts/main-sidebar.php b/backend/views/layouts/main-sidebar.php index bd70450..4534331 100755 --- a/backend/views/layouts/main-sidebar.php +++ b/backend/views/layouts/main-sidebar.php @@ -54,7 +54,14 @@ use yii\widgets\Menu; ['label' => 'Статические страницы', 'url' => ['/page/index']], ['label' => 'Акции', 'url' => ['/event/index']], ['label' => 'Услуги', 'url' => ['/service/index']], - ['label' => 'SEO', 'url' => ['/seo/index']], + [ + 'label' => 'SEO', + 'template'=>' {label}', + 'items' => [ + ['label' => 'URL', 'url' => ['/seo/index']], + ['label' => 'Шаблоны', 'url' => ['/seo-category/index']] + ] + ], // ['label' => 'Rubrication', 'url' => ['/rubrication/tax-group']], // ['label' => 'Relation', 'url' => ['/relation/manage']], ], diff --git a/backend/views/seo-category/_form.php b/backend/views/seo-category/_form.php new file mode 100644 index 0000000..51069d9 --- /dev/null +++ b/backend/views/seo-category/_form.php @@ -0,0 +1,27 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'controller')->textInput(['maxlength' => true]) ?> + + field($model, 'status')->textInput() ?> + +
+ isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/seo-category/_search.php b/backend/views/seo-category/_search.php new file mode 100644 index 0000000..38ba21f --- /dev/null +++ b/backend/views/seo-category/_search.php @@ -0,0 +1,33 @@ + + + diff --git a/backend/views/seo-category/create.php b/backend/views/seo-category/create.php new file mode 100644 index 0000000..6173179 --- /dev/null +++ b/backend/views/seo-category/create.php @@ -0,0 +1,21 @@ +title = Yii::t('app', 'Create Seo Category'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Categories'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/seo-category/index.php b/backend/views/seo-category/index.php new file mode 100644 index 0000000..9f3eee2 --- /dev/null +++ b/backend/views/seo-category/index.php @@ -0,0 +1,72 @@ +title = Yii::t('app', 'Seo Categories'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

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

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

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'seo_category_id', + 'name', + 'controller', + 'status', + + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{update} {image} {delete}', + 'buttons' => [ + 'update' => function ($url, $model) + { + return Html::a ( + '', + Url::toRoute(['seo-category/update', 'id' => $model->seo_category_id]), + [ + 'title' => "Редактировать", + ] + ); + }, + 'image' => function ($url, $model) + { + return Html::a ( + '', + Url::toRoute(['seo-dynamic/index', 'seo_category_id' => $model->seo_category_id]), + [ + 'title' => "слайды", + ] + ); + }, + 'delete' => function ($url, $model) + { + return Html::a ( + '', + Url::toRoute(['seo-category/delete', 'id' => $model->seo_category_id]), + [ + 'title' => "Удалить", + ] + ); + }, + ], + 'contentOptions' => ['style' => 'width: 70px;'], + ], + ], + ]); ?> +
diff --git a/backend/views/seo-category/update.php b/backend/views/seo-category/update.php new file mode 100644 index 0000000..0e7755e --- /dev/null +++ b/backend/views/seo-category/update.php @@ -0,0 +1,23 @@ +title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Seo Category', +]) . $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Categories'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->seo_category_id]]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/seo-category/view.php b/backend/views/seo-category/view.php new file mode 100644 index 0000000..a880663 --- /dev/null +++ b/backend/views/seo-category/view.php @@ -0,0 +1,38 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Categories'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

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

+ + $model, + 'attributes' => [ + 'seo_category_id', + 'name', + 'controller', + 'status', + ], + ]) ?> + +
diff --git a/backend/views/seo-dynamic/_form.php b/backend/views/seo-dynamic/_form.php new file mode 100644 index 0000000..fd26945 --- /dev/null +++ b/backend/views/seo-dynamic/_form.php @@ -0,0 +1,37 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'action')->textInput(['maxlength' => true]) ?> + + field($model, 'fields')->textInput(['maxlength' => true]) ?> + + field($model, 'title')->textInput(['maxlength' => true]) ?> + + field($model, 'h1')->textInput(['maxlength' => true]) ?> + + field($model, 'description')->textInput(['maxlength' => true]) ?> + + field($model, 'seo_text')->textarea(['rows' => 6]) ?> + + field($model, 'status')->textInput() ?> + +
+ isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/seo-dynamic/_search.php b/backend/views/seo-dynamic/_search.php new file mode 100644 index 0000000..820b5bd --- /dev/null +++ b/backend/views/seo-dynamic/_search.php @@ -0,0 +1,45 @@ + + + diff --git a/backend/views/seo-dynamic/create.php b/backend/views/seo-dynamic/create.php new file mode 100644 index 0000000..f3eafd3 --- /dev/null +++ b/backend/views/seo-dynamic/create.php @@ -0,0 +1,22 @@ +title = Yii::t('app', 'Create Seo Dynamic'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Dynamics'), 'url' => Url::toRoute(['index','seo_category_id'=>$seo_category_id])]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/seo-dynamic/index.php b/backend/views/seo-dynamic/index.php new file mode 100644 index 0000000..753878f --- /dev/null +++ b/backend/views/seo-dynamic/index.php @@ -0,0 +1,76 @@ +title = Yii::t('app', 'Seo Dynamics'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

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

+ $seo_category_id]), ['class' => 'btn btn-success']) ?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'seo_dynamic_id', + 'seo_category_id', + 'name', + 'action', + 'fields', + // 'title', + // 'h1', + // 'description', + // 'seo_text:ntext', + // 'status', + + [ + 'class' => 'yii\grid\ActionColumn', + 'buttons' => [ + 'view' => function ($url, $model) + { + return Html::a ( + '', + Url::toRoute(['view','seo_category_id'=> $model->seo_category_id, 'id' => $model->seo_dynamic_id]), + [ + 'title' => "Просмотр", + ] + ); + }, + 'update' => function ($url, $model) + { + return Html::a ( + '', + Url::toRoute(['update','seo_category_id'=> $model->seo_category_id, 'id' => $model->seo_dynamic_id]), + [ + 'title' => "Редактировать", + ] + ); + }, + 'delete' => function ($url, $model) + { + + return Html::a('', Url::toRoute(['delete','seo_category_id'=> $model->seo_category_id, 'id' => $model->seo_dynamic_id]), [ + 'title' => Yii::t('yii', 'Delete'), + 'data-confirm' => Yii::t('yii', 'Are you sure to delete this item?'), + 'data-method' => 'post', + ]); + + }, + ], + ], + ], + ]); ?> +
diff --git a/backend/views/seo-dynamic/update.php b/backend/views/seo-dynamic/update.php new file mode 100644 index 0000000..9c2dd7a --- /dev/null +++ b/backend/views/seo-dynamic/update.php @@ -0,0 +1,24 @@ +title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Seo Dynamic', +]) . $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Dynamics'), 'url' => Url::toRoute(['index','seo_category_id'=>$seo_category_id])]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => Url::toRoute(['view', 'seo_category_id'=>$seo_category_id, 'id' => $model->seo_dynamic_id])]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/seo-dynamic/view.php b/backend/views/seo-dynamic/view.php new file mode 100644 index 0000000..78611a9 --- /dev/null +++ b/backend/views/seo-dynamic/view.php @@ -0,0 +1,44 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Dynamics'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

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

+ + $model, + 'attributes' => [ + 'seo_dynamic_id', + 'seo_category_id', + 'name', + 'action', + 'fields', + 'title', + 'h1', + 'description', + 'seo_text:ntext', + 'status', + ], + ]) ?> + +
diff --git a/backend/views/seo/_form.php b/backend/views/seo/_form.php new file mode 100644 index 0000000..4a3ee6a --- /dev/null +++ b/backend/views/seo/_form.php @@ -0,0 +1,31 @@ + + +
+ + + + field($model, 'url')->textInput(['maxlength' => true]) ?> + + field($model, 'title')->textInput(['maxlength' => true]) ?> + + field($model, 'description')->textInput(['maxlength' => true]) ?> + + field($model, 'h1')->textInput(['maxlength' => true]) ?> + + field($model, 'seo_text')->textarea(['rows' => 6]) ?> + +
+ isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/seo/_search.php b/backend/views/seo/_search.php new file mode 100644 index 0000000..f2a4536 --- /dev/null +++ b/backend/views/seo/_search.php @@ -0,0 +1,37 @@ + + + diff --git a/backend/views/seo/create.php b/backend/views/seo/create.php new file mode 100644 index 0000000..9c2dd28 --- /dev/null +++ b/backend/views/seo/create.php @@ -0,0 +1,21 @@ +title = Yii::t('app', 'Create Seo'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seos'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

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

title) ?>

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

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

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'seo_id', + 'url:url', + 'title', + 'description', + 'h1', + // 'seo_text:ntext', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/views/seo/update.php b/backend/views/seo/update.php new file mode 100644 index 0000000..8dda2ef --- /dev/null +++ b/backend/views/seo/update.php @@ -0,0 +1,23 @@ +title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Seo', +]) . $model->title; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seos'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->seo_id]]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); +?> +
+ +

title) ?>

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

title) ?>

+ +

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

+ + $model, + 'attributes' => [ + 'seo_id', + 'url:url', + 'title', + 'description', + 'h1', + 'seo_text:ntext', + ], + ]) ?> + +
diff --git a/common/models/SeoCategory.php b/common/models/SeoCategory.php new file mode 100644 index 0000000..74757d9 --- /dev/null +++ b/common/models/SeoCategory.php @@ -0,0 +1,59 @@ + 255], + [['controller'], 'string', 'max' => 100], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_category_id' => Yii::t('app', 'Seo Category ID'), + 'name' => Yii::t('app', 'Name'), + 'controller' => Yii::t('app', 'Controller'), + 'status' => Yii::t('app', 'Status'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeoDynamics() + { + return $this->hasMany(SeoDynamic::className(), ['seo_category_id' => 'seo_category_id']); + } +} diff --git a/common/models/SeoCategorySearch.php b/common/models/SeoCategorySearch.php new file mode 100644 index 0000000..ca39122 --- /dev/null +++ b/common/models/SeoCategorySearch.php @@ -0,0 +1,71 @@ + $query, + ]); + + $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'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'seo_category_id' => $this->seo_category_id, + 'status' => $this->status, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'controller', $this->controller]); + + return $dataProvider; + } +} diff --git a/common/models/SeoDynamic.php b/common/models/SeoDynamic.php new file mode 100644 index 0000000..167fb5a --- /dev/null +++ b/common/models/SeoDynamic.php @@ -0,0 +1,73 @@ + 200], + [['fields', 'title', 'h1', 'description'], 'string', 'max' => 255], + [['seo_category_id'], 'exist', 'skipOnError' => true, 'targetClass' => SeoCategory::className(), 'targetAttribute' => ['seo_category_id' => 'seo_category_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_dynamic_id' => Yii::t('app', 'Seo Dynamic ID'), + 'seo_category_id' => Yii::t('app', 'Seo Category ID'), + 'name' => Yii::t('app', 'Name'), + 'action' => Yii::t('app', 'Action'), + 'fields' => Yii::t('app', 'Fields'), + 'title' => Yii::t('app', 'Title'), + 'h1' => Yii::t('app', 'H1'), + 'description' => Yii::t('app', 'Description'), + 'seo_text' => Yii::t('app', 'Seo Text'), + 'status' => Yii::t('app', 'Status'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeoCategory() + { + return $this->hasOne(SeoCategory::className(), ['seo_category_id' => 'seo_category_id']); + } +} diff --git a/common/models/SeoDynamicSearch.php b/common/models/SeoDynamicSearch.php new file mode 100644 index 0000000..4d9ade6 --- /dev/null +++ b/common/models/SeoDynamicSearch.php @@ -0,0 +1,77 @@ + $query, + ]); + + $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'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'seo_dynamic_id' => $this->seo_dynamic_id, + 'seo_category_id' => $this->seo_category_id, + 'status' => $this->status, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'action', $this->action]) + ->andFilterWhere(['like', 'fields', $this->fields]) + ->andFilterWhere(['like', 'title', $this->title]) + ->andFilterWhere(['like', 'h1', $this->h1]) + ->andFilterWhere(['like', 'description', $this->description]) + ->andFilterWhere(['like', 'seo_text', $this->seo_text]); + + return $dataProvider; + } +} diff --git a/console/migrations/m160412_133944_create_seo_category.php b/console/migrations/m160412_133944_create_seo_category.php new file mode 100644 index 0000000..2ee5c4c --- /dev/null +++ b/console/migrations/m160412_133944_create_seo_category.php @@ -0,0 +1,30 @@ +createTable('seo_category', [ + 'seo_category_id' => $this->primaryKey(), + 'name' => $this->string(), + 'controller' => $this->string(100), + 'status' => $this->smallInteger(1), + ]); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('seo_category'); + } +} diff --git a/console/migrations/m160413_112158_create_seo_dynamic.php b/console/migrations/m160413_112158_create_seo_dynamic.php new file mode 100644 index 0000000..82ae679 --- /dev/null +++ b/console/migrations/m160413_112158_create_seo_dynamic.php @@ -0,0 +1,39 @@ +createTable('seo_dynamic', [ + 'seo_dynamic_id' => $this->primaryKey(), + 'seo_category_id' => $this->integer(), + 'name' => $this->string(200), + 'action' => $this->string(200), + 'fields' => $this->string(), + 'title' => $this->string(), + 'h1' => $this->string(), + 'description' => $this->string(), + 'seo_text' => $this->text(), + 'status' => $this->smallInteger() + ]); + + $this->addForeignKey('seo_category_seo_dynamic_fk', 'seo_dynamic', 'seo_category_id', 'seo_category', 'seo_category_id', 'CASCADE', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropForeignKey('seo_category_seo_dynamic_fk', '{{%seo_dynamic}}'); + $this->dropTable('seo_dynamic'); + } +} diff --git a/frontend/views/event/index.php b/frontend/views/event/index.php index c91f03a..6de6eeb 100644 --- a/frontend/views/event/index.php +++ b/frontend/views/event/index.php @@ -1,7 +1,9 @@ params['breadcrumbs'][] = ['label' => 'Акции', 'url' => ['index']]; ?> + $dataProvider, @@ -11,3 +13,6 @@ $this->params['breadcrumbs'][] = ['label' => 'Акции', 'url' => ['index']];
{pager}
" ] ); ?> +
+ 'seo_text'])?> +
diff --git a/frontend/views/event/view.php b/frontend/views/event/view.php index 37e0207..f3ab564 100644 --- a/frontend/views/event/view.php +++ b/frontend/views/event/view.php @@ -2,14 +2,14 @@ use yii\helpers\Html; use yii\widgets\DetailView; - +use frontend\widgets\Seo; /* @var $this yii\web\View */ /* @var $model common\models\Stone */ $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => 'Акции', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; - +$this->params['name'] = $this->title; ?>

name?>

@@ -21,3 +21,6 @@ $this->params['breadcrumbs'][] = $this->title; body?>
+
+ 'seo_text'])?> +
diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index e4cd596..7c9f033 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -7,6 +7,7 @@ use common\widgets\BasketHead; use common\widgets\BasketModal; use frontend\assets\AppAsset; +use frontend\widgets\Seo; use yii\helpers\Html; use yii\helpers\Url; @@ -18,8 +19,26 @@ AppAsset::register($this); - <?= Html::encode($this->title)?> + <?= Seo::widget([ + 'row'=>'title', + 'own_attr'=>$this->title, + 'fields' =>[ + 'name' => isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '' + ] + ])?> + + registerMetaTag([ + 'name' => 'description', + 'content' => Seo::widget([ + 'row'=>'description', + 'own_attr'=>isset($this->params[ 'description' ]) ? $this->params[ 'description' ] : '', + 'fields' =>[ + 'name' => isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '' + ] + ]) + ]); ?> head() ?> + diff --git a/frontend/widgets/Seo.php b/frontend/widgets/Seo.php index 36852fb..16931e8 100644 --- a/frontend/widgets/Seo.php +++ b/frontend/widgets/Seo.php @@ -1,12 +1,16 @@ url = $_SERVER['REQUEST_URI']; @@ -17,17 +21,49 @@ class Seo extends Widget public function run() { - $widgetData = $this->findModel(); + $row = ''; + + + $widgetData = $this->findSeoByUrl(); + if($widgetData instanceof \common\models\Seo){ + + $row = $widgetData->{$this->row}; + } else{ + + $widgetData = $this->findSeoByDynamic(); + if($widgetData instanceof SeoDynamic){ + $row = $widgetData->{$this->row}; + } + } + if(!empty($this->own_attr) && empty($row)) { + + $row = $this->own_attr; + } + + + return $this->replaceData($row); + - return $widgetData->{$this->row}; } - protected function findModel() + protected function replaceData($str) { - if (($model = \common\models\Seo::findOne(['url'=>$this->url])) !== null) { - return $model; - } else { - return new SeoSearch(); + + if(!empty($this->fields)){ + foreach($this->fields as $field_name => $field_value){ + $str = str_replace('{'.$field_name.'}', $field_value, $str); + } } + return Html::encode($str); + } + + protected function findSeoByUrl() + { + return \common\models\Seo::findOne(['url'=>$this->url]); + } + + protected function findSeoByDynamic() + { + return SeoDynamic::find()->joinWith('seoCategory')->where(['controller'=> \Yii::$app->controller->id, 'action'=>\Yii::$app->controller->action->id])->one(); } } \ No newline at end of file -- libgit2 0.21.4