Commit ace6c6ed864670b1fbe8e0c1f109b695857fc95d
1 parent
37517202
-Fixed rewrite to 'catalog'
Showing
2 changed files
with
44 additions
and
3 deletions
Show diff stats
models/ArticleSearch.php
| ... | ... | @@ -14,6 +14,9 @@ |
| 14 | 14 | * @var string |
| 15 | 15 | */ |
| 16 | 16 | public $title; |
| 17 | + | |
| 18 | + public $tag; | |
| 19 | + | |
| 17 | 20 | /** |
| 18 | 21 | * @inheritdoc |
| 19 | 22 | */ |
| ... | ... | @@ -34,7 +37,10 @@ |
| 34 | 37 | 'boolean', |
| 35 | 38 | ], |
| 36 | 39 | [ |
| 37 | - [ 'title' ], | |
| 40 | + [ | |
| 41 | + 'title', | |
| 42 | + 'tag', | |
| 43 | + ], | |
| 38 | 44 | 'string', |
| 39 | 45 | ], |
| 40 | 46 | ]; |
| ... | ... | @@ -67,7 +73,12 @@ |
| 67 | 73 | public function search($params) |
| 68 | 74 | { |
| 69 | 75 | $query = Article::find() |
| 70 | - ->joinWith('lang'); | |
| 76 | + ->joinWith( | |
| 77 | + [ | |
| 78 | + 'lang', | |
| 79 | + 'tags.lang', | |
| 80 | + ] | |
| 81 | + ); | |
| 71 | 82 | |
| 72 | 83 | // add conditions that should always apply here |
| 73 | 84 | |
| ... | ... | @@ -107,11 +118,19 @@ |
| 107 | 118 | |
| 108 | 119 | $query->andFilterWhere( |
| 109 | 120 | [ |
| 110 | - 'like', | |
| 121 | + 'ilike', | |
| 111 | 122 | 'blog_article_lang.title', |
| 112 | 123 | $this->title, |
| 113 | 124 | ] |
| 114 | 125 | ); |
| 126 | + | |
| 127 | + $query->andFilterWhere( | |
| 128 | + [ | |
| 129 | + 'ilike', | |
| 130 | + 'blog_tag_lang.label', | |
| 131 | + $this->tag, | |
| 132 | + ] | |
| 133 | + ); | |
| 115 | 134 | |
| 116 | 135 | return $dataProvider; |
| 117 | 136 | } | ... | ... |
views/blog-article/index.php
| ... | ... | @@ -2,7 +2,9 @@ |
| 2 | 2 | |
| 3 | 3 | use artbox\weblog\models\Article; |
| 4 | 4 | use artbox\weblog\models\ArticleSearch; |
| 5 | + use artbox\weblog\models\Tag; | |
| 5 | 6 | use yii\data\ActiveDataProvider; |
| 7 | + use yii\helpers\ArrayHelper; | |
| 6 | 8 | use yii\helpers\Html; |
| 7 | 9 | use yii\grid\GridView; |
| 8 | 10 | use yii\web\View; |
| ... | ... | @@ -42,6 +44,26 @@ |
| 42 | 44 | 'value' => 'lang.title', |
| 43 | 45 | ], |
| 44 | 46 | [ |
| 47 | + 'attribute' => 'tag', | |
| 48 | + 'label' => \Yii::t('catalog', 'Tags'), | |
| 49 | + 'value' => function (Article $model) { | |
| 50 | + if (empty($model->tags)) { | |
| 51 | + return \Yii::$app->formatter->asText(null); | |
| 52 | + } else { | |
| 53 | + return implode( | |
| 54 | + ',<br>', | |
| 55 | + ArrayHelper::getColumn( | |
| 56 | + $model->tags, | |
| 57 | + function (Tag $tag) { | |
| 58 | + return $tag->lang->label; | |
| 59 | + } | |
| 60 | + ) | |
| 61 | + ); | |
| 62 | + } | |
| 63 | + }, | |
| 64 | + 'format' => 'html', | |
| 65 | + ], | |
| 66 | + [ | |
| 45 | 67 | 'attribute' => 'image_id', |
| 46 | 68 | 'value' => function (Article $model) { |
| 47 | 69 | if (empty($model->image_id)) { | ... | ... |