Commit ace6c6ed864670b1fbe8e0c1f109b695857fc95d

Authored by Alexey Boroda
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,6 +14,9 @@
14 * @var string 14 * @var string
15 */ 15 */
16 public $title; 16 public $title;
  17 +
  18 + public $tag;
  19 +
17 /** 20 /**
18 * @inheritdoc 21 * @inheritdoc
19 */ 22 */
@@ -34,7 +37,10 @@ @@ -34,7 +37,10 @@
34 'boolean', 37 'boolean',
35 ], 38 ],
36 [ 39 [
37 - [ 'title' ], 40 + [
  41 + 'title',
  42 + 'tag',
  43 + ],
38 'string', 44 'string',
39 ], 45 ],
40 ]; 46 ];
@@ -67,7 +73,12 @@ @@ -67,7 +73,12 @@
67 public function search($params) 73 public function search($params)
68 { 74 {
69 $query = Article::find() 75 $query = Article::find()
70 - ->joinWith('lang'); 76 + ->joinWith(
  77 + [
  78 + 'lang',
  79 + 'tags.lang',
  80 + ]
  81 + );
71 82
72 // add conditions that should always apply here 83 // add conditions that should always apply here
73 84
@@ -107,11 +118,19 @@ @@ -107,11 +118,19 @@
107 118
108 $query->andFilterWhere( 119 $query->andFilterWhere(
109 [ 120 [
110 - 'like', 121 + 'ilike',
111 'blog_article_lang.title', 122 'blog_article_lang.title',
112 $this->title, 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 return $dataProvider; 135 return $dataProvider;
117 } 136 }
views/blog-article/index.php
@@ -2,7 +2,9 @@ @@ -2,7 +2,9 @@
2 2
3 use artbox\weblog\models\Article; 3 use artbox\weblog\models\Article;
4 use artbox\weblog\models\ArticleSearch; 4 use artbox\weblog\models\ArticleSearch;
  5 + use artbox\weblog\models\Tag;
5 use yii\data\ActiveDataProvider; 6 use yii\data\ActiveDataProvider;
  7 + use yii\helpers\ArrayHelper;
6 use yii\helpers\Html; 8 use yii\helpers\Html;
7 use yii\grid\GridView; 9 use yii\grid\GridView;
8 use yii\web\View; 10 use yii\web\View;
@@ -42,6 +44,26 @@ @@ -42,6 +44,26 @@
42 'value' => 'lang.title', 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 'attribute' => 'image_id', 67 'attribute' => 'image_id',
46 'value' => function (Article $model) { 68 'value' => function (Article $model) {
47 if (empty($model->image_id)) { 69 if (empty($model->image_id)) {