diff --git a/models/ArticleSearch.php b/models/ArticleSearch.php index f45edf7..3cb9330 100755 --- a/models/ArticleSearch.php +++ b/models/ArticleSearch.php @@ -14,6 +14,9 @@ * @var string */ public $title; + + public $tag; + /** * @inheritdoc */ @@ -34,7 +37,10 @@ 'boolean', ], [ - [ 'title' ], + [ + 'title', + 'tag', + ], 'string', ], ]; @@ -67,7 +73,12 @@ public function search($params) { $query = Article::find() - ->joinWith('lang'); + ->joinWith( + [ + 'lang', + 'tags.lang', + ] + ); // add conditions that should always apply here @@ -107,11 +118,19 @@ $query->andFilterWhere( [ - 'like', + 'ilike', 'blog_article_lang.title', $this->title, ] ); + + $query->andFilterWhere( + [ + 'ilike', + 'blog_tag_lang.label', + $this->tag, + ] + ); return $dataProvider; } diff --git a/views/blog-article/index.php b/views/blog-article/index.php index a56822e..3f311cb 100755 --- a/views/blog-article/index.php +++ b/views/blog-article/index.php @@ -2,7 +2,9 @@ use artbox\weblog\models\Article; use artbox\weblog\models\ArticleSearch; + use artbox\weblog\models\Tag; use yii\data\ActiveDataProvider; + use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\grid\GridView; use yii\web\View; @@ -42,6 +44,26 @@ 'value' => 'lang.title', ], [ + 'attribute' => 'tag', + 'label' => \Yii::t('catalog', 'Tags'), + 'value' => function (Article $model) { + if (empty($model->tags)) { + return \Yii::$app->formatter->asText(null); + } else { + return implode( + ',
', + ArrayHelper::getColumn( + $model->tags, + function (Tag $tag) { + return $tag->lang->label; + } + ) + ); + } + }, + 'format' => 'html', + ], + [ 'attribute' => 'image_id', 'value' => function (Article $model) { if (empty($model->image_id)) { -- libgit2 0.21.4