Commit f202ab2b57b31def6c257f2dc3060aada96bef8b

Authored by Yarik
1 parent 5c2eb7c8

Article table refactor.

backend/assets/AdminLteAsset.php
@@ -27,9 +27,7 @@ class AdminLteAsset extends AssetBundle @@ -27,9 +27,7 @@ class AdminLteAsset extends AssetBundle
27 ]; 27 ];
28 public $depends = [ 28 public $depends = [
29 'yii\web\YiiAsset', 29 'yii\web\YiiAsset',
30 - 'common\modules\file\FileUploadAsset',  
31 'yii\bootstrap\BootstrapPluginAsset', 30 'yii\bootstrap\BootstrapPluginAsset',
32 'backend\assets\FontAwesomeAsset', 31 'backend\assets\FontAwesomeAsset',
33 -  
34 ]; 32 ];
35 } 33 }
36 \ No newline at end of file 34 \ No newline at end of file
backend/controllers/ArticlesController.php renamed to backend/controllers/ArticleController.php
@@ -2,18 +2,18 @@ @@ -2,18 +2,18 @@
2 2
3 namespace backend\controllers; 3 namespace backend\controllers;
4 4
  5 + use common\models\Article;
  6 + use common\models\ArticleSearch;
5 use Yii; 7 use Yii;
6 - use common\models\Articles;  
7 - use common\models\ArticlesSearch;  
8 use yii\web\Controller; 8 use yii\web\Controller;
9 use yii\web\NotFoundHttpException; 9 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter; 10 use yii\filters\VerbFilter;
11 use developeruz\db_rbac\behaviors\AccessBehavior; 11 use developeruz\db_rbac\behaviors\AccessBehavior;
12 12
13 /** 13 /**
14 - * ArticlesController implements the CRUD actions for Articles model. 14 + * ArticleController implements the CRUD actions for Article model.
15 */ 15 */
16 - class ArticlesController extends Controller 16 + class ArticleController extends Controller
17 { 17 {
18 18
19 /** 19 /**
@@ -46,12 +46,12 @@ @@ -46,12 +46,12 @@
46 } 46 }
47 47
48 /** 48 /**
49 - * Lists all Articles models. 49 + * Lists all Article models.
50 * @return mixed 50 * @return mixed
51 */ 51 */
52 public function actionIndex() 52 public function actionIndex()
53 { 53 {
54 - $searchModel = new ArticlesSearch(); 54 + $searchModel = new ArticleSearch();
55 $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 55 $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
56 56
57 return $this->render('index', [ 57 return $this->render('index', [
@@ -61,7 +61,7 @@ @@ -61,7 +61,7 @@
61 } 61 }
62 62
63 /** 63 /**
64 - * Displays a single Articles model. 64 + * Displays a single Article model.
65 * 65 *
66 * @param integer $id 66 * @param integer $id
67 * 67 *
@@ -75,13 +75,13 @@ @@ -75,13 +75,13 @@
75 } 75 }
76 76
77 /** 77 /**
78 - * Creates a new Articles model. 78 + * Creates a new Article model.
79 * If creation is successful, the browser will be redirected to the 'view' page. 79 * If creation is successful, the browser will be redirected to the 'view' page.
80 * @return mixed 80 * @return mixed
81 */ 81 */
82 public function actionCreate() 82 public function actionCreate()
83 { 83 {
84 - $model = new Articles(); 84 + $model = new Article();
85 $model->generateLangs(); 85 $model->generateLangs();
86 if($model->load(Yii::$app->request->post())) { 86 if($model->load(Yii::$app->request->post())) {
87 $model->loadLangs(\Yii::$app->request); 87 $model->loadLangs(\Yii::$app->request);
@@ -99,7 +99,7 @@ @@ -99,7 +99,7 @@
99 } 99 }
100 100
101 /** 101 /**
102 - * Updates an existing Articles model. 102 + * Updates an existing Article model.
103 * If update is successful, the browser will be redirected to the 'view' page. 103 * If update is successful, the browser will be redirected to the 'view' page.
104 * 104 *
105 * @param integer $id 105 * @param integer $id
@@ -126,7 +126,7 @@ @@ -126,7 +126,7 @@
126 } 126 }
127 127
128 /** 128 /**
129 - * Deletes an existing Articles model. 129 + * Deletes an existing Article model.
130 * If deletion is successful, the browser will be redirected to the 'index' page. 130 * If deletion is successful, the browser will be redirected to the 'index' page.
131 * 131 *
132 * @param integer $id 132 * @param integer $id
@@ -142,17 +142,17 @@ @@ -142,17 +142,17 @@
142 } 142 }
143 143
144 /** 144 /**
145 - * Finds the Articles model based on its primary key value. 145 + * Finds the Article model based on its primary key value.
146 * If the model is not found, a 404 HTTP exception will be thrown. 146 * If the model is not found, a 404 HTTP exception will be thrown.
147 * 147 *
148 * @param integer $id 148 * @param integer $id
149 * 149 *
150 - * @return Articles the loaded model 150 + * @return Article the loaded model
151 * @throws NotFoundHttpException if the model cannot be found 151 * @throws NotFoundHttpException if the model cannot be found
152 */ 152 */
153 protected function findModel($id) 153 protected function findModel($id)
154 { 154 {
155 - if(( $model = Articles::find() 155 + if(( $model = Article::find()
156 ->where([ 'id' => $id ]) 156 ->where([ 'id' => $id ])
157 ->with('lang') 157 ->with('lang')
158 ->one() ) !== NULL 158 ->one() ) !== NULL
backend/views/articles/_form.php renamed to backend/views/article/_form.php
1 <?php 1 <?php
2 - use common\models\Articles;  
3 - use common\models\ArticlesLang; 2 + use common\models\Article;
  3 + use common\models\ArticleLang;
4 use common\modules\language\widgets\LanguageForm; 4 use common\modules\language\widgets\LanguageForm;
5 use yii\helpers\Html; 5 use yii\helpers\Html;
6 use yii\web\View; 6 use yii\web\View;
7 use yii\widgets\ActiveForm; 7 use yii\widgets\ActiveForm;
8 - use mihaildev\ckeditor\CKEditor;  
9 - use mihaildev\elfinder\ElFinder;  
10 use yii\jui\DatePicker; 8 use yii\jui\DatePicker;
11 9
12 /** 10 /**
13 - * @var View $this  
14 - * @var Articles $model  
15 - * @var ArticlesLang[] $model_langs  
16 - * @var ActiveForm $form 11 + * @var View $this
  12 + * @var Article $model
  13 + * @var ArticleLang[] $model_langs
  14 + * @var ActiveForm $form
17 */ 15 */
18 ?> 16 ?>
19 17
20 -<div class="articles-form"> 18 +<div class="article-form">
21 19
22 <?php $form = ActiveForm::begin([ 20 <?php $form = ActiveForm::begin([
23 'enableClientValidation' => false, 21 'enableClientValidation' => false,
@@ -25,7 +23,7 @@ @@ -25,7 +23,7 @@
25 ]); ?> 23 ]); ?>
26 24
27 25
28 - <?= $form->field($model, 'date') 26 + <?= $form->field($model, 'created_at')
29 ->widget(DatePicker::className(), [ 27 ->widget(DatePicker::className(), [
30 'dateFormat' => 'dd-MM-yyyy', 28 'dateFormat' => 'dd-MM-yyyy',
31 ]) ?> 29 ]) ?>
@@ -54,13 +52,13 @@ @@ -54,13 +52,13 @@
54 <?php 52 <?php
55 echo LanguageForm::widget([ 53 echo LanguageForm::widget([
56 'model_langs' => $model_langs, 54 'model_langs' => $model_langs,
57 - 'formView' => '@backend/views/articles/_form_language', 55 + 'formView' => '@backend/views/article/_form_language',
58 'form' => $form, 56 'form' => $form,
59 ]); 57 ]);
60 ?> 58 ?>
61 59
62 <div class="form-group"> 60 <div class="form-group">
63 - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> 61 + <?= Html::submitButton($model->isNewRecord ? \Yii::t('app', 'Create') : \Yii::t('app', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
64 </div> 62 </div>
65 63
66 <?php ActiveForm::end(); ?> 64 <?php ActiveForm::end(); ?>
backend/views/articles/_form_language.php renamed to backend/views/article/_form_language.php
1 <?php 1 <?php
2 - use common\models\ArticlesLang; 2 + use common\models\ArticleLang;
3 use common\modules\language\models\Language; 3 use common\modules\language\models\Language;
4 use mihaildev\ckeditor\CKEditor; 4 use mihaildev\ckeditor\CKEditor;
5 use mihaildev\elfinder\ElFinder; 5 use mihaildev\elfinder\ElFinder;
@@ -7,10 +7,10 @@ @@ -7,10 +7,10 @@
7 use yii\widgets\ActiveForm; 7 use yii\widgets\ActiveForm;
8 8
9 /** 9 /**
10 - * @var ArticlesLang $model_lang  
11 - * @var Language $language  
12 - * @var ActiveForm $form  
13 - * @var View $this 10 + * @var ArticleLang $model_lang
  11 + * @var Language $language
  12 + * @var ActiveForm $form
  13 + * @var View $this
14 */ 14 */
15 ?> 15 ?>
16 <?= $form->field($model_lang, '[' . $language->language_id . ']title') 16 <?= $form->field($model_lang, '[' . $language->language_id . ']title')
backend/views/articles/_search.php renamed to backend/views/article/_search.php
backend/views/articles/create.php renamed to backend/views/article/create.php
1 <?php 1 <?php
2 - use common\models\Articles;  
3 - use common\models\ArticlesLang; 2 + use common\models\Article;
  3 + use common\models\ArticleLang;
4 use yii\helpers\Html; 4 use yii\helpers\Html;
5 use yii\web\View; 5 use yii\web\View;
6 6
7 /** 7 /**
8 * @var View $this 8 * @var View $this
9 - * @var Articles $model  
10 - * @var ArticlesLang[] $model_langs 9 + * @var Article $model
  10 + * @var ArticleLang[] $model_langs
11 */ 11 */
12 - $this->title = \Yii::t('app', 'Create Articles'); 12 + $this->title = \Yii::t('app', 'Create Article');
13 $this->params[ 'breadcrumbs' ][] = [ 13 $this->params[ 'breadcrumbs' ][] = [
14 - 'label' => \Yii::t('app', 'Articles'), 14 + 'label' => \Yii::t('app', 'Article'),
15 'url' => [ 'index' ], 15 'url' => [ 'index' ],
16 ]; 16 ];
17 $this->params[ 'breadcrumbs' ][] = $this->title; 17 $this->params[ 'breadcrumbs' ][] = $this->title;
18 ?> 18 ?>
19 -<div class="articles-create"> 19 +<div class="article-create">
20 20
21 <h1><?= Html::encode($this->title) ?></h1> 21 <h1><?= Html::encode($this->title) ?></h1>
22 22
backend/views/articles/index.php renamed to backend/views/article/index.php
@@ -4,9 +4,9 @@ @@ -4,9 +4,9 @@
4 use yii\grid\GridView; 4 use yii\grid\GridView;
5 5
6 /** 6 /**
7 - * @var yii\web\View $this  
8 - * @var common\models\ArticlesSearch $searchModel  
9 - * @var yii\data\ActiveDataProvider $dataProvider 7 + * @var yii\web\View $this
  8 + * @var common\models\ArticleSearch $searchModel
  9 + * @var yii\data\ActiveDataProvider $dataProvider
10 */ 10 */
11 11
12 $this->title = \Yii::t('app', 'Articles'); 12 $this->title = \Yii::t('app', 'Articles');
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 'attribute' => 'title', 26 'attribute' => 'title',
27 'value' => 'lang.title', 27 'value' => 'lang.title',
28 ], 28 ],
29 - 'date:date', 29 + 'created_at:date',
30 'imageUrl:image', 30 'imageUrl:image',
31 [ 'class' => 'yii\grid\ActionColumn' ], 31 [ 'class' => 'yii\grid\ActionColumn' ],
32 ], 32 ],
backend/views/articles/update.php renamed to backend/views/article/update.php
1 <?php 1 <?php
2 - use common\models\Articles;  
3 - use common\models\ArticlesLang; 2 + use common\models\Article;
  3 + use common\models\ArticleLang;
4 use yii\helpers\Html; 4 use yii\helpers\Html;
5 use yii\web\View; 5 use yii\web\View;
6 6
7 /** 7 /**
8 - * @var View $this  
9 - * @var Articles $model  
10 - * @var ArticlesLang[] $model_langs 8 + * @var View $this
  9 + * @var Article $model
  10 + * @var ArticleLang[] $model_langs
11 */ 11 */
12 - $this->title = \Yii::t('app', 'Update Articles').': ' . $model->id; 12 + $this->title = \Yii::t('app', 'Update Article') . ': ' . $model->lang->title;
13 $this->params[ 'breadcrumbs' ][] = [ 13 $this->params[ 'breadcrumbs' ][] = [
14 - 'label' => \Yii::t('app', 'Articles'), 14 + 'label' => \Yii::t('app', 'Article'),
15 'url' => [ 'index' ], 15 'url' => [ 'index' ],
16 ]; 16 ];
17 $this->params[ 'breadcrumbs' ][] = [ 17 $this->params[ 'breadcrumbs' ][] = [
18 - 'label' => $model->id, 18 + 'label' => $model->lang->title,
19 'url' => [ 19 'url' => [
20 'view', 20 'view',
21 'id' => $model->id, 21 'id' => $model->id,
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 ]; 23 ];
24 $this->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Update'); 24 $this->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Update');
25 ?> 25 ?>
26 -<div class="articles-update"> 26 +<div class="article-update">
27 27
28 <h1><?= Html::encode($this->title) ?></h1> 28 <h1><?= Html::encode($this->title) ?></h1>
29 29
backend/views/articles/view.php renamed to backend/views/article/view.php
@@ -4,18 +4,18 @@ @@ -4,18 +4,18 @@
4 use yii\widgets\DetailView; 4 use yii\widgets\DetailView;
5 5
6 /** 6 /**
7 - * @var yii\web\View $this  
8 - * @var common\models\Articles $model 7 + * @var yii\web\View $this
  8 + * @var common\models\Article $model
9 */ 9 */
10 10
11 $this->title = $model->lang->title; 11 $this->title = $model->lang->title;
12 $this->params[ 'breadcrumbs' ][] = [ 12 $this->params[ 'breadcrumbs' ][] = [
13 - 'label' => \Yii::t('app', 'Articles'), 13 + 'label' => \Yii::t('app', 'Article'),
14 'url' => [ 'index' ], 14 'url' => [ 'index' ],
15 ]; 15 ];
16 $this->params[ 'breadcrumbs' ][] = $this->title; 16 $this->params[ 'breadcrumbs' ][] = $this->title;
17 ?> 17 ?>
18 -<div class="articles-view"> 18 +<div class="article-view">
19 <h1><?= Html::encode($this->title) ?></h1> 19 <h1><?= Html::encode($this->title) ?></h1>
20 <p> 20 <p>
21 <?= Html::a(\Yii::t('app', 'Update'), [ 21 <?= Html::a(\Yii::t('app', 'Update'), [
@@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
37 'model' => $model, 37 'model' => $model,
38 'attributes' => [ 38 'attributes' => [
39 'id', 39 'id',
40 - 'date:date', 40 + 'created_at:date',
41 'lang.title', 41 'lang.title',
42 'lang.body:html', 42 'lang.body:html',
43 'imageUrl:image', 43 'imageUrl:image',
backend/views/layouts/main-sidebar.php
@@ -117,8 +117,8 @@ use yii\widgets\Menu; @@ -117,8 +117,8 @@ use yii\widgets\Menu;
117 [ 117 [
118 'label' => 'Статьи', 118 'label' => 'Статьи',
119 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-pencil"></i> <span>{label}</span></a>', 119 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-pencil"></i> <span>{label}</span></a>',
120 - 'url' => ['/articles/index'],  
121 - 'options' => ['class'=>\Yii::$app->user->can('articles') ? '' :'hide'], 120 + 'url' => ['/article/index'],
  121 + 'options' => ['class'=>\Yii::$app->user->can('article') ? '' :'hide'],
122 ], 122 ],
123 [ 123 [
124 'label' => 'Акции', 124 'label' => 'Акции',
common/behaviors/NotifyBehavior.php
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 namespace common\behaviors; 3 namespace common\behaviors;
4 4
5 - use common\models\Articles; 5 + use common\models\Article;
6 use common\modules\comment\models\CommentModel; 6 use common\modules\comment\models\CommentModel;
7 use common\modules\product\models\Product; 7 use common\modules\product\models\Product;
8 use common\widgets\Mailer; 8 use common\widgets\Mailer;
@@ -53,15 +53,15 @@ @@ -53,15 +53,15 @@
53 * @todo Change that statements 53 * @todo Change that statements
54 */ 54 */
55 if($model::className() == Product::className()) { 55 if($model::className() == Product::className()) {
56 - $url .= '/product/'.$model->alias.'#artbox-comment';  
57 - } elseif($model::className() == Articles::className()) {  
58 - $url .= '/blog/'.$model->translit.'#artbox-comment'; 56 + $url .= '/product/' . $model->alias . '#artbox-comment';
  57 + } elseif($model::className() == Article::className()) {
  58 + $url .= '/blog/' . $model->translit . '#artbox-comment';
59 } 59 }
60 $mailer = Mailer::widget([ 60 $mailer = Mailer::widget([
61 'type' => 'comment_notify', 61 'type' => 'comment_notify',
62 'params' => [ 62 'params' => [
63 - 'model' => $model,  
64 - 'url' => $url, 63 + 'model' => $model,
  64 + 'url' => $url,
65 'comment' => $owner, 65 'comment' => $owner,
66 ], 66 ],
67 'subject' => 'Ваш комментарий опубликован', 67 'subject' => 'Ваш комментарий опубликован',
common/behaviors/RatingBehavior.php
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 namespace common\behaviors; 3 namespace common\behaviors;
4 4
5 - use common\models\Articles; 5 + use common\models\Article;
6 use common\modules\comment\models\CommentModel; 6 use common\modules\comment\models\CommentModel;
7 use common\modules\product\models\Product; 7 use common\modules\product\models\Product;
8 use yii\base\Behavior; 8 use yii\base\Behavior;
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 * @var CommentModel $owner 31 * @var CommentModel $owner
32 */ 32 */
33 $owner = $this->owner; 33 $owner = $this->owner;
34 - if($owner->entity == Product::className() || $owner->entity == Articles::className()) { 34 + if($owner->entity == Product::className() || $owner->entity == Article::className()) {
35 $entity = $owner->entity; 35 $entity = $owner->entity;
36 $model = $entity::findOne($owner->entity_id); 36 $model = $entity::findOne($owner->entity_id);
37 if($model != NULL) { 37 if($model != NULL) {
common/models/Articles.php renamed to common/models/Article.php
@@ -4,8 +4,8 @@ @@ -4,8 +4,8 @@
4 4
5 use common\modules\language\behaviors\LanguageBehavior; 5 use common\modules\language\behaviors\LanguageBehavior;
6 use common\behaviors\SaveImgBehavior; 6 use common\behaviors\SaveImgBehavior;
7 - use common\modules\comment\models\CommentModel;  
8 use Yii; 7 use Yii;
  8 + use yii\behaviors\TimestampBehavior;
9 use yii\db\ActiveQuery; 9 use yii\db\ActiveQuery;
10 use yii\db\ActiveRecord; 10 use yii\db\ActiveRecord;
11 use yii\web\Request; 11 use yii\web\Request;
@@ -13,16 +13,15 @@ @@ -13,16 +13,15 @@
13 /** 13 /**
14 * This is the model class for table "articles". 14 * This is the model class for table "articles".
15 * @property integer $id 15 * @property integer $id
16 - * @property integer $date 16 + * @property integer $created_at
17 * @property string $image 17 * @property string $image
18 - * @property ArticleToRating $averageRating  
19 * * From language behavior * 18 * * From language behavior *
20 - * @property ArticlesLang $lang  
21 - * @property ArticlesLang[] $langs  
22 - * @property ArticlesLang $object_lang 19 + * @property ArticleLang $lang
  20 + * @property ArticleLang[] $langs
  21 + * @property ArticleLang $object_lang
23 * @property string $ownerKey 22 * @property string $ownerKey
24 * @property string $langKey 23 * @property string $langKey
25 - * @property ArticlesLang[] $model_langs 24 + * @property ArticleLang[] $model_langs
26 * @property bool $transactionStatus 25 * @property bool $transactionStatus
27 * @method string getOwnerKey() 26 * @method string getOwnerKey()
28 * @method void setOwnerKey( string $value ) 27 * @method void setOwnerKey( string $value )
@@ -30,7 +29,7 @@ @@ -30,7 +29,7 @@
30 * @method void setLangKey( string $value ) 29 * @method void setLangKey( string $value )
31 * @method ActiveQuery getLangs() 30 * @method ActiveQuery getLangs()
32 * @method ActiveQuery getLang( integer $language_id ) 31 * @method ActiveQuery getLang( integer $language_id )
33 - * @method ArticlesLang[] generateLangs() 32 + * @method ArticleLang[] generateLangs()
34 * @method void loadLangs( Request $request ) 33 * @method void loadLangs( Request $request )
35 * @method bool linkLangs() 34 * @method bool linkLangs()
36 * @method bool saveLangs() 35 * @method bool saveLangs()
@@ -43,7 +42,7 @@ @@ -43,7 +42,7 @@
43 * @method string|null getImageUrl( int $field ) 42 * @method string|null getImageUrl( int $field )
44 * * End SaveImgBehavior 43 * * End SaveImgBehavior
45 */ 44 */
46 - class Articles extends ActiveRecord 45 + class Article extends ActiveRecord
47 { 46 {
48 47
49 /** 48 /**
@@ -51,7 +50,7 @@ @@ -51,7 +50,7 @@
51 */ 50 */
52 public static function tableName() 51 public static function tableName()
53 { 52 {
54 - return 'articles'; 53 + return 'article';
55 } 54 }
56 55
57 /** 56 /**
@@ -65,13 +64,17 @@ @@ -65,13 +64,17 @@
65 'fields' => [ 64 'fields' => [
66 [ 65 [
67 'name' => 'image', 66 'name' => 'image',
68 - 'directory' => 'articles', 67 + 'directory' => 'article',
69 ], 68 ],
70 ], 69 ],
71 ], 70 ],
72 'language' => [ 71 'language' => [
73 'class' => LanguageBehavior::className(), 72 'class' => LanguageBehavior::className(),
74 ], 73 ],
  74 + [
  75 + 'class' => TimestampBehavior::className(),
  76 + 'updatedAtAttribute' => false,
  77 + ],
75 ]; 78 ];
76 } 79 }
77 80
@@ -82,18 +85,11 @@ @@ -82,18 +85,11 @@
82 { 85 {
83 return [ 86 return [
84 [ 87 [
85 - [ 'date' ],  
86 - 'default',  
87 - 'value' => function() {  
88 - return time();  
89 - },  
90 - ],  
91 - [  
92 - [ 'date' ], 88 + [ 'created_at' ],
93 'safe', 89 'safe',
94 ], 90 ],
95 [ 91 [
96 - [ 'date' ], 92 + [ 'created_at' ],
97 'filter', 93 'filter',
98 'filter' => function($value) { 94 'filter' => function($value) {
99 return strtotime($value) ? : time(); 95 return strtotime($value) ? : time();
@@ -108,53 +104,10 @@ @@ -108,53 +104,10 @@
108 public function attributeLabels() 104 public function attributeLabels()
109 { 105 {
110 return [ 106 return [
111 - 'id' => Yii::t('app', 'ID'),  
112 - 'date' => Yii::t('app', 'Date'),  
113 - 'image' => Yii::t('app', 'Image'),  
114 - 'imageUrl' => Yii::t('app', 'Image'), 107 + 'id' => Yii::t('app', 'ID'),
  108 + 'created_at' => Yii::t('app', 'Date'),
  109 + 'image' => Yii::t('app', 'Image'),
  110 + 'imageUrl' => Yii::t('app', 'Image'),
115 ]; 111 ];
116 } 112 }
117 -  
118 - public function recalculateRating()  
119 - {  
120 - /**  
121 - * @var ArticleToRating $averageRating  
122 - */  
123 - $average = $this->getComments()  
124 - ->joinWith('rating')  
125 - ->select([ 'average' => 'avg(artbox_comment_rating.value)::float' ])  
126 - ->scalar();  
127 - if(!$average) {  
128 - $average = 0;  
129 - }  
130 - $averageRating = $this->averageRating;  
131 - if(!empty( $averageRating )) {  
132 - $averageRating->value = $average;  
133 - } else {  
134 - $averageRating = new ArticleToRating([  
135 - 'articles_id' => $this->id,  
136 - 'value' => $average,  
137 - ]);  
138 - }  
139 - if($averageRating->save()) {  
140 - return true;  
141 - } else {  
142 - return false;  
143 - }  
144 - }  
145 -  
146 - public function getComments()  
147 - {  
148 - return $this->hasMany(CommentModel::className(), [ 'entity_id' => 'id' ])  
149 - ->where([  
150 - 'artbox_comment.entity' => self::className(),  
151 - 'artbox_comment.status' => CommentModel::STATUS_ACTIVE,  
152 - 'artbox_comment.artbox_comment_pid' => NULL,  
153 - ]);  
154 - }  
155 -  
156 - public function getAverageRating()  
157 - {  
158 - return $this->hasOne(ArticleToRating::className(), [ 'articles_id' => 'id' ]);  
159 - }  
160 } 113 }
common/models/ArticlesLang.php renamed to common/models/ArticleLang.php
@@ -7,8 +7,8 @@ @@ -7,8 +7,8 @@
7 use yii\db\ActiveRecord; 7 use yii\db\ActiveRecord;
8 8
9 /** 9 /**
10 - * This is the model class for table "articles_lang".  
11 - * @property integer $articles_id 10 + * This is the model class for table "article_lang".
  11 + * @property integer $article_id
12 * @property integer $language_id 12 * @property integer $language_id
13 * @property string $title 13 * @property string $title
14 * @property string $body 14 * @property string $body
@@ -19,16 +19,16 @@ @@ -19,16 +19,16 @@
19 * @property string $h1 19 * @property string $h1
20 * @property string $body_preview 20 * @property string $body_preview
21 * @property string $alias 21 * @property string $alias
22 - * @property Articles $articles 22 + * @property Article $article
23 * @property Language $language 23 * @property Language $language
24 */ 24 */
25 - class ArticlesLang extends ActiveRecord 25 + class ArticleLang extends ActiveRecord
26 { 26 {
27 27
28 public static function primaryKey() 28 public static function primaryKey()
29 { 29 {
30 return [ 30 return [
31 - 'articles_id', 31 + 'article_id',
32 'language_id', 32 'language_id',
33 ]; 33 ];
34 } 34 }
@@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
38 */ 38 */
39 public static function tableName() 39 public static function tableName()
40 { 40 {
41 - return 'articles_lang'; 41 + return 'article_lang';
42 } 42 }
43 43
44 public function behaviors() 44 public function behaviors()
@@ -88,22 +88,22 @@ @@ -88,22 +88,22 @@
88 ], 88 ],
89 [ 89 [
90 [ 90 [
91 - 'articles_id', 91 + 'article_id',
92 'language_id', 92 'language_id',
93 ], 93 ],
94 'unique', 94 'unique',
95 'targetAttribute' => [ 95 'targetAttribute' => [
96 - 'articles_id', 96 + 'article_id',
97 'language_id', 97 'language_id',
98 ], 98 ],
99 - 'message' => 'The combination of Articles ID and Language ID has already been taken.', 99 + 'message' => 'The combination of Article ID and Language ID has already been taken.',
100 ], 100 ],
101 [ 101 [
102 - [ 'articles_id' ], 102 + [ 'article_id' ],
103 'exist', 103 'exist',
104 'skipOnError' => true, 104 'skipOnError' => true,
105 - 'targetClass' => Articles::className(),  
106 - 'targetAttribute' => [ 'articles_id' => 'id' ], 105 + 'targetClass' => Article::className(),
  106 + 'targetAttribute' => [ 'article_id' => 'id' ],
107 ], 107 ],
108 [ 108 [
109 [ 'language_id' ], 109 [ 'language_id' ],
@@ -121,7 +121,7 @@ @@ -121,7 +121,7 @@
121 public function attributeLabels() 121 public function attributeLabels()
122 { 122 {
123 return [ 123 return [
124 - 'articles_id' => Yii::t('app', 'lang-Articles ID'), 124 + 'article_id' => Yii::t('app', 'lang-Article ID'),
125 'language_id' => Yii::t('app', 'lang-Language ID'), 125 'language_id' => Yii::t('app', 'lang-Language ID'),
126 'title' => Yii::t('app', 'lang-Title'), 126 'title' => Yii::t('app', 'lang-Title'),
127 'body' => Yii::t('app', 'lang-Body'), 127 'body' => Yii::t('app', 'lang-Body'),
@@ -137,9 +137,9 @@ @@ -137,9 +137,9 @@
137 /** 137 /**
138 * @return \yii\db\ActiveQuery 138 * @return \yii\db\ActiveQuery
139 */ 139 */
140 - public function getArticles() 140 + public function getArticle()
141 { 141 {
142 - return $this->hasOne(Articles::className(), [ 'id' => 'articles_id' ]) 142 + return $this->hasOne(Article::className(), [ 'id' => 'article_id' ])
143 ->inverseOf('langs'); 143 ->inverseOf('langs');
144 } 144 }
145 145
common/models/ArticlesSearch.php renamed to common/models/ArticleSearch.php
@@ -6,9 +6,9 @@ @@ -6,9 +6,9 @@
6 use yii\data\ActiveDataProvider; 6 use yii\data\ActiveDataProvider;
7 7
8 /** 8 /**
9 - * ArticlesSearch represents the model behind the search form about `common\models\Articles`. 9 + * ArticleSearch represents the model behind the search form about `common\models\Article`.
10 */ 10 */
11 - class ArticlesSearch extends Articles 11 + class ArticleSearch extends Article
12 { 12 {
13 13
14 public $title; 14 public $title;
@@ -53,8 +53,8 @@ @@ -53,8 +53,8 @@
53 */ 53 */
54 public function search($params) 54 public function search($params)
55 { 55 {
56 - $query = Articles::find()  
57 - ->joinWith('lang', true, 'INNER JOIN'); 56 + $query = Article::find()
  57 + ->joinWith('lang');
58 58
59 // add conditions that should always apply here 59 // add conditions that should always apply here
60 60
@@ -64,8 +64,8 @@ @@ -64,8 +64,8 @@
64 'attributes' => [ 64 'attributes' => [
65 'id', 65 'id',
66 'title' => [ 66 'title' => [
67 - 'asc' => [ 'articles_lang.title' => SORT_ASC ],  
68 - 'desc' => [ 'articles_lang.title' => SORT_DESC ], 67 + 'asc' => [ 'article_lang.title' => SORT_ASC ],
  68 + 'desc' => [ 'article_lang.title' => SORT_DESC ],
69 ], 69 ],
70 ], 70 ],
71 ], 71 ],
@@ -86,7 +86,7 @@ @@ -86,7 +86,7 @@
86 86
87 $query->andFilterWhere([ 87 $query->andFilterWhere([
88 'like', 88 'like',
89 - 'articles_lang.title', 89 + 'article_lang.title',
90 $this->title, 90 $this->title,
91 ]); 91 ]);
92 92
common/models/ArticleToRating.php deleted
1 -<?php  
2 -  
3 - namespace common\models;  
4 -  
5 - use yii\db\ActiveRecord;  
6 -  
7 - /**  
8 - * This is the model class for table "article_to_rating".  
9 - * @property integer $article_to_rating_id  
10 - * @property integer $articles_id  
11 - * @property double $value  
12 - * @property Articles $articles  
13 - */  
14 - class ArticleToRating extends ActiveRecord  
15 - {  
16 -  
17 - /**  
18 - * @inheritdoc  
19 - */  
20 - public static function tableName()  
21 - {  
22 - return 'article_to_rating';  
23 - }  
24 -  
25 - /**  
26 - * @inheritdoc  
27 - */  
28 - public function rules()  
29 - {  
30 - return [  
31 - [  
32 - [ 'articles_id' ],  
33 - 'required',  
34 - ],  
35 - [  
36 - [ 'articles_id' ],  
37 - 'integer',  
38 - ],  
39 - [  
40 - [ 'value' ],  
41 - 'number',  
42 - ],  
43 - [  
44 - [ 'articles_id' ],  
45 - 'exist',  
46 - 'skipOnError' => true,  
47 - 'targetClass' => Articles::className(),  
48 - 'targetAttribute' => [ 'articles_id' => 'id' ],  
49 - ],  
50 - ];  
51 - }  
52 -  
53 - /**  
54 - * @inheritdoc  
55 - */  
56 - public function attributeLabels()  
57 - {  
58 - return [  
59 - 'article_to_rating_id' => 'Article To Rating ID',  
60 - 'articles_id' => 'Articles ID',  
61 - 'value' => 'Value',  
62 - ];  
63 - }  
64 -  
65 - /**  
66 - * @return \yii\db\ActiveQuery  
67 - */  
68 - public function getArticles()  
69 - {  
70 - return $this->hasOne(Articles::className(), [ 'id' => 'articles_id' ]);  
71 - }  
72 - }  
console/controllers/SiteMapController.php
@@ -2,22 +2,16 @@ @@ -2,22 +2,16 @@
2 2
3 namespace console\controllers; 3 namespace console\controllers;
4 4
5 -use common\models\Articles; 5 +use common\models\Article;
6 use common\models\Seo; 6 use common\models\Seo;
7 -use common\modules\product\helpers\FilterHelper;  
8 -use common\modules\product\models\Brand;  
9 use common\modules\product\models\Category; 7 use common\modules\product\models\Category;
10 use common\modules\product\models\Product; 8 use common\modules\product\models\Product;
11 use frontend\models\ProductFrontendSearch; 9 use frontend\models\ProductFrontendSearch;
12 use Yii; 10 use Yii;
13 use common\models\Page; 11 use common\models\Page;
14 -use common\models\PageSearch;  
15 use yii\helpers\ArrayHelper; 12 use yii\helpers\ArrayHelper;
16 use yii\helpers\Url; 13 use yii\helpers\Url;
17 use yii\console\Controller; 14 use yii\console\Controller;
18 -use yii\web\NotFoundHttpException;  
19 -use yii\filters\VerbFilter;  
20 -use developeruz\db_rbac\behaviors\AccessBehavior;  
21 /** 15 /**
22 * PageController implements the CRUD actions for Page model. 16 * PageController implements the CRUD actions for Page model.
23 */ 17 */
@@ -71,7 +65,7 @@ class SiteMapController extends Controller @@ -71,7 +65,7 @@ class SiteMapController extends Controller
71 65
72 66
73 public function getArticles(){ 67 public function getArticles(){
74 - return Articles::find()->all(); 68 + return Article::find()->all();
75 } 69 }
76 70
77 public function getBrands($category){ 71 public function getBrands($category){
console/migrations/m160926_122456_create_articles_lang_table.php
@@ -3,9 +3,9 @@ @@ -3,9 +3,9 @@
3 use yii\db\Migration; 3 use yii\db\Migration;
4 4
5 /** 5 /**
6 - * Handles the creation for table `articles_lang`. 6 + * Handles the creation for table `article_lang`.
7 */ 7 */
8 - class m160926_122456_create_articles_lang_table extends Migration 8 + class m160926_122456_create_article_lang_table extends Migration
9 { 9 {
10 10
11 /** 11 /**
@@ -13,8 +13,8 @@ @@ -13,8 +13,8 @@
13 */ 13 */
14 public function up() 14 public function up()
15 { 15 {
16 - $this->createTable('articles_lang', [  
17 - 'articles_id' => $this->integer() 16 + $this->createTable('article_lang', [
  17 + 'article_id' => $this->integer()
18 ->notNull(), 18 ->notNull(),
19 'language_id' => $this->integer() 19 'language_id' => $this->integer()
20 ->notNull(), 20 ->notNull(),
@@ -30,12 +30,12 @@ @@ -30,12 +30,12 @@
30 'body_preview' => $this->text(), 30 'body_preview' => $this->text(),
31 ]); 31 ]);
32 32
33 - $this->createIndex('articles_lang_article_language_key', 'articles_lang', [  
34 - 'articles_id', 33 + $this->createIndex('article_lang_article_language_key', 'article_lang', [
  34 + 'article_id',
35 'language_id', 35 'language_id',
36 ], true); 36 ], true);
37 37
38 - $this->addForeignKey('articles_fk', 'articles_lang', 'articles_id', 'articles', 'id', 'CASCADE', 'CASCADE'); 38 + $this->addForeignKey('article_fk', 'article_lang', 'article_id', 'article', 'id', 'CASCADE', 'CASCADE');
39 $this->addForeignKey('language_fk', 'articles_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); 39 $this->addForeignKey('language_fk', 'articles_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
40 } 40 }
41 41
@@ -44,6 +44,6 @@ @@ -44,6 +44,6 @@
44 */ 44 */
45 public function down() 45 public function down()
46 { 46 {
47 - $this->dropTable('articles_lang'); 47 + $this->dropTable('article_lang');
48 } 48 }
49 } 49 }
@@ -82,4 +82,10 @@ Fix по существующему: @@ -82,4 +82,10 @@ Fix по существующему:
82 6. backend/config/bootstrap.php 82 6. backend/config/bootstrap.php
83 7. Сделать behavior для комментов/рейтинга 83 7. Сделать behavior для комментов/рейтинга
84 8. Category->setTaxGroup() ??? 84 8. Category->setTaxGroup() ???
85 -9. Избавиться от Mailer widget  
86 \ No newline at end of file 85 \ No newline at end of file
  86 +9. Избавиться от Mailer widget
  87 +10. На статьях включить клиентскую валидацию
  88 +11. Спросить у Виталика или нужно вернуть модуль file (используется elfinder ?)
  89 +
  90 +
  91 +Комментарии (создать поведение):
  92 +1. Добавить к Article с рейтингом
87 \ No newline at end of file 93 \ No newline at end of file