Commit 6c741c3cbbe7d18bab42916577e3e43cf342e2ee
1 parent
ace6c6ed
-Blog small fixes ready
Showing
3 changed files
with
38 additions
and
4 deletions
Show diff stats
models/ArticleLang.php
| ... | ... | @@ -9,20 +9,21 @@ |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * This is the model class for table "blog_article_lang". |
| 12 | + | |
| 12 | 13 | * |
| 13 | - * @property integer $id | |
| 14 | +*@property integer $id | |
| 14 | 15 | * @property integer $blog_article_id |
| 15 | 16 | * @property integer $language_id |
| 16 | 17 | * @property string $title |
| 17 | 18 | * @property string $body |
| 18 | 19 | * @property string $body_preview |
| 19 | - * @property string $alias | |
| 20 | 20 | * @property string $meta_title |
| 21 | 21 | * @property string $meta_description |
| 22 | 22 | * @property string $h1 |
| 23 | 23 | * @property string $seo_text |
| 24 | 24 | * @property Article $article |
| 25 | 25 | * @property Language $language |
| 26 | + * @property Alias $alias | |
| 26 | 27 | */ |
| 27 | 28 | class ArticleLang extends ActiveRecord |
| 28 | 29 | { |
| ... | ... | @@ -156,6 +157,6 @@ |
| 156 | 157 | */ |
| 157 | 158 | public function getAlias() |
| 158 | 159 | { |
| 159 | - return $this->hasOne(Alias::className(), ['id' => 'alias_id']); | |
| 160 | + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]); | |
| 160 | 161 | } |
| 161 | 162 | } | ... | ... |
models/ArticleSearch.php
| ... | ... | @@ -16,6 +16,8 @@ |
| 16 | 16 | public $title; |
| 17 | 17 | |
| 18 | 18 | public $tag; |
| 19 | + | |
| 20 | + public $category; | |
| 19 | 21 | |
| 20 | 22 | /** |
| 21 | 23 | * @inheritdoc |
| ... | ... | @@ -40,6 +42,7 @@ |
| 40 | 42 | [ |
| 41 | 43 | 'title', |
| 42 | 44 | 'tag', |
| 45 | + 'category', | |
| 43 | 46 | ], |
| 44 | 47 | 'string', |
| 45 | 48 | ], |
| ... | ... | @@ -77,6 +80,7 @@ |
| 77 | 80 | [ |
| 78 | 81 | 'lang', |
| 79 | 82 | 'tags.lang', |
| 83 | + 'categories.lang', | |
| 80 | 84 | ] |
| 81 | 85 | ); |
| 82 | 86 | |
| ... | ... | @@ -131,6 +135,14 @@ |
| 131 | 135 | $this->tag, |
| 132 | 136 | ] |
| 133 | 137 | ); |
| 138 | + | |
| 139 | + $query->andFilterWhere( | |
| 140 | + [ | |
| 141 | + 'ilike', | |
| 142 | + 'blog_category_lang.title', | |
| 143 | + $this->category, | |
| 144 | + ] | |
| 145 | + ); | |
| 134 | 146 | |
| 135 | 147 | return $dataProvider; |
| 136 | 148 | } | ... | ... |
views/blog-article/index.php
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | use artbox\weblog\models\Article; |
| 4 | 4 | use artbox\weblog\models\ArticleSearch; |
| 5 | + use artbox\weblog\models\Category; | |
| 5 | 6 | use artbox\weblog\models\Tag; |
| 6 | 7 | use yii\data\ActiveDataProvider; |
| 7 | 8 | use yii\helpers\ArrayHelper; |
| ... | ... | @@ -44,8 +45,28 @@ |
| 44 | 45 | 'value' => 'lang.title', |
| 45 | 46 | ], |
| 46 | 47 | [ |
| 48 | + 'attribute' => 'category', | |
| 49 | + 'label' => \Yii::t('blog', 'Categories'), | |
| 50 | + 'value' => function (Article $model) { | |
| 51 | + if (empty($model->categories)) { | |
| 52 | + return \Yii::$app->formatter->asText(null); | |
| 53 | + } else { | |
| 54 | + return implode( | |
| 55 | + ',<br>', | |
| 56 | + ArrayHelper::getColumn( | |
| 57 | + $model->categories, | |
| 58 | + function (Category $category) { | |
| 59 | + return $category->lang->title; | |
| 60 | + } | |
| 61 | + ) | |
| 62 | + ); | |
| 63 | + } | |
| 64 | + }, | |
| 65 | + 'format' => 'html', | |
| 66 | + ], | |
| 67 | + [ | |
| 47 | 68 | 'attribute' => 'tag', |
| 48 | - 'label' => \Yii::t('catalog', 'Tags'), | |
| 69 | + 'label' => \Yii::t('blog', 'Tags'), | |
| 49 | 70 | 'value' => function (Article $model) { |
| 50 | 71 | if (empty($model->tags)) { |
| 51 | 72 | return \Yii::$app->formatter->asText(null); | ... | ... |