From f202ab2b57b31def6c257f2dc3060aada96bef8b Mon Sep 17 00:00:00 2001 From: yarik Date: Mon, 24 Oct 2016 00:27:53 +0300 Subject: [PATCH] Article table refactor. --- backend/assets/AdminLteAsset.php | 2 -- backend/controllers/ArticleController.php | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/controllers/ArticlesController.php | 165 --------------------------------------------------------------------------------------------------------------------------------------------------------------------- backend/views/article/_form.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/article/_form_language.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/article/_search.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ backend/views/article/create.php | 28 ++++++++++++++++++++++++++++ backend/views/article/index.php | 34 ++++++++++++++++++++++++++++++++++ backend/views/article/update.php | 35 +++++++++++++++++++++++++++++++++++ backend/views/article/view.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ backend/views/articles/_form.php | 68 -------------------------------------------------------------------- backend/views/articles/_form_language.php | 53 ----------------------------------------------------- backend/views/articles/_search.php | 47 ----------------------------------------------- backend/views/articles/create.php | 28 ---------------------------- backend/views/articles/index.php | 34 ---------------------------------- backend/views/articles/update.php | 35 ----------------------------------- backend/views/articles/view.php | 46 ---------------------------------------------- backend/views/layouts/main-sidebar.php | 4 ++-- common/behaviors/NotifyBehavior.php | 12 ++++++------ common/behaviors/RatingBehavior.php | 4 ++-- common/models/Article.php | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/ArticleLang.php | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/ArticleSearch.php | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/ArticleToRating.php | 72 ------------------------------------------------------------------------ common/models/Articles.php | 160 ---------------------------------------------------------------------------------------------------------------------------------------------------------------- common/models/ArticlesLang.php | 153 --------------------------------------------------------------------------------------------------------------------------------------------------------- common/models/ArticlesSearch.php | 95 ----------------------------------------------------------------------------------------------- console/controllers/SiteMapController.php | 10 ++-------- console/migrations/m160926_122456_create_articles_lang_table.php | 16 ++++++++-------- todo | 8 +++++++- 30 files changed, 862 insertions(+), 985 deletions(-) create mode 100755 backend/controllers/ArticleController.php delete mode 100755 backend/controllers/ArticlesController.php create mode 100755 backend/views/article/_form.php create mode 100755 backend/views/article/_form_language.php create mode 100755 backend/views/article/_search.php create mode 100755 backend/views/article/create.php create mode 100755 backend/views/article/index.php create mode 100755 backend/views/article/update.php create mode 100755 backend/views/article/view.php delete mode 100755 backend/views/articles/_form.php delete mode 100755 backend/views/articles/_form_language.php delete mode 100755 backend/views/articles/_search.php delete mode 100755 backend/views/articles/create.php delete mode 100755 backend/views/articles/index.php delete mode 100755 backend/views/articles/update.php delete mode 100755 backend/views/articles/view.php create mode 100755 common/models/Article.php create mode 100755 common/models/ArticleLang.php create mode 100755 common/models/ArticleSearch.php delete mode 100755 common/models/ArticleToRating.php delete mode 100755 common/models/Articles.php delete mode 100755 common/models/ArticlesLang.php delete mode 100755 common/models/ArticlesSearch.php diff --git a/backend/assets/AdminLteAsset.php b/backend/assets/AdminLteAsset.php index c4a7c67..8c46511 100755 --- a/backend/assets/AdminLteAsset.php +++ b/backend/assets/AdminLteAsset.php @@ -27,9 +27,7 @@ class AdminLteAsset extends AssetBundle ]; public $depends = [ 'yii\web\YiiAsset', - 'common\modules\file\FileUploadAsset', 'yii\bootstrap\BootstrapPluginAsset', 'backend\assets\FontAwesomeAsset', - ]; } \ No newline at end of file diff --git a/backend/controllers/ArticleController.php b/backend/controllers/ArticleController.php new file mode 100755 index 0000000..7a837e0 --- /dev/null +++ b/backend/controllers/ArticleController.php @@ -0,0 +1,165 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Article models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ArticleSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Article model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Article model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Article(); + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } + } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); + } + + /** + * 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) + { + $model = $this->findModel($id); + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } + } + return $this->render('update', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); + } + + /** + * Deletes an existing Article 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 Article model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Article the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Article::find() + ->where([ 'id' => $id ]) + ->with('lang') + ->one() ) !== NULL + ) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/backend/controllers/ArticlesController.php b/backend/controllers/ArticlesController.php deleted file mode 100755 index 34d4258..0000000 --- a/backend/controllers/ArticlesController.php +++ /dev/null @@ -1,165 +0,0 @@ - [ - 'class' => AccessBehavior::className(), - 'rules' => [ - 'site' => [ - [ - 'actions' => [ - 'login', - 'error', - ], - 'allow' => true, - ], - ], - ], - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => [ 'POST' ], - ], - ], - ]; - } - - /** - * Lists all Articles models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new ArticlesSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Articles model. - * - * @param integer $id - * - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Articles model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Articles(); - $model->generateLangs(); - if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request); - if($model->save() && $model->transactionStatus) { - return $this->redirect([ - 'view', - 'id' => $model->id, - ]); - } - } - return $this->render('create', [ - 'model' => $model, - 'model_langs' => $model->model_langs, - ]); - } - - /** - * Updates an existing Articles 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->generateLangs(); - if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request); - if($model->save() && $model->transactionStatus) { - return $this->redirect([ - 'view', - 'id' => $model->id, - ]); - } - } - return $this->render('update', [ - 'model' => $model, - 'model_langs' => $model->model_langs, - ]); - } - - /** - * Deletes an existing Articles 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 Articles model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * - * @param integer $id - * - * @return Articles the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if(( $model = Articles::find() - ->where([ 'id' => $id ]) - ->with('lang') - ->one() ) !== NULL - ) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); - } - } - } diff --git a/backend/views/article/_form.php b/backend/views/article/_form.php new file mode 100755 index 0000000..83551bf --- /dev/null +++ b/backend/views/article/_form.php @@ -0,0 +1,66 @@ + + +
+ + false, + 'options' => [ 'enctype' => 'multipart/form-data' ], + ]); ?> + + + field($model, 'created_at') + ->widget(DatePicker::className(), [ + 'dateFormat' => 'dd-MM-yyyy', + ]) ?> + + field($model, 'image') + ->widget(\kartik\file\FileInput::className(), [ + 'language' => 'ru', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'jpg', + 'gif', + 'png', + ], + 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', + 'overwriteInitial' => true, + 'showRemove' => false, + 'showUpload' => false, + 'previewFileType' => 'image', + ], + ]); ?> + + $model_langs, + 'formView' => '@backend/views/article/_form_language', + 'form' => $form, + ]); + ?> + +
+ isNewRecord ? \Yii::t('app', 'Create') : \Yii::t('app', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> +
+ + + +
diff --git a/backend/views/article/_form_language.php b/backend/views/article/_form_language.php new file mode 100755 index 0000000..a5592a2 --- /dev/null +++ b/backend/views/article/_form_language.php @@ -0,0 +1,53 @@ + +field($model_lang, '[' . $language->language_id . ']title') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']alias') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']body') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']body_preview') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_title') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_keywords') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_description') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']seo_text') + ->textarea([ 'rows' => 6 ]) ?> + +field($model_lang, '[' . $language->language_id . ']h1') + ->textInput([ 'maxlength' => true ]) ?> diff --git a/backend/views/article/_search.php b/backend/views/article/_search.php new file mode 100755 index 0000000..afb9cfc --- /dev/null +++ b/backend/views/article/_search.php @@ -0,0 +1,47 @@ + + + diff --git a/backend/views/article/create.php b/backend/views/article/create.php new file mode 100755 index 0000000..4b777fb --- /dev/null +++ b/backend/views/article/create.php @@ -0,0 +1,28 @@ +title = \Yii::t('app', 'Create Article'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => \Yii::t('app', 'Article'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]) ?> + +
diff --git a/backend/views/article/index.php b/backend/views/article/index.php new file mode 100755 index 0000000..57926bd --- /dev/null +++ b/backend/views/article/index.php @@ -0,0 +1,34 @@ +title = \Yii::t('app', 'Articles'); + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+

title) ?>

+

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

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + 'id', + [ + 'attribute' => 'title', + 'value' => 'lang.title', + ], + 'created_at:date', + 'imageUrl:image', + [ 'class' => 'yii\grid\ActionColumn' ], + ], + ]); ?> +
diff --git a/backend/views/article/update.php b/backend/views/article/update.php new file mode 100755 index 0000000..9ac32d8 --- /dev/null +++ b/backend/views/article/update.php @@ -0,0 +1,35 @@ +title = \Yii::t('app', 'Update Article') . ': ' . $model->lang->title; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => \Yii::t('app', 'Article'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->lang->title, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]) ?> + +
diff --git a/backend/views/article/view.php b/backend/views/article/view.php new file mode 100755 index 0000000..7055d3a --- /dev/null +++ b/backend/views/article/view.php @@ -0,0 +1,46 @@ +title = $model->lang->title; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => \Yii::t('app', 'Article'), + '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', + 'created_at:date', + 'lang.title', + 'lang.body:html', + 'imageUrl:image', + ], + ]) ?> +
diff --git a/backend/views/articles/_form.php b/backend/views/articles/_form.php deleted file mode 100755 index 07698f5..0000000 --- a/backend/views/articles/_form.php +++ /dev/null @@ -1,68 +0,0 @@ - - -
- - false, - 'options' => [ 'enctype' => 'multipart/form-data' ], - ]); ?> - - - field($model, 'date') - ->widget(DatePicker::className(), [ - 'dateFormat' => 'dd-MM-yyyy', - ]) ?> - - field($model, 'image') - ->widget(\kartik\file\FileInput::className(), [ - 'language' => 'ru', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => false, - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => [ - 'jpg', - 'gif', - 'png', - ], - 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', - 'overwriteInitial' => true, - 'showRemove' => false, - 'showUpload' => false, - 'previewFileType' => 'image', - ], - ]); ?> - - $model_langs, - 'formView' => '@backend/views/articles/_form_language', - 'form' => $form, - ]); - ?> - -
- isNewRecord ? 'Create' : 'Update', [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> -
- - - -
diff --git a/backend/views/articles/_form_language.php b/backend/views/articles/_form_language.php deleted file mode 100755 index 8ad752c..0000000 --- a/backend/views/articles/_form_language.php +++ /dev/null @@ -1,53 +0,0 @@ - -field($model_lang, '[' . $language->language_id . ']title') - ->textInput([ 'maxlength' => true ]); ?> -field($model_lang, '[' . $language->language_id . ']alias') - ->textInput([ 'maxlength' => true ]); ?> -field($model_lang, '[' . $language->language_id . ']body') - ->widget(CKEditor::className(), [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ - 'preset' => 'full', - 'inline' => false, - 'filebrowserUploadUrl' => Yii::$app->getUrlManager() - ->createUrl('file/uploader/images-upload'), - ]), - ]) ?> - -field($model_lang, '[' . $language->language_id . ']body_preview') - ->widget(CKEditor::className(), [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ - 'preset' => 'full', - 'inline' => false, - 'filebrowserUploadUrl' => Yii::$app->getUrlManager() - ->createUrl('file/uploader/images-upload'), - ]), - ]) ?> - -field($model_lang, '[' . $language->language_id . ']meta_title') - ->textInput([ 'maxlength' => true ]) ?> - -field($model_lang, '[' . $language->language_id . ']meta_keywords') - ->textInput([ 'maxlength' => true ]) ?> - -field($model_lang, '[' . $language->language_id . ']meta_description') - ->textInput([ 'maxlength' => true ]) ?> - -field($model_lang, '[' . $language->language_id . ']seo_text') - ->textarea([ 'rows' => 6 ]) ?> - -field($model_lang, '[' . $language->language_id . ']h1') - ->textInput([ 'maxlength' => true ]) ?> diff --git a/backend/views/articles/_search.php b/backend/views/articles/_search.php deleted file mode 100755 index afb9cfc..0000000 --- a/backend/views/articles/_search.php +++ /dev/null @@ -1,47 +0,0 @@ - - - diff --git a/backend/views/articles/create.php b/backend/views/articles/create.php deleted file mode 100755 index 2e4d10e..0000000 --- a/backend/views/articles/create.php +++ /dev/null @@ -1,28 +0,0 @@ -title = \Yii::t('app', 'Create Articles'); - $this->params[ 'breadcrumbs' ][] = [ - 'label' => \Yii::t('app', 'Articles'), - 'url' => [ 'index' ], - ]; - $this->params[ 'breadcrumbs' ][] = $this->title; -?> -
- -

title) ?>

- - render('_form', [ - 'model' => $model, - 'model_langs' => $model_langs, - ]) ?> - -
diff --git a/backend/views/articles/index.php b/backend/views/articles/index.php deleted file mode 100755 index c0655da..0000000 --- a/backend/views/articles/index.php +++ /dev/null @@ -1,34 +0,0 @@ -title = \Yii::t('app', 'Articles'); - $this->params[ 'breadcrumbs' ][] = $this->title; -?> -
-

title) ?>

-

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

- $dataProvider, - 'filterModel' => $searchModel, - 'columns' => [ - 'id', - [ - 'attribute' => 'title', - 'value' => 'lang.title', - ], - 'date:date', - 'imageUrl:image', - [ 'class' => 'yii\grid\ActionColumn' ], - ], - ]); ?> -
diff --git a/backend/views/articles/update.php b/backend/views/articles/update.php deleted file mode 100755 index 20b26de..0000000 --- a/backend/views/articles/update.php +++ /dev/null @@ -1,35 +0,0 @@ -title = \Yii::t('app', 'Update Articles').': ' . $model->id; - $this->params[ 'breadcrumbs' ][] = [ - 'label' => \Yii::t('app', 'Articles'), - '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, - 'model_langs' => $model_langs, - ]) ?> - -
diff --git a/backend/views/articles/view.php b/backend/views/articles/view.php deleted file mode 100755 index 462345e..0000000 --- a/backend/views/articles/view.php +++ /dev/null @@ -1,46 +0,0 @@ -title = $model->lang->title; - $this->params[ 'breadcrumbs' ][] = [ - 'label' => \Yii::t('app', 'Articles'), - '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', - 'date:date', - 'lang.title', - 'lang.body:html', - 'imageUrl:image', - ], - ]) ?> -
diff --git a/backend/views/layouts/main-sidebar.php b/backend/views/layouts/main-sidebar.php index 679f775..3bbe6f9 100755 --- a/backend/views/layouts/main-sidebar.php +++ b/backend/views/layouts/main-sidebar.php @@ -117,8 +117,8 @@ use yii\widgets\Menu; [ 'label' => 'Статьи', 'template'=>' {label}', - 'url' => ['/articles/index'], - 'options' => ['class'=>\Yii::$app->user->can('articles') ? '' :'hide'], + 'url' => ['/article/index'], + 'options' => ['class'=>\Yii::$app->user->can('article') ? '' :'hide'], ], [ 'label' => 'Акции', diff --git a/common/behaviors/NotifyBehavior.php b/common/behaviors/NotifyBehavior.php index d1767ea..12f1c57 100755 --- a/common/behaviors/NotifyBehavior.php +++ b/common/behaviors/NotifyBehavior.php @@ -2,7 +2,7 @@ namespace common\behaviors; - use common\models\Articles; + use common\models\Article; use common\modules\comment\models\CommentModel; use common\modules\product\models\Product; use common\widgets\Mailer; @@ -53,15 +53,15 @@ * @todo Change that statements */ if($model::className() == Product::className()) { - $url .= '/product/'.$model->alias.'#artbox-comment'; - } elseif($model::className() == Articles::className()) { - $url .= '/blog/'.$model->translit.'#artbox-comment'; + $url .= '/product/' . $model->alias . '#artbox-comment'; + } elseif($model::className() == Article::className()) { + $url .= '/blog/' . $model->translit . '#artbox-comment'; } $mailer = Mailer::widget([ 'type' => 'comment_notify', 'params' => [ - 'model' => $model, - 'url' => $url, + 'model' => $model, + 'url' => $url, 'comment' => $owner, ], 'subject' => 'Ваш комментарий опубликован', diff --git a/common/behaviors/RatingBehavior.php b/common/behaviors/RatingBehavior.php index 0d999ca..7ea03e3 100755 --- a/common/behaviors/RatingBehavior.php +++ b/common/behaviors/RatingBehavior.php @@ -2,7 +2,7 @@ namespace common\behaviors; - use common\models\Articles; + use common\models\Article; use common\modules\comment\models\CommentModel; use common\modules\product\models\Product; use yii\base\Behavior; @@ -31,7 +31,7 @@ * @var CommentModel $owner */ $owner = $this->owner; - if($owner->entity == Product::className() || $owner->entity == Articles::className()) { + if($owner->entity == Product::className() || $owner->entity == Article::className()) { $entity = $owner->entity; $model = $entity::findOne($owner->entity_id); if($model != NULL) { diff --git a/common/models/Article.php b/common/models/Article.php new file mode 100755 index 0000000..13bd646 --- /dev/null +++ b/common/models/Article.php @@ -0,0 +1,113 @@ + SaveImgBehavior::className(), + 'fields' => [ + [ + 'name' => 'image', + 'directory' => 'article', + ], + ], + ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + [ + 'class' => TimestampBehavior::className(), + 'updatedAtAttribute' => false, + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'created_at' ], + 'safe', + ], + [ + [ 'created_at' ], + 'filter', + 'filter' => function($value) { + return strtotime($value) ? : time(); + }, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'created_at' => Yii::t('app', 'Date'), + 'image' => Yii::t('app', 'Image'), + 'imageUrl' => Yii::t('app', 'Image'), + ]; + } + } diff --git a/common/models/ArticleLang.php b/common/models/ArticleLang.php new file mode 100755 index 0000000..e571694 --- /dev/null +++ b/common/models/ArticleLang.php @@ -0,0 +1,153 @@ + [ + 'class' => 'common\behaviors\Slug', + 'in_attribute' => 'title', + 'out_attribute' => 'alias', + 'translit' => true, + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'title', + 'body', + ], + 'required', + ], + [ + [ + 'body', + 'seo_text', + 'body_preview', + 'alias', + ], + 'string', + ], + [ + [ + 'title', + 'meta_title', + 'meta_keywords', + 'meta_description', + 'h1', + ], + 'string', + 'max' => 255, + ], + [ + [ + 'article_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'article_id', + 'language_id', + ], + 'message' => 'The combination of Article ID and Language ID has already been taken.', + ], + [ + [ 'article_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Article::className(), + 'targetAttribute' => [ 'article_id' => 'id' ], + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'language_id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'article_id' => Yii::t('app', 'lang-Article ID'), + 'language_id' => Yii::t('app', 'lang-Language ID'), + 'title' => Yii::t('app', 'lang-Title'), + 'body' => Yii::t('app', 'lang-Body'), + 'meta_title' => Yii::t('app', 'lang-Meta Title'), + 'meta_keywords' => Yii::t('app', 'lang-Meta Keywords'), + 'meta_description' => Yii::t('app', 'lang-Meta Description'), + 'seo_text' => Yii::t('app', 'lang-Seo Text'), + 'h1' => Yii::t('app', 'lang-H1'), + 'body_preview' => Yii::t('app', 'lang-Body Preview'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getArticle() + { + return $this->hasOne(Article::className(), [ 'id' => 'article_id' ]) + ->inverseOf('langs'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'language_id' => 'language_id' ]); + } + } diff --git a/common/models/ArticleSearch.php b/common/models/ArticleSearch.php new file mode 100755 index 0000000..0a9c57e --- /dev/null +++ b/common/models/ArticleSearch.php @@ -0,0 +1,95 @@ +joinWith('lang'); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'sort' => [ + 'attributes' => [ + 'id', + 'title' => [ + 'asc' => [ 'article_lang.title' => SORT_ASC ], + 'desc' => [ 'article_lang.title' => SORT_DESC ], + ], + ], + ], + ]); + + $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([ + 'id' => $this->id, + ]); + + $query->andFilterWhere([ + 'like', + 'article_lang.title', + $this->title, + ]); + + return $dataProvider; + } + } diff --git a/common/models/ArticleToRating.php b/common/models/ArticleToRating.php deleted file mode 100755 index 5ee365a..0000000 --- a/common/models/ArticleToRating.php +++ /dev/null @@ -1,72 +0,0 @@ - true, - 'targetClass' => Articles::className(), - 'targetAttribute' => [ 'articles_id' => 'id' ], - ], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'article_to_rating_id' => 'Article To Rating ID', - 'articles_id' => 'Articles ID', - 'value' => 'Value', - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getArticles() - { - return $this->hasOne(Articles::className(), [ 'id' => 'articles_id' ]); - } - } diff --git a/common/models/Articles.php b/common/models/Articles.php deleted file mode 100755 index 30882e8..0000000 --- a/common/models/Articles.php +++ /dev/null @@ -1,160 +0,0 @@ - SaveImgBehavior::className(), - 'fields' => [ - [ - 'name' => 'image', - 'directory' => 'articles', - ], - ], - ], - 'language' => [ - 'class' => LanguageBehavior::className(), - ], - ]; - } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [ - [ 'date' ], - 'default', - 'value' => function() { - return time(); - }, - ], - [ - [ 'date' ], - 'safe', - ], - [ - [ 'date' ], - 'filter', - 'filter' => function($value) { - return strtotime($value) ? : time(); - }, - ], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'id' => Yii::t('app', 'ID'), - 'date' => Yii::t('app', 'Date'), - 'image' => Yii::t('app', 'Image'), - 'imageUrl' => Yii::t('app', 'Image'), - ]; - } - - public function recalculateRating() - { - /** - * @var ArticleToRating $averageRating - */ - $average = $this->getComments() - ->joinWith('rating') - ->select([ 'average' => 'avg(artbox_comment_rating.value)::float' ]) - ->scalar(); - if(!$average) { - $average = 0; - } - $averageRating = $this->averageRating; - if(!empty( $averageRating )) { - $averageRating->value = $average; - } else { - $averageRating = new ArticleToRating([ - 'articles_id' => $this->id, - 'value' => $average, - ]); - } - if($averageRating->save()) { - return true; - } else { - return false; - } - } - - public function getComments() - { - return $this->hasMany(CommentModel::className(), [ 'entity_id' => 'id' ]) - ->where([ - 'artbox_comment.entity' => self::className(), - 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, - 'artbox_comment.artbox_comment_pid' => NULL, - ]); - } - - public function getAverageRating() - { - return $this->hasOne(ArticleToRating::className(), [ 'articles_id' => 'id' ]); - } - } diff --git a/common/models/ArticlesLang.php b/common/models/ArticlesLang.php deleted file mode 100755 index 997c88e..0000000 --- a/common/models/ArticlesLang.php +++ /dev/null @@ -1,153 +0,0 @@ - [ - 'class' => 'common\behaviors\Slug', - 'in_attribute' => 'title', - 'out_attribute' => 'alias', - 'translit' => true, - ], - ]; - } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [ - [ - 'title', - 'body', - ], - 'required', - ], - [ - [ - 'body', - 'seo_text', - 'body_preview', - 'alias', - ], - 'string', - ], - [ - [ - 'title', - 'meta_title', - 'meta_keywords', - 'meta_description', - 'h1', - ], - 'string', - 'max' => 255, - ], - [ - [ - 'articles_id', - 'language_id', - ], - 'unique', - 'targetAttribute' => [ - 'articles_id', - 'language_id', - ], - 'message' => 'The combination of Articles ID and Language ID has already been taken.', - ], - [ - [ 'articles_id' ], - 'exist', - 'skipOnError' => true, - 'targetClass' => Articles::className(), - 'targetAttribute' => [ 'articles_id' => 'id' ], - ], - [ - [ 'language_id' ], - 'exist', - 'skipOnError' => true, - 'targetClass' => Language::className(), - 'targetAttribute' => [ 'language_id' => 'language_id' ], - ], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'articles_id' => Yii::t('app', 'lang-Articles ID'), - 'language_id' => Yii::t('app', 'lang-Language ID'), - 'title' => Yii::t('app', 'lang-Title'), - 'body' => Yii::t('app', 'lang-Body'), - 'meta_title' => Yii::t('app', 'lang-Meta Title'), - 'meta_keywords' => Yii::t('app', 'lang-Meta Keywords'), - 'meta_description' => Yii::t('app', 'lang-Meta Description'), - 'seo_text' => Yii::t('app', 'lang-Seo Text'), - 'h1' => Yii::t('app', 'lang-H1'), - 'body_preview' => Yii::t('app', 'lang-Body Preview'), - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getArticles() - { - return $this->hasOne(Articles::className(), [ 'id' => 'articles_id' ]) - ->inverseOf('langs'); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getLanguage() - { - return $this->hasOne(Language::className(), [ 'language_id' => 'language_id' ]); - } - } diff --git a/common/models/ArticlesSearch.php b/common/models/ArticlesSearch.php deleted file mode 100755 index 2c13445..0000000 --- a/common/models/ArticlesSearch.php +++ /dev/null @@ -1,95 +0,0 @@ -joinWith('lang', true, 'INNER JOIN'); - - // add conditions that should always apply here - - $dataProvider = new ActiveDataProvider([ - 'query' => $query, - 'sort' => [ - 'attributes' => [ - 'id', - 'title' => [ - 'asc' => [ 'articles_lang.title' => SORT_ASC ], - 'desc' => [ 'articles_lang.title' => SORT_DESC ], - ], - ], - ], - ]); - - $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([ - 'id' => $this->id, - ]); - - $query->andFilterWhere([ - 'like', - 'articles_lang.title', - $this->title, - ]); - - return $dataProvider; - } - } diff --git a/console/controllers/SiteMapController.php b/console/controllers/SiteMapController.php index 9b72340..6552ae3 100755 --- a/console/controllers/SiteMapController.php +++ b/console/controllers/SiteMapController.php @@ -2,22 +2,16 @@ namespace console\controllers; -use common\models\Articles; +use common\models\Article; use common\models\Seo; -use common\modules\product\helpers\FilterHelper; -use common\modules\product\models\Brand; use common\modules\product\models\Category; use common\modules\product\models\Product; use frontend\models\ProductFrontendSearch; use Yii; use common\models\Page; -use common\models\PageSearch; use yii\helpers\ArrayHelper; use yii\helpers\Url; use yii\console\Controller; -use yii\web\NotFoundHttpException; -use yii\filters\VerbFilter; -use developeruz\db_rbac\behaviors\AccessBehavior; /** * PageController implements the CRUD actions for Page model. */ @@ -71,7 +65,7 @@ class SiteMapController extends Controller public function getArticles(){ - return Articles::find()->all(); + return Article::find()->all(); } public function getBrands($category){ diff --git a/console/migrations/m160926_122456_create_articles_lang_table.php b/console/migrations/m160926_122456_create_articles_lang_table.php index 7630b40..fc6c538 100755 --- a/console/migrations/m160926_122456_create_articles_lang_table.php +++ b/console/migrations/m160926_122456_create_articles_lang_table.php @@ -3,9 +3,9 @@ use yii\db\Migration; /** - * Handles the creation for table `articles_lang`. + * Handles the creation for table `article_lang`. */ - class m160926_122456_create_articles_lang_table extends Migration + class m160926_122456_create_article_lang_table extends Migration { /** @@ -13,8 +13,8 @@ */ public function up() { - $this->createTable('articles_lang', [ - 'articles_id' => $this->integer() + $this->createTable('article_lang', [ + 'article_id' => $this->integer() ->notNull(), 'language_id' => $this->integer() ->notNull(), @@ -30,12 +30,12 @@ 'body_preview' => $this->text(), ]); - $this->createIndex('articles_lang_article_language_key', 'articles_lang', [ - 'articles_id', + $this->createIndex('article_lang_article_language_key', 'article_lang', [ + 'article_id', 'language_id', ], true); - $this->addForeignKey('articles_fk', 'articles_lang', 'articles_id', 'articles', 'id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('article_fk', 'article_lang', 'article_id', 'article', 'id', 'CASCADE', 'CASCADE'); $this->addForeignKey('language_fk', 'articles_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); } @@ -44,6 +44,6 @@ */ public function down() { - $this->dropTable('articles_lang'); + $this->dropTable('article_lang'); } } diff --git a/todo b/todo index 1fef3ff..bd6a7d9 100755 --- a/todo +++ b/todo @@ -82,4 +82,10 @@ Fix по существующему: 6. backend/config/bootstrap.php 7. Сделать behavior для комментов/рейтинга 8. Category->setTaxGroup() ??? -9. Избавиться от Mailer widget \ No newline at end of file +9. Избавиться от Mailer widget +10. На статьях включить клиентскую валидацию +11. Спросить у Виталика или нужно вернуть модуль file (используется elfinder ?) + + +Комментарии (создать поведение): +1. Добавить к Article с рейтингом \ No newline at end of file -- libgit2 0.21.4