Commit c846c0078f721a6c47285f327db582a470d99854

Authored by Alexey Boroda
1 parent 52190232

-Blog ready

common/modules/blog/Module.php
1 1 <?php
2   -
3   -namespace common\modules\blog;
4   -
5   -/**
6   - * blog module definition class
7   - */
8   -class Module extends \yii\base\Module
9   -{
  2 +
  3 + namespace common\modules\blog;
  4 +
10 5 /**
11   - * @inheritdoc
  6 + * blog module definition class
12 7 */
13   - public $controllerNamespace = 'common\modules\blog\controllers';
14   -
15   - /**
16   - * @inheritdoc
17   - */
18   - public function init()
  8 + class Module extends \yii\base\Module
19 9 {
20   - parent::init();
21   -
22   - // custom initialization code goes here
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public $controllerNamespace = 'common\modules\blog\controllers';
  14 +
  15 + /**
  16 + * @inheritdoc
  17 + */
  18 + public function init()
  19 + {
  20 + parent::init();
  21 +
  22 + // custom initialization code goes here
  23 + }
23 24 }
24   -}
... ...
common/modules/blog/controllers/BlogArticleController.php
... ... @@ -3,16 +3,16 @@
3 3 namespace common\modules\blog\controllers;
4 4  
5 5 use common\modules\blog\models\BlogCategory;
6   - use common\modules\blog\models\BlogCategoryLang;
7 6 use common\modules\blog\models\BlogTag;
  7 + use common\modules\product\models\Product;
8 8 use Yii;
9 9 use common\modules\blog\models\BlogArticle;
10 10 use common\modules\blog\models\BlogArticleSearch;
11 11 use yii\helpers\ArrayHelper;
12   - use yii\helpers\VarDumper;
13 12 use yii\web\Controller;
14 13 use yii\web\NotFoundHttpException;
15 14 use yii\filters\VerbFilter;
  15 + use yii\web\Response;
16 16  
17 17 /**
18 18 * BlogArticleController implements the CRUD actions for BlogArticle model.
... ... @@ -108,7 +108,7 @@
108 108 }
109 109 }
110 110 }
111   -
  111 +
112 112 if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogTags' ] )) {
113 113 foreach (\Yii::$app->request->post('BlogArticle')[ 'blogTags' ] as $item) {
114 114 if ($category = BlogTag::findOne($item)) {
... ... @@ -117,6 +117,22 @@
117 117 }
118 118 }
119 119  
  120 + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'products' ] )) {
  121 + foreach (\Yii::$app->request->post('BlogArticle')[ 'products' ] as $item) {
  122 + if ($product = Product::findOne($item)) {
  123 + $model->link('products', $product);
  124 + }
  125 + }
  126 + }
  127 +
  128 + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] )) {
  129 + foreach (\Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] as $item) {
  130 + if ($article = Product::findOne($item)) {
  131 + $model->link('blogArticles', $article);
  132 + }
  133 + }
  134 + }
  135 +
120 136 return $this->redirect(
121 137 [
122 138 'view',
... ... @@ -132,6 +148,8 @@
132 148 'modelLangs' => $model->modelLangs,
133 149 'categories' => $categories,
134 150 'tags' => $tags,
  151 + 'products' => [],
  152 + 'articles' => [],
135 153 ]
136 154 );
137 155  
... ... @@ -166,6 +184,24 @@
166 184 'lang.label'
167 185 );
168 186  
  187 + $products = ArrayHelper::map(
  188 + $model->getProducts()
  189 + ->joinWith('lang')
  190 + ->asArray()
  191 + ->all(),
  192 + 'id',
  193 + 'lang.title'
  194 + );
  195 +
  196 + $articles = ArrayHelper::map(
  197 + $model->getBlogArticles()
  198 + ->joinWith('lang')
  199 + ->asArray()
  200 + ->all(),
  201 + 'id',
  202 + 'lang.title'
  203 + );
  204 +
169 205 if ($model->load(Yii::$app->request->post())) {
170 206 $model->loadLangs(\Yii::$app->request);
171 207 if ($model->save() && $model->transactionStatus) {
... ... @@ -178,12 +214,30 @@
178 214 }
179 215 }
180 216 }
181   -
  217 +
182 218 if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogTags' ] )) {
183 219 $model->unlinkAll('blogTags', true);
184 220 foreach (\Yii::$app->request->post('BlogArticle')[ 'blogTags' ] as $item) {
185   - if ($category = BlogTag::findOne($item)) {
186   - $model->link('blogTags', $category);
  221 + if ($tag = BlogTag::findOne($item)) {
  222 + $model->link('blogTags', $tag);
  223 + }
  224 + }
  225 + }
  226 +
  227 + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'products' ] )) {
  228 + $model->unlinkAll('products', true);
  229 + foreach (\Yii::$app->request->post('BlogArticle')[ 'products' ] as $item) {
  230 + if ($product = Product::findOne($item)) {
  231 + $model->link('products', $product);
  232 + }
  233 + }
  234 + }
  235 +
  236 + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] )) {
  237 + $model->unlinkAll('blogArticles', true);
  238 + foreach (\Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] as $item) {
  239 + if ($article = BlogArticle::findOne($item)) {
  240 + $model->link('blogArticles', $article);
187 241 }
188 242 }
189 243 }
... ... @@ -203,6 +257,8 @@
203 257 'modelLangs' => $model->modelLangs,
204 258 'categories' => $categories,
205 259 'tags' => $tags,
  260 + 'products' => $products,
  261 + 'articles' => $articles,
206 262 ]
207 263 );
208 264  
... ... @@ -241,4 +297,95 @@
241 297 throw new NotFoundHttpException('The requested page does not exist.');
242 298 }
243 299 }
  300 +
  301 + /**
  302 + * @param string $q
  303 + * @param null $id
  304 + *
  305 + * @return array
  306 + */
  307 + public function actionProductList($q = NULL, $id = NULL)
  308 + {
  309 + \Yii::$app->response->format = Response::FORMAT_JSON;
  310 + $out = [
  311 + 'results' => [
  312 + 'id' => '',
  313 + 'text' => '',
  314 + ],
  315 + ];
  316 + if (!is_null($q)) {
  317 + $out[ 'results' ] = Product::find()
  318 + ->joinWith('lang')
  319 + ->select(
  320 + [
  321 + 'id',
  322 + 'product_lang.title as text',
  323 + ]
  324 + )
  325 + ->where(
  326 + [
  327 + 'like',
  328 + 'product_lang.title',
  329 + $q,
  330 + ]
  331 + )
  332 + ->limit(20)
  333 + ->asArray()
  334 + ->all();
  335 + } elseif ($id > 0) {
  336 + $out[ 'results' ] = [
  337 + 'id' => $id,
  338 + 'text' => Product::find()
  339 + ->joinWith('lang')
  340 + ->where([ 'id' => $id ])
  341 + ->one()->title,
  342 + ];
  343 + }
  344 + return $out;
  345 + }
  346 +
  347 + /**
  348 + * @param string $q
  349 + * @param integer $id
  350 + *
  351 + * @return array
  352 + */
  353 + public function actionArticleList($q = NULL, $id = NULL)
  354 + {
  355 + \Yii::$app->response->format = Response::FORMAT_JSON;
  356 + $out = [
  357 + 'results' => [
  358 + 'id' => '',
  359 + 'text' => '',
  360 + ],
  361 + ];
  362 + if (!is_null($q)) {
  363 + $out[ 'results' ] = BlogArticle::find()
  364 + ->joinWith('lang')
  365 + ->select(
  366 + [
  367 + 'blog_article.id as id',
  368 + 'blog_article_lang.title as text',
  369 + ]
  370 + )
  371 + ->where(
  372 + [
  373 + 'like',
  374 + 'blog_article_lang.title',
  375 + $q,
  376 + ]
  377 + )
  378 + ->andWhere(
  379 + [
  380 + '!=',
  381 + 'blog_article.id',
  382 + $id,
  383 + ]
  384 + )
  385 + ->limit(20)
  386 + ->asArray()
  387 + ->all();
  388 + }
  389 + return $out;
  390 + }
244 391 }
... ...
common/modules/blog/models/BlogArticle.php
... ... @@ -14,34 +14,29 @@
14 14 /**
15 15 * This is the model class for table "blog_article".
16 16 *
17   - * @property integer $id
18   - * @property string $image
19   - * @property integer $created_at
20   - * @property integer $updated_at
21   - * @property integer $deleted_at
22   - * @property integer $sort
23   - * @property boolean $status
24   - * @property integer $author_id
25   - * @property BlogArticleLang[] $blogArticleLangs
26   - * @property Language[] $languages
27   - * @property BlogArticleToArticle[] $blogArticleToArticles
28   - * @property BlogArticleToArticle[] $blogArticleToArticles0
29   - * @property BlogArticle[] $relatedBlogArticles
30   - * @property BlogArticle[] $blogArticles
31   - * @property BlogArticleToCategory[] $blogArticleToCategories
32   - * @property BlogCategory[] $blogCategories
33   - * @property BlogArticleToProduct[] $blogArticleToProducts
34   - * @property Product[] $products
35   - * @property BlogArticleToTag[] $blogArticleToTags
36   - * @property BlogTag[] $blogTags
  17 + * @property integer $id
  18 + * @property string $image
  19 + * @property integer $created_at
  20 + * @property integer $updated_at
  21 + * @property integer $deleted_at
  22 + * @property integer $sort
  23 + * @property boolean $status
  24 + * @property integer $author_id
  25 + * @property BlogArticleLang[] $blogArticleLangs
  26 + * @property Language[] $languages
  27 + * @property BlogArticle[] $relatedBlogArticles
  28 + * @property BlogArticle[] $blogArticles
  29 + * @property BlogCategory[] $blogCategories
  30 + * @property Product[] $products
  31 + * @property BlogTag[] $blogTags
37 32 * * * From language behavior *
38   - * @property BlogArticleLang $lang
39   - * @property BlogArticleLang[] $langs
40   - * @property BlogArticleLang $objectLang
41   - * @property string $ownerKey
42   - * @property string $langKey
43   - * @property BlogArticleLang[] $modelLangs
44   - * @property bool $transactionStatus
  33 + * @property BlogArticleLang $lang
  34 + * @property BlogArticleLang[] $langs
  35 + * @property BlogArticleLang $objectLang
  36 + * @property string $ownerKey
  37 + * @property string $langKey
  38 + * @property BlogArticleLang[] $modelLangs
  39 + * @property bool $transactionStatus
45 40 * @method string getOwnerKey()
46 41 * @method void setOwnerKey( string $value )
47 42 * @method string getLangKey()
... ... @@ -55,8 +50,8 @@
55 50 * @method bool getTransactionStatus()
56 51 * * End language behavior *
57 52 * * From SaveImgBehavior
58   - * @property string|null $imageFile
59   - * @property string|null $imageUrl
  53 + * @property string|null $imageFile
  54 + * @property string|null $imageUrl
60 55 * @method string|null getImageFile( int $field )
61 56 * @method string|null getImageUrl( int $field )
62 57 * * End SaveImgBehavior
... ... @@ -156,22 +151,6 @@
156 151 /**
157 152 * @return \yii\db\ActiveQuery
158 153 */
159   - public function getBlogArticleToArticles()
160   - {
161   - return $this->hasMany(BlogArticleToArticle::className(), [ 'blog_article_id' => 'id' ]);
162   - }
163   -
164   - /**
165   - * @return \yii\db\ActiveQuery
166   - */
167   - public function getBlogArticleToArticles0()
168   - {
169   - return $this->hasMany(BlogArticleToArticle::className(), [ 'related_blog_article_id' => 'id' ]);
170   - }
171   -
172   - /**
173   - * @return \yii\db\ActiveQuery
174   - */
175 154 public function getRelatedBlogArticles()
176 155 {
177 156 return $this->hasMany(BlogArticle::className(), [ 'id' => 'related_blog_article_id' ])
... ... @@ -190,14 +169,6 @@
190 169 /**
191 170 * @return \yii\db\ActiveQuery
192 171 */
193   - public function getBlogArticleToCategories()
194   - {
195   - return $this->hasMany(BlogArticleToCategory::className(), [ 'blog_article_id' => 'id' ]);
196   - }
197   -
198   - /**
199   - * @return \yii\db\ActiveQuery
200   - */
201 172 public function getBlogCategories()
202 173 {
203 174 return $this->hasMany(BlogCategory::className(), [ 'id' => 'blog_category_id' ])
... ... @@ -207,14 +178,6 @@
207 178 /**
208 179 * @return \yii\db\ActiveQuery
209 180 */
210   - public function getBlogArticleToProducts()
211   - {
212   - return $this->hasMany(BlogArticleToProduct::className(), [ 'blog_article_id' => 'id' ]);
213   - }
214   -
215   - /**
216   - * @return \yii\db\ActiveQuery
217   - */
218 181 public function getProducts()
219 182 {
220 183 return $this->hasMany(Product::className(), [ 'id' => 'product_id' ])
... ... @@ -224,14 +187,6 @@
224 187 /**
225 188 * @return \yii\db\ActiveQuery
226 189 */
227   - public function getBlogArticleToTags()
228   - {
229   - return $this->hasMany(BlogArticleToTag::className(), [ 'blog_article_id' => 'id' ]);
230   - }
231   -
232   - /**
233   - * @return \yii\db\ActiveQuery
234   - */
235 190 public function getBlogTags()
236 191 {
237 192 return $this->hasMany(BlogTag::className(), [ 'id' => 'blog_tag_id' ])
... ...
common/modules/blog/models/BlogArticleLang.php
1 1 <?php
2   -
3   -namespace common\modules\blog\models;
4   -
5   -use common\modules\language\models\Language;
6   -use yii\db\ActiveRecord;
7   -
8   -/**
9   - * This is the model class for table "blog_article_lang".
10   - *
11   - * @property integer $id
12   - * @property integer $blog_article_id
13   - * @property integer $language_id
14   - * @property string $title
15   - * @property string $body
16   - * @property string $body_preview
17   - * @property string $alias
18   - * @property string $meta_title
19   - * @property string $meta_description
20   - * @property string $h1
21   - * @property string $seo_text
22   - *
23   - * @property BlogArticle $blogArticle
24   - * @property Language $language
25   - */
26   -class BlogArticleLang extends ActiveRecord
27   -{
28   - /**
29   - * @inheritdoc
30   - */
31   - public static function tableName()
32   - {
33   - return 'blog_article_lang';
34   - }
35 2  
36   - public function behaviors()
37   - {
38   - return [
39   - 'slug' => [
40   - 'class' => 'common\behaviors\Slug',
41   - ],
42   - ];
43   - }
  3 + namespace common\modules\blog\models;
  4 +
  5 + use common\modules\language\models\Language;
  6 + use yii\db\ActiveRecord;
44 7  
45 8 /**
46   - * @inheritdoc
47   - */
48   - public function rules()
49   - {
50   - return [
51   - [['blog_article_id', 'language_id'], 'required'],
52   - [['blog_article_id', 'language_id'], 'integer'],
53   - [['body', 'body_preview'], 'string'],
54   - [['title', 'alias', 'meta_title', 'meta_description', 'h1', 'seo_text'], 'string', 'max' => 255],
55   - [['alias'], 'unique'],
56   - [['blog_article_id', 'language_id'], 'unique', 'targetAttribute' => ['blog_article_id', 'language_id'], 'message' => 'The combination of Blog Article ID and Language ID has already been taken.'],
57   - [['blog_article_id'], 'exist', 'skipOnError' => true, 'targetClass' => BlogArticle::className(), 'targetAttribute' => ['blog_article_id' => 'id']],
58   - [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']],
59   - ];
60   - }
61   -
62   - /**
63   - * @inheritdoc
64   - */
65   - public function attributeLabels()
66   - {
67   - return [
68   - 'id' => 'ID',
69   - 'blog_article_id' => 'Blog Article ID',
70   - 'language_id' => 'Language ID',
71   - 'title' => 'Title',
72   - 'body' => 'Body',
73   - 'body_preview' => 'Body Preview',
74   - 'alias' => 'Alias',
75   - 'meta_title' => 'Meta Title',
76   - 'meta_description' => 'Meta Description',
77   - 'h1' => 'H1',
78   - 'seo_text' => 'Seo Text',
79   - ];
80   - }
81   -
82   - /**
83   - * @return \yii\db\ActiveQuery
84   - */
85   - public function getBlogArticle()
86   - {
87   - return $this->hasOne(BlogArticle::className(), ['id' => 'blog_article_id']);
88   - }
89   -
90   - /**
91   - * @return \yii\db\ActiveQuery
  9 + * This is the model class for table "blog_article_lang".
  10 + *
  11 + * @property integer $id
  12 + * @property integer $blog_article_id
  13 + * @property integer $language_id
  14 + * @property string $title
  15 + * @property string $body
  16 + * @property string $body_preview
  17 + * @property string $alias
  18 + * @property string $meta_title
  19 + * @property string $meta_description
  20 + * @property string $h1
  21 + * @property string $seo_text
  22 + * @property BlogArticle $blogArticle
  23 + * @property Language $language
92 24 */
93   - public function getLanguage()
  25 + class BlogArticleLang extends ActiveRecord
94 26 {
95   - return $this->hasOne(Language::className(), ['id' => 'language_id']);
  27 + /**
  28 + * @inheritdoc
  29 + */
  30 + public static function tableName()
  31 + {
  32 + return 'blog_article_lang';
  33 + }
  34 +
  35 + public function behaviors()
  36 + {
  37 + return [
  38 + 'slug' => [
  39 + 'class' => 'common\behaviors\Slug',
  40 + ],
  41 + ];
  42 + }
  43 +
  44 + /**
  45 + * @inheritdoc
  46 + */
  47 + public function rules()
  48 + {
  49 + return [
  50 + [
  51 + [
  52 + 'blog_article_id',
  53 + 'language_id',
  54 + ],
  55 + 'required',
  56 + ],
  57 + [
  58 + [
  59 + 'blog_article_id',
  60 + 'language_id',
  61 + ],
  62 + 'integer',
  63 + ],
  64 + [
  65 + [
  66 + 'body',
  67 + 'body_preview',
  68 + ],
  69 + 'string',
  70 + ],
  71 + [
  72 + [
  73 + 'title',
  74 + 'alias',
  75 + 'meta_title',
  76 + 'meta_description',
  77 + 'h1',
  78 + 'seo_text',
  79 + ],
  80 + 'string',
  81 + 'max' => 255,
  82 + ],
  83 + [
  84 + [ 'alias' ],
  85 + 'unique',
  86 + ],
  87 + [
  88 + [
  89 + 'blog_article_id',
  90 + 'language_id',
  91 + ],
  92 + 'unique',
  93 + 'targetAttribute' => [
  94 + 'blog_article_id',
  95 + 'language_id',
  96 + ],
  97 + 'message' => 'The combination of Blog Article ID and Language ID has already been taken.',
  98 + ],
  99 + [
  100 + [ 'blog_article_id' ],
  101 + 'exist',
  102 + 'skipOnError' => true,
  103 + 'targetClass' => BlogArticle::className(),
  104 + 'targetAttribute' => [ 'blog_article_id' => 'id' ],
  105 + ],
  106 + [
  107 + [ 'language_id' ],
  108 + 'exist',
  109 + 'skipOnError' => true,
  110 + 'targetClass' => Language::className(),
  111 + 'targetAttribute' => [ 'language_id' => 'id' ],
  112 + ],
  113 + ];
  114 + }
  115 +
  116 + /**
  117 + * @inheritdoc
  118 + */
  119 + public function attributeLabels()
  120 + {
  121 + return [
  122 + 'id' => 'ID',
  123 + 'blog_article_id' => 'Blog Article ID',
  124 + 'language_id' => 'Language ID',
  125 + 'title' => 'Title',
  126 + 'body' => 'Body',
  127 + 'body_preview' => 'Body Preview',
  128 + 'alias' => 'Alias',
  129 + 'meta_title' => 'Meta Title',
  130 + 'meta_description' => 'Meta Description',
  131 + 'h1' => 'H1',
  132 + 'seo_text' => 'Seo Text',
  133 + ];
  134 + }
  135 +
  136 + /**
  137 + * @return \yii\db\ActiveQuery
  138 + */
  139 + public function getBlogArticle()
  140 + {
  141 + return $this->hasOne(BlogArticle::className(), [ 'id' => 'blog_article_id' ]);
  142 + }
  143 +
  144 + /**
  145 + * @return \yii\db\ActiveQuery
  146 + */
  147 + public function getLanguage()
  148 + {
  149 + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
  150 + }
96 151 }
97   -}
... ...
common/modules/blog/models/BlogArticleSearch.php
1 1 <?php
2   -
3   -namespace common\modules\blog\models;
4   -
5   -use Yii;
6   -use yii\base\Model;
7   -use yii\data\ActiveDataProvider;
8   -use common\modules\blog\models\BlogArticle;
9   -
10   -/**
11   - * BlogArticleSearch represents the model behind the search form about `common\modules\blog\models\BlogArticle`.
12   - */
13   -class BlogArticleSearch extends BlogArticle
14   -{
15   - /**
16   - * @inheritdoc
17   - */
18   - public function rules()
19   - {
20   - return [
21   - [['id', 'created_at', 'updated_at', 'deleted_at', 'sort', 'author_id'], 'integer'],
22   - [['image'], 'safe'],
23   - [['status'], 'boolean'],
24   - ];
25   - }
26 2  
27   - /**
28   - * @inheritdoc
29   - */
30   - public function behaviors()
31   - {
32   - return [];
33   - }
  3 + namespace common\modules\blog\models;
  4 +
  5 + use yii\base\Model;
  6 + use yii\data\ActiveDataProvider;
34 7  
35 8 /**
36   - * @inheritdoc
37   - */
38   - public function scenarios()
39   - {
40   - // bypass scenarios() implementation in the parent class
41   - return Model::scenarios();
42   - }
43   -
44   - /**
45   - * Creates data provider instance with search query applied
46   - *
47   - * @param array $params
48   - *
49   - * @return ActiveDataProvider
  9 + * BlogArticleSearch represents the model behind the search form about `common\modules\blog\models\BlogArticle`.
50 10 */
51   - public function search($params)
  11 + class BlogArticleSearch extends BlogArticle
52 12 {
53   - $query = BlogArticle::find();
54   -
55   - // add conditions that should always apply here
56   -
57   - $dataProvider = new ActiveDataProvider([
58   - 'query' => $query,
59   - ]);
60   -
61   - $this->load($params);
62   -
63   - if (!$this->validate()) {
64   - // uncomment the following line if you do not want to return any records when validation fails
65   - // $query->where('0=1');
  13 + /**
  14 + * @var string
  15 + */
  16 + public $title;
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public function rules()
  21 + {
  22 + return [
  23 + [
  24 + [
  25 + 'id',
  26 + 'deleted_at',
  27 + 'sort',
  28 + 'author_id',
  29 + ],
  30 + 'integer',
  31 + ],
  32 + [
  33 + [ 'image' ],
  34 + 'safe',
  35 + ],
  36 + [
  37 + [ 'status' ],
  38 + 'boolean',
  39 + ],
  40 + [
  41 + [ 'title' ],
  42 + 'string',
  43 + ],
  44 + ];
  45 + }
  46 +
  47 + /**
  48 + * @inheritdoc
  49 + */
  50 + public function behaviors()
  51 + {
  52 + return [];
  53 + }
  54 +
  55 + /**
  56 + * @inheritdoc
  57 + */
  58 + public function scenarios()
  59 + {
  60 + // bypass scenarios() implementation in the parent class
  61 + return Model::scenarios();
  62 + }
  63 +
  64 + /**
  65 + * Creates data provider instance with search query applied
  66 + *
  67 + * @param array $params
  68 + *
  69 + * @return ActiveDataProvider
  70 + */
  71 + public function search($params)
  72 + {
  73 + $query = BlogArticle::find()
  74 + ->joinWith('lang');
  75 +
  76 + // add conditions that should always apply here
  77 +
  78 + $dataProvider = new ActiveDataProvider(
  79 + [
  80 + 'query' => $query,
  81 + 'sort' => [
  82 + 'attributes' => [
  83 + 'id',
  84 + 'created_at',
  85 + 'updated_at',
  86 + 'title' => [
  87 + 'asc' => [ 'blog_article_lang.title' => SORT_ASC ],
  88 + 'desc' => [ 'blog_article_lang.title' => SORT_DESC ],
  89 + ],
  90 + ],
  91 + ],
  92 + ]
  93 + );
  94 +
  95 + $this->load($params);
  96 +
  97 + if (!$this->validate()) {
  98 + // uncomment the following line if you do not want to return any records when validation fails
  99 + // $query->where('0=1');
  100 + return $dataProvider;
  101 + }
  102 +
  103 + // grid filtering conditions
  104 + $query->andFilterWhere(
  105 + [
  106 + 'id' => $this->id,
  107 + 'status' => $this->status,
  108 + 'author_id' => $this->author_id,
  109 + ]
  110 + );
  111 +
  112 + $query->andFilterWhere(
  113 + [
  114 + 'like',
  115 + 'image',
  116 + $this->image,
  117 + ]
  118 + );
  119 +
  120 + $query->andFilterWhere(
  121 + [
  122 + 'like',
  123 + 'blog_article_lang.title',
  124 + $this->title,
  125 + ]
  126 + );
  127 +
66 128 return $dataProvider;
67 129 }
68   -
69   - // grid filtering conditions
70   - $query->andFilterWhere([
71   - 'id' => $this->id,
72   - 'created_at' => $this->created_at,
73   - 'updated_at' => $this->updated_at,
74   - 'deleted_at' => $this->deleted_at,
75   - 'sort' => $this->sort,
76   - 'status' => $this->status,
77   - 'author_id' => $this->author_id,
78   - ]);
79   -
80   - $query->andFilterWhere(['like', 'image', $this->image]);
81   -
82   - return $dataProvider;
83 130 }
84   -}
... ...
common/modules/blog/models/BlogCategory.php
... ... @@ -12,23 +12,23 @@
12 12 /**
13 13 * This is the model class for table "blog_category".
14 14 *
15   - * @property integer $id
16   - * @property integer $sort
17   - * @property string $image
18   - * @property integer $parent_id
19   - * @property boolean $status
20   - * @property BlogArticleToCategory[] $blogArticleToCategories
21   - * @property BlogArticle[] $blogArticles
22   - * @property BlogCategoryLang[] $blogCategoryLangs
23   - * @property Language[] $languages
  15 + * @property integer $id
  16 + * @property integer $sort
  17 + * @property string $image
  18 + * @property integer $parent_id
  19 + * @property boolean $status
  20 + * @property BlogArticle[] $blogArticles
  21 + * @property BlogCategoryLang[] $blogCategoryLangs
  22 + * @property Language[] $languages
  23 + * @property BlogCategory $parent
24 24 * * From language behavior *
25   - * @property BlogCategoryLang $lang
26   - * @property BlogCategoryLang[] $langs
27   - * @property BlogCategoryLang $objectLang
28   - * @property string $ownerKey
29   - * @property string $langKey
30   - * @property BlogCategoryLang[] $modelLangs
31   - * @property bool $transactionStatus
  25 + * @property BlogCategoryLang $lang
  26 + * @property BlogCategoryLang[] $langs
  27 + * @property BlogCategoryLang $objectLang
  28 + * @property string $ownerKey
  29 + * @property string $langKey
  30 + * @property BlogCategoryLang[] $modelLangs
  31 + * @property bool $transactionStatus
32 32 * @method string getOwnerKey()
33 33 * @method void setOwnerKey( string $value )
34 34 * @method string getLangKey()
... ... @@ -42,8 +42,8 @@
42 42 * @method bool getTransactionStatus()
43 43 * * End language behavior *
44 44 * * From SaveImgBehavior *
45   - * @property string|null $imageFile
46   - * @property string|null $imageUrl
  45 + * @property string|null $imageFile
  46 + * @property string|null $imageUrl
47 47 * @method string|null getImageFile( int $field )
48 48 * @method string|null getImageUrl( int $field )
49 49 * * End SaveImgBehavior
... ... @@ -76,7 +76,7 @@
76 76 'language' => [
77 77 'class' => LanguageBehavior::className(),
78 78 ],
79   - 'Slug' => [
  79 + 'Slug' => [
80 80 'class' => 'common\behaviors\Slug',
81 81 ],
82 82 ];
... ... @@ -105,7 +105,7 @@
105 105 'max' => 255,
106 106 ],
107 107 [
108   - ['parent_id'],
  108 + [ 'parent_id' ],
109 109 'default',
110 110 'value' => 0,
111 111 ],
... ... @@ -129,14 +129,6 @@
129 129 /**
130 130 * @return \yii\db\ActiveQuery
131 131 */
132   - public function getBlogArticleToCategories()
133   - {
134   - return $this->hasMany(BlogArticleToCategory::className(), [ 'blog_category_id' => 'id' ]);
135   - }
136   -
137   - /**
138   - * @return \yii\db\ActiveQuery
139   - */
140 132 public function getBlogArticles()
141 133 {
142 134 return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ])
... ... @@ -159,4 +151,9 @@
159 151 return $this->hasMany(Language::className(), [ 'id' => 'language_id' ])
160 152 ->viaTable('blog_category_lang', [ 'blog_category_id' => 'id' ]);
161 153 }
  154 +
  155 + public function getParent()
  156 + {
  157 + return $this->hasOne(BlogCategory::className(), [ 'id' => 'parent_id' ]);
  158 + }
162 159 }
... ...
common/modules/blog/models/BlogCategoryLang.php
1 1 <?php
2   -
3   -namespace common\modules\blog\models;
4   -
5   -use yii\db\ActiveRecord;
6   -use common\modules\language\models\Language;
7   -
8   -/**
9   - * This is the model class for table "blog_category_lang".
10   - *
11   - * @property integer $id
12   - * @property integer $blog_category_id
13   - * @property integer $language_id
14   - * @property string $title
15   - * @property string $alias
16   - * @property string $description
17   - * @property string $meta_title
18   - * @property string $meta_description
19   - * @property string $h1
20   - * @property string $seo_text
21   - *
22   - * @property BlogCategory $blogCategory
23   - * @property Language $language
24   - */
25   -class BlogCategoryLang extends ActiveRecord
26   -{
27   - /**
28   - * @inheritdoc
29   - */
30   - public static function tableName()
31   - {
32   - return 'blog_category_lang';
33   - }
34   -
35   - public function behaviors()
36   - {
37   - return [
38   - 'slug' => [
39   - 'class' => 'common\behaviors\Slug',
40   - ],
41   - ];
42   - }
  2 +
  3 + namespace common\modules\blog\models;
  4 +
  5 + use yii\db\ActiveRecord;
  6 + use common\modules\language\models\Language;
43 7  
44 8 /**
45   - * @inheritdoc
46   - */
47   - public function rules()
48   - {
49   - return [
50   - [['blog_category_id', 'language_id'], 'required'],
51   - [['blog_category_id', 'language_id'], 'integer'],
52   - [['description'], 'string'],
53   - [['title', 'alias', 'meta_title', 'meta_description', 'h1', 'seo_text'], 'string', 'max' => 255],
54   - [['alias'], 'unique'],
55   - [['blog_category_id', 'language_id'], 'unique', 'targetAttribute' => ['blog_category_id', 'language_id'], 'message' => 'The combination of Blog Category ID and Language ID has already been taken.'],
56   - [['blog_category_id'], 'exist', 'skipOnError' => true, 'targetClass' => BlogCategory::className(), 'targetAttribute' => ['blog_category_id' => 'id']],
57   - [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']],
58   - ];
59   - }
60   -
61   - /**
62   - * @inheritdoc
63   - */
64   - public function attributeLabels()
65   - {
66   - return [
67   - 'id' => 'ID',
68   - 'blog_category_id' => 'Blog Category ID',
69   - 'language_id' => 'Language ID',
70   - 'title' => 'Title',
71   - 'alias' => 'Alias',
72   - 'description' => 'Description',
73   - 'meta_title' => 'Meta Title',
74   - 'meta_description' => 'Meta Description',
75   - 'h1' => 'H1',
76   - 'seo_text' => 'Seo Text',
77   - ];
78   - }
79   -
80   - /**
81   - * @return \yii\db\ActiveQuery
82   - */
83   - public function getBlogCategory()
84   - {
85   - return $this->hasOne(BlogCategory::className(), ['id' => 'blog_category_id']);
86   - }
87   -
88   - /**
89   - * @return \yii\db\ActiveQuery
  9 + * This is the model class for table "blog_category_lang".
  10 + *
  11 + * @property integer $id
  12 + * @property integer $blog_category_id
  13 + * @property integer $language_id
  14 + * @property string $title
  15 + * @property string $alias
  16 + * @property string $description
  17 + * @property string $meta_title
  18 + * @property string $meta_description
  19 + * @property string $h1
  20 + * @property string $seo_text
  21 + * @property BlogCategory $blogCategory
  22 + * @property Language $language
90 23 */
91   - public function getLanguage()
  24 + class BlogCategoryLang extends ActiveRecord
92 25 {
93   - return $this->hasOne(Language::className(), ['id' => 'language_id']);
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public static function tableName()
  30 + {
  31 + return 'blog_category_lang';
  32 + }
  33 +
  34 + public function behaviors()
  35 + {
  36 + return [
  37 + 'slug' => [
  38 + 'class' => 'common\behaviors\Slug',
  39 + ],
  40 + ];
  41 + }
  42 +
  43 + /**
  44 + * @inheritdoc
  45 + */
  46 + public function rules()
  47 + {
  48 + return [
  49 + [
  50 + [
  51 + 'blog_category_id',
  52 + 'language_id',
  53 + ],
  54 + 'required',
  55 + ],
  56 + [
  57 + [
  58 + 'blog_category_id',
  59 + 'language_id',
  60 + ],
  61 + 'integer',
  62 + ],
  63 + [
  64 + [ 'description' ],
  65 + 'string',
  66 + ],
  67 + [
  68 + [
  69 + 'title',
  70 + 'alias',
  71 + 'meta_title',
  72 + 'meta_description',
  73 + 'h1',
  74 + 'seo_text',
  75 + ],
  76 + 'string',
  77 + 'max' => 255,
  78 + ],
  79 + [
  80 + [ 'alias' ],
  81 + 'unique',
  82 + ],
  83 + [
  84 + [
  85 + 'blog_category_id',
  86 + 'language_id',
  87 + ],
  88 + 'unique',
  89 + 'targetAttribute' => [
  90 + 'blog_category_id',
  91 + 'language_id',
  92 + ],
  93 + 'message' => 'The combination of Blog Category ID and Language ID has already been taken.',
  94 + ],
  95 + [
  96 + [ 'blog_category_id' ],
  97 + 'exist',
  98 + 'skipOnError' => true,
  99 + 'targetClass' => BlogCategory::className(),
  100 + 'targetAttribute' => [ 'blog_category_id' => 'id' ],
  101 + ],
  102 + [
  103 + [ 'language_id' ],
  104 + 'exist',
  105 + 'skipOnError' => true,
  106 + 'targetClass' => Language::className(),
  107 + 'targetAttribute' => [ 'language_id' => 'id' ],
  108 + ],
  109 + ];
  110 + }
  111 +
  112 + /**
  113 + * @inheritdoc
  114 + */
  115 + public function attributeLabels()
  116 + {
  117 + return [
  118 + 'id' => 'ID',
  119 + 'blog_category_id' => 'Blog Category ID',
  120 + 'language_id' => 'Language ID',
  121 + 'title' => 'Title',
  122 + 'alias' => 'Alias',
  123 + 'description' => 'Description',
  124 + 'meta_title' => 'Meta Title',
  125 + 'meta_description' => 'Meta Description',
  126 + 'h1' => 'H1',
  127 + 'seo_text' => 'Seo Text',
  128 + ];
  129 + }
  130 +
  131 + /**
  132 + * @return \yii\db\ActiveQuery
  133 + */
  134 + public function getBlogCategory()
  135 + {
  136 + return $this->hasOne(BlogCategory::className(), [ 'id' => 'blog_category_id' ]);
  137 + }
  138 +
  139 + /**
  140 + * @return \yii\db\ActiveQuery
  141 + */
  142 + public function getLanguage()
  143 + {
  144 + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
  145 + }
94 146 }
95   -}
... ...
common/modules/blog/models/BlogCategorySearch.php
1 1 <?php
2   -
3   -namespace common\modules\blog\models;
4   -
5   -use Yii;
6   -use yii\base\Model;
7   -use yii\data\ActiveDataProvider;
8   -use common\modules\blog\models\BlogCategory;
9   -
10   -/**
11   - * BlogCategorySearch represents the model behind the search form about `common\modules\blog\models\BlogCategory`.
12   - */
13   -class BlogCategorySearch extends BlogCategory
14   -{
15   - /**
16   - * @inheritdoc
17   - */
18   - public function rules()
19   - {
20   - return [
21   - [['id', 'sort', 'parent_id'], 'integer'],
22   - [['image'], 'safe'],
23   - [['status'], 'boolean'],
24   - ];
25   - }
26 2  
27   - /**
28   - * @inheritdoc
29   - */
30   - public function behaviors()
31   - {
32   - return [];
33   - }
  3 + namespace common\modules\blog\models;
  4 +
  5 + use yii\base\Model;
  6 + use yii\data\ActiveDataProvider;
34 7  
35 8 /**
36   - * @inheritdoc
37   - */
38   - public function scenarios()
39   - {
40   - // bypass scenarios() implementation in the parent class
41   - return Model::scenarios();
42   - }
43   -
44   - /**
45   - * Creates data provider instance with search query applied
46   - *
47   - * @param array $params
48   - *
49   - * @return ActiveDataProvider
  9 + * BlogCategorySearch represents the model behind the search form about `common\modules\blog\models\BlogCategory`.
50 10 */
51   - public function search($params)
  11 + class BlogCategorySearch extends BlogCategory
52 12 {
53   - $query = BlogCategory::find();
54   -
55   - // add conditions that should always apply here
56   -
57   - $dataProvider = new ActiveDataProvider([
58   - 'query' => $query,
59   - ]);
60   -
61   - $this->load($params);
62   -
63   - if (!$this->validate()) {
64   - // uncomment the following line if you do not want to return any records when validation fails
65   - // $query->where('0=1');
  13 + /**
  14 + * @var string
  15 + */
  16 + public $title;
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public function rules()
  21 + {
  22 + return [
  23 + [
  24 + [
  25 + 'id',
  26 + 'sort',
  27 + 'parent_id',
  28 + ],
  29 + 'integer',
  30 + ],
  31 + [
  32 + [ 'image' ],
  33 + 'safe',
  34 + ],
  35 + [
  36 + [ 'status' ],
  37 + 'boolean',
  38 + ],
  39 + [
  40 + [ 'title' ],
  41 + 'string',
  42 + ],
  43 + ];
  44 + }
  45 +
  46 + /**
  47 + * @inheritdoc
  48 + */
  49 + public function behaviors()
  50 + {
  51 + return [];
  52 + }
  53 +
  54 + /**
  55 + * @inheritdoc
  56 + */
  57 + public function scenarios()
  58 + {
  59 + // bypass scenarios() implementation in the parent class
  60 + return Model::scenarios();
  61 + }
  62 +
  63 + /**
  64 + * Creates data provider instance with search query applied
  65 + *
  66 + * @param array $params
  67 + *
  68 + * @return ActiveDataProvider
  69 + */
  70 + public function search($params)
  71 + {
  72 + $query = BlogCategory::find()
  73 + ->joinWith('lang', 'parent.lang');
  74 +
  75 + // add conditions that should always apply here
  76 +
  77 + $dataProvider = new ActiveDataProvider(
  78 + [
  79 + 'query' => $query,
  80 + 'sort' => [
  81 + 'attributes' => [
  82 + 'title' => [
  83 + 'asc' => [ 'blog_category_lang.title' => SORT_ASC ],
  84 + 'desc' => [ 'blog_category_lang.title' => SORT_DESC ],
  85 + ],
  86 + 'id',
  87 + ],
  88 + ],
  89 + ]
  90 + );
  91 +
  92 + $this->load($params);
  93 +
  94 + if (!$this->validate()) {
  95 + // uncomment the following line if you do not want to return any records when validation fails
  96 + // $query->where('0=1');
  97 + return $dataProvider;
  98 + }
  99 +
  100 + // grid filtering conditions
  101 + $query->andFilterWhere(
  102 + [
  103 + 'id' => $this->id,
  104 + 'sort' => $this->sort,
  105 + 'parent_id' => $this->parent_id,
  106 + 'status' => $this->status,
  107 + ]
  108 + );
  109 +
  110 + $query->andFilterWhere(
  111 + [
  112 + 'like',
  113 + 'image',
  114 + $this->image,
  115 + ]
  116 + );
  117 +
  118 + $query->andFilterWhere(
  119 + [
  120 + 'like',
  121 + 'blog_category_lang.title',
  122 + $this->title,
  123 + ]
  124 + );
  125 +
66 126 return $dataProvider;
67 127 }
68   -
69   - // grid filtering conditions
70   - $query->andFilterWhere([
71   - 'id' => $this->id,
72   - 'sort' => $this->sort,
73   - 'parent_id' => $this->parent_id,
74   - 'status' => $this->status,
75   - ]);
76   -
77   - $query->andFilterWhere(['like', 'image', $this->image]);
78   -
79   - return $dataProvider;
80 128 }
81   -}
... ...
common/modules/blog/models/BlogTag.php
... ... @@ -11,27 +11,26 @@
11 11 /**
12 12 * This is the model class for table "blog_tag".
13 13 *
14   - * @property integer $id
15   - * @property BlogArticleToTag[] $blogArticleToTags
  14 + * @property integer $id
16 15 * @property BlogArticle[] $blogArticles
17 16 * @property BlogTagLang[] $blogTagLangs
18   - * @property Language[] $languages
  17 + * @property Language[] $languages
19 18 * * From language behavior *
20   - * @property BlogTagLang $lang
21   - * @property BlogTagLang[] $langs
22   - * @property BlogTagLang $objectLang
23   - * @property string $ownerKey
24   - * @property string $langKey
25   - * @property BlogTagLang[] $modelLangs
26   - * @property bool $transactionStatus
  19 + * @property BlogTagLang $lang
  20 + * @property BlogTagLang[] $langs
  21 + * @property BlogTagLang $objectLang
  22 + * @property string $ownerKey
  23 + * @property string $langKey
  24 + * @property BlogTagLang[] $modelLangs
  25 + * @property bool $transactionStatus
27 26 * @method string getOwnerKey()
28   - * @method void setOwnerKey(string $value)
  27 + * @method void setOwnerKey( string $value )
29 28 * @method string getLangKey()
30   - * @method void setLangKey(string $value)
  29 + * @method void setLangKey( string $value )
31 30 * @method ActiveQuery getLangs()
32 31 * @method ActiveQuery getLang( integer $language_id )
33 32 * @method BlogTagLang[] generateLangs()
34   - * @method void loadLangs(Request $request)
  33 + * @method void loadLangs( Request $request )
35 34 * @method bool linkLangs()
36 35 * @method bool saveLangs()
37 36 * @method bool getTransactionStatus()
... ... @@ -46,7 +45,7 @@
46 45 {
47 46 return 'blog_tag';
48 47 }
49   -
  48 +
50 49 /**
51 50 * @inheritdoc
52 51 */
... ... @@ -85,14 +84,6 @@
85 84 /**
86 85 * @return \yii\db\ActiveQuery
87 86 */
88   - public function getBlogArticleToTags()
89   - {
90   - return $this->hasMany(BlogArticleToTag::className(), [ 'blog_tag_id' => 'id' ]);
91   - }
92   -
93   - /**
94   - * @return \yii\db\ActiveQuery
95   - */
96 87 public function getBlogArticles()
97 88 {
98 89 return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ])
... ...
common/modules/blog/models/BlogTagLang.php
1 1 <?php
2   -
3   -namespace common\modules\blog\models;
4   -
5   -use common\modules\language\models\Language;
6   -use yii\db\ActiveRecord;
7   -
8   -/**
9   - * This is the model class for table "blog_tag_lang".
10   - *
11   - * @property integer $id
12   - * @property integer $blog_tag_id
13   - * @property integer $language_id
14   - * @property string $label
15   - *
16   - * @property BlogTag $blogTag
17   - * @property Language $language
18   - */
19   -class BlogTagLang extends ActiveRecord
20   -{
  2 +
  3 + namespace common\modules\blog\models;
  4 +
  5 + use common\modules\language\models\Language;
  6 + use yii\db\ActiveRecord;
  7 +
21 8 /**
22   - * @inheritdoc
  9 + * This is the model class for table "blog_tag_lang".
  10 + *
  11 + * @property integer $id
  12 + * @property integer $blog_tag_id
  13 + * @property integer $language_id
  14 + * @property string $label
  15 + * @property BlogTag $blogTag
  16 + * @property Language $language
23 17 */
24   - public static function tableName()
  18 + class BlogTagLang extends ActiveRecord
25 19 {
26   - return 'blog_tag_lang';
  20 + /**
  21 + * @inheritdoc
  22 + */
  23 + public static function tableName()
  24 + {
  25 + return 'blog_tag_lang';
  26 + }
  27 +
  28 + /**
  29 + * @inheritdoc
  30 + */
  31 + public function rules()
  32 + {
  33 + return [
  34 + [
  35 + [
  36 + 'blog_tag_id',
  37 + 'language_id',
  38 + ],
  39 + 'required',
  40 + ],
  41 + [
  42 + [
  43 + 'blog_tag_id',
  44 + 'language_id',
  45 + ],
  46 + 'integer',
  47 + ],
  48 + [
  49 + [ 'label' ],
  50 + 'string',
  51 + 'max' => 255,
  52 + ],
  53 + [
  54 + [
  55 + 'blog_tag_id',
  56 + 'language_id',
  57 + ],
  58 + 'unique',
  59 + 'targetAttribute' => [
  60 + 'blog_tag_id',
  61 + 'language_id',
  62 + ],
  63 + 'message' => 'The combination of Blog Tag ID and Language ID has already been taken.',
  64 + ],
  65 + [
  66 + [ 'blog_tag_id' ],
  67 + 'exist',
  68 + 'skipOnError' => true,
  69 + 'targetClass' => BlogTag::className(),
  70 + 'targetAttribute' => [ 'blog_tag_id' => 'id' ],
  71 + ],
  72 + [
  73 + [ 'language_id' ],
  74 + 'exist',
  75 + 'skipOnError' => true,
  76 + 'targetClass' => Language::className(),
  77 + 'targetAttribute' => [ 'language_id' => 'id' ],
  78 + ],
  79 + ];
  80 + }
  81 +
  82 + /**
  83 + * @inheritdoc
  84 + */
  85 + public function attributeLabels()
  86 + {
  87 + return [
  88 + 'id' => 'ID',
  89 + 'blog_tag_id' => 'Blog Tag ID',
  90 + 'language_id' => 'Language ID',
  91 + 'label' => 'Label',
  92 + ];
  93 + }
  94 +
  95 + /**
  96 + * @return \yii\db\ActiveQuery
  97 + */
  98 + public function getBlogTag()
  99 + {
  100 + return $this->hasOne(BlogTag::className(), [ 'id' => 'blog_tag_id' ]);
  101 + }
  102 +
  103 + /**
  104 + * @return \yii\db\ActiveQuery
  105 + */
  106 + public function getLanguage()
  107 + {
  108 + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
  109 + }
27 110 }
28   -
29   - /**
30   - * @inheritdoc
31   - */
32   - public function rules()
33   - {
34   - return [
35   - [['blog_tag_id', 'language_id'], 'required'],
36   - [['blog_tag_id', 'language_id'], 'integer'],
37   - [['label'], 'string', 'max' => 255],
38   - [['blog_tag_id', 'language_id'], 'unique', 'targetAttribute' => ['blog_tag_id', 'language_id'], 'message' => 'The combination of Blog Tag ID and Language ID has already been taken.'],
39   - [['blog_tag_id'], 'exist', 'skipOnError' => true, 'targetClass' => BlogTag::className(), 'targetAttribute' => ['blog_tag_id' => 'id']],
40   - [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']],
41   - ];
42   - }
43   -
44   - /**
45   - * @inheritdoc
46   - */
47   - public function attributeLabels()
48   - {
49   - return [
50   - 'id' => 'ID',
51   - 'blog_tag_id' => 'Blog Tag ID',
52   - 'language_id' => 'Language ID',
53   - 'label' => 'Label',
54   - ];
55   - }
56   -
57   - /**
58   - * @return \yii\db\ActiveQuery
59   - */
60   - public function getBlogTag()
61   - {
62   - return $this->hasOne(BlogTag::className(), ['id' => 'blog_tag_id']);
63   - }
64   -
65   - /**
66   - * @return \yii\db\ActiveQuery
67   - */
68   - public function getLanguage()
69   - {
70   - return $this->hasOne(Language::className(), ['id' => 'language_id']);
71   - }
72   -}
... ...
common/modules/blog/models/BlogTagSearch.php
1 1 <?php
2   -
3   -namespace common\modules\blog\models;
4   -
5   -use Yii;
6   -use yii\base\Model;
7   -use yii\data\ActiveDataProvider;
8   -use common\modules\blog\models\BlogTag;
9   -
10   -/**
11   - * BlogTagSearch represents the model behind the search form about `common\modules\blog\models\BlogTag`.
12   - */
13   -class BlogTagSearch extends BlogTag
14   -{
15   - /**
16   - * @inheritdoc
17   - */
18   - public function rules()
19   - {
20   - return [
21   - [['id'], 'integer'],
22   - ];
23   - }
24 2  
25   - /**
26   - * @inheritdoc
27   - */
28   - public function behaviors()
29   - {
30   - return [];
31   - }
  3 + namespace common\modules\blog\models;
  4 +
  5 + use yii\base\Model;
  6 + use yii\data\ActiveDataProvider;
32 7  
33 8 /**
34   - * @inheritdoc
35   - */
36   - public function scenarios()
37   - {
38   - // bypass scenarios() implementation in the parent class
39   - return Model::scenarios();
40   - }
41   -
42   - /**
43   - * Creates data provider instance with search query applied
44   - *
45   - * @param array $params
46   - *
47   - * @return ActiveDataProvider
  9 + * BlogTagSearch represents the model behind the search form about `common\modules\blog\models\BlogTag`.
48 10 */
49   - public function search($params)
  11 + class BlogTagSearch extends BlogTag
50 12 {
51   - $query = BlogTag::find();
52   -
53   - // add conditions that should always apply here
54   -
55   - $dataProvider = new ActiveDataProvider([
56   - 'query' => $query,
57   - ]);
58   -
59   - $this->load($params);
60   -
61   - if (!$this->validate()) {
62   - // uncomment the following line if you do not want to return any records when validation fails
63   - // $query->where('0=1');
  13 + /**
  14 + * @var string
  15 + */
  16 + public $label;
  17 +
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function rules()
  22 + {
  23 + return [
  24 + [
  25 + [ 'id' ],
  26 + 'integer',
  27 + ],
  28 + [
  29 + [ 'label' ],
  30 + 'string',
  31 + ],
  32 + ];
  33 + }
  34 +
  35 + /**
  36 + * @inheritdoc
  37 + */
  38 + public function behaviors()
  39 + {
  40 + return [];
  41 + }
  42 +
  43 + /**
  44 + * @inheritdoc
  45 + */
  46 + public function scenarios()
  47 + {
  48 + // bypass scenarios() implementation in the parent class
  49 + return Model::scenarios();
  50 + }
  51 +
  52 + /**
  53 + * Creates data provider instance with search query applied
  54 + *
  55 + * @param array $params
  56 + *
  57 + * @return ActiveDataProvider
  58 + */
  59 + public function search($params)
  60 + {
  61 + $query = BlogTag::find()
  62 + ->joinWith('lang');
  63 +
  64 + // add conditions that should always apply here
  65 +
  66 + $dataProvider = new ActiveDataProvider(
  67 + [
  68 + 'query' => $query,
  69 + 'sort' => [
  70 + 'attributes' => [
  71 + 'id',
  72 + 'label' => [
  73 + 'asc' => [ 'blog_tag_lang.label' => SORT_ASC ],
  74 + 'desc' => [ 'blog_tag_lang.label' => SORT_DESC ],
  75 + ],
  76 + ],
  77 + ],
  78 + ]
  79 + );
  80 +
  81 + $this->load($params);
  82 +
  83 + if (!$this->validate()) {
  84 + // uncomment the following line if you do not want to return any records when validation fails
  85 + // $query->where('0=1');
  86 + return $dataProvider;
  87 + }
  88 +
  89 + // grid filtering conditions
  90 + $query->andFilterWhere(
  91 + [
  92 + 'id' => $this->id,
  93 + ]
  94 + );
  95 +
  96 + $query->andFilterWhere(
  97 + [
  98 + 'like',
  99 + 'blog_tag_lang.label',
  100 + $this->label,
  101 + ]
  102 + );
  103 +
64 104 return $dataProvider;
65 105 }
66   -
67   - // grid filtering conditions
68   - $query->andFilterWhere([
69   - 'id' => $this->id,
70   - ]);
71   -
72   - return $dataProvider;
73 106 }
74   -}
... ...
common/modules/blog/views/blog-article/_form.php
... ... @@ -9,6 +9,7 @@
9 9 use yii\web\View;
10 10 use yii\widgets\ActiveForm;
11 11 use common\modules\language\widgets\LanguageForm;
  12 + use yii\web\JsExpression;
12 13  
13 14 /**
14 15 * @var View $this
... ... @@ -17,6 +18,8 @@
17 18 * @var BlogArticleLang[] $modelLangs
18 19 * @var BlogCategory[] $categories
19 20 * @var BlogTag[] $tags
  21 + * @var array $products
  22 + * @var array $articles
20 23 */
21 24 ?>
22 25  
... ... @@ -101,6 +104,68 @@
101 104 ]
102 105 ); ?>
103 106  
  107 + <?php
  108 + echo $form->field($model, 'products')
  109 + ->widget(
  110 + Select2::className(),
  111 + [
  112 + 'data' => $products,
  113 + 'options' => [
  114 + 'placeholder' => \Yii::t('blog', 'Select related products'),
  115 + 'multiple' => true,
  116 + ],
  117 + 'pluginOptions' => [
  118 + 'allowClear' => true,
  119 + 'minimumInputLength' => 3,
  120 + 'language' => [
  121 + 'errorLoading' => new JsExpression(
  122 + "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }"
  123 + ),
  124 + ],
  125 + 'ajax' => [
  126 + 'url' => yii\helpers\Url::to([ '/blog/blog-article/product-list' ]),
  127 + 'dataType' => 'json',
  128 + 'data' => new JsExpression('function(params) { return {q:params.term}; }'),
  129 + ],
  130 + 'templateResult' => new JsExpression('function(product) { return product.text; }'),
  131 + 'templateSelection' => new JsExpression('function (product) { return product.text; }'),
  132 + ],
  133 + ]
  134 + );
  135 + ?>
  136 +
  137 + <?php
  138 + echo $form->field($model, 'blogArticles')
  139 + ->widget(
  140 + Select2::className(),
  141 + [
  142 + 'data' => $articles,
  143 + 'options' => [
  144 + 'placeholder' => \Yii::t('blog', 'Select related articles'),
  145 + 'multiple' => true,
  146 + ],
  147 + 'pluginOptions' => [
  148 + 'allowClear' => true,
  149 + 'minimumInputLength' => 3,
  150 + 'language' => [
  151 + 'errorLoading' => new JsExpression(
  152 + "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }"
  153 + ),
  154 + ],
  155 + 'ajax' => [
  156 + 'url' => yii\helpers\Url::to([ '/blog/blog-article/article-list' ]),
  157 + 'dataType' => 'json',
  158 + 'data' => new JsExpression(
  159 + 'function(params) { return {q:params.term, id:' . $model->id . '}; }'
  160 + ),
  161 + ],
  162 + 'templateResult' => new JsExpression('function(article) { return article.text; }'),
  163 + 'templateSelection' => new JsExpression('function (article) { return article.text; }'),
  164 + ],
  165 + ]
  166 + );
  167 + ?>
  168 +
104 169 <?= $form->field($model, 'sort')
105 170 ->textInput() ?>
106 171  
... ...
common/modules/blog/views/blog-article/_search.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\widgets\ActiveForm;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $model common\modules\blog\models\BlogArticleSearch */
8   -/* @var $form yii\widgets\ActiveForm */
  2 +
  3 + use yii\helpers\Html;
  4 + use yii\widgets\ActiveForm;
  5 +
  6 + /* @var $this yii\web\View */
  7 + /* @var $model common\modules\blog\models\BlogArticleSearch */
  8 + /* @var $form yii\widgets\ActiveForm */
9 9 ?>
10 10  
11 11 <div class="blog-article-search">
12   -
13   - <?php $form = ActiveForm::begin([
14   - 'action' => ['index'],
15   - 'method' => 'get',
16   - ]); ?>
17   -
  12 +
  13 + <?php $form = ActiveForm::begin(
  14 + [
  15 + 'action' => [ 'index' ],
  16 + 'method' => 'get',
  17 + ]
  18 + ); ?>
  19 +
18 20 <?= $form->field($model, 'id') ?>
19   -
  21 +
20 22 <?= $form->field($model, 'image') ?>
21   -
  23 +
22 24 <?= $form->field($model, 'created_at') ?>
23   -
  25 +
24 26 <?= $form->field($model, 'updated_at') ?>
25   -
  27 +
26 28 <?= $form->field($model, 'deleted_at') ?>
27   -
  29 +
28 30 <?php // echo $form->field($model, 'sort') ?>
29   -
  31 +
30 32 <?php // echo $form->field($model, 'status')->checkbox() ?>
31   -
  33 +
32 34 <?php // echo $form->field($model, 'author_id') ?>
33   -
  35 +
34 36 <div class="form-group">
35   - <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
36   - <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
  37 + <?= Html::submitButton('Search', [ 'class' => 'btn btn-primary' ]) ?>
  38 + <?= Html::resetButton('Reset', [ 'class' => 'btn btn-default' ]) ?>
37 39 </div>
38   -
  40 +
39 41 <?php ActiveForm::end(); ?>
40 42  
41 43 </div>
... ...
common/modules/blog/views/blog-article/create.php
... ... @@ -13,11 +13,13 @@
13 13 * @var BlogArticleLang[] $modelLangs
14 14 * @var BlogCategory[] $categories
15 15 * @var BlogTag[] $tags
  16 + * @var array $products
  17 + * @var array $articles
16 18 */
17 19  
18   - $this->title = 'Create Blog Article';
  20 + $this->title = \Yii::t('blog', 'Create Blog Article');
19 21 $this->params[ 'breadcrumbs' ][] = [
20   - 'label' => 'Blog Articles',
  22 + 'label' => \Yii::t('blog', 'Blog Articles'),
21 23 'url' => [ 'index' ],
22 24 ];
23 25 $this->params[ 'breadcrumbs' ][] = $this->title;
... ... @@ -33,6 +35,8 @@
33 35 'modelLangs' => $modelLangs,
34 36 'categories' => $categories,
35 37 'tags' => $tags,
  38 + 'products' => $products,
  39 + 'articles' => $articles,
36 40 ]
37 41 ) ?>
38 42  
... ...
common/modules/blog/views/blog-article/index.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\grid\GridView;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $searchModel common\modules\blog\models\BlogArticleSearch */
8   -/* @var $dataProvider yii\data\ActiveDataProvider */
9   -
10   -$this->title = 'Blog Articles';
11   -$this->params['breadcrumbs'][] = $this->title;
  2 +
  3 + use common\modules\blog\models\BlogArticle;
  4 + use common\modules\blog\models\BlogArticleSearch;
  5 + use yii\data\ActiveDataProvider;
  6 + use yii\helpers\Html;
  7 + use yii\grid\GridView;
  8 + use yii\web\View;
  9 +
  10 + /**
  11 + * @var View $this
  12 + * @var BlogArticleSearch $searchModel
  13 + * @var ActiveDataProvider $dataProvider
  14 + */
  15 +
  16 + $this->title = \Yii::t('blog', 'Blog Articles');
  17 + $this->params[ 'breadcrumbs' ][] = $this->title;
12 18 ?>
13 19 <div class="blog-article-index">
14   -
  20 +
15 21 <h1><?= Html::encode($this->title) ?></h1>
16 22 <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
17   -
  23 +
18 24 <p>
19   - <?= Html::a('Create Blog Article', ['create'], ['class' => 'btn btn-success']) ?>
  25 + <?= Html::a(\Yii::t('blog', 'Create Blog Article'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?>
20 26 </p>
21   - <?= GridView::widget([
22   - 'dataProvider' => $dataProvider,
23   - 'filterModel' => $searchModel,
24   - 'columns' => [
25   - ['class' => 'yii\grid\SerialColumn'],
26   -
27   - 'id',
28   - 'image',
29   - 'created_at',
30   - 'updated_at',
31   - 'deleted_at',
32   - // 'sort',
33   - // 'status:boolean',
34   - // 'author_id',
35   -
36   - ['class' => 'yii\grid\ActionColumn'],
37   - ],
38   - ]); ?>
  27 + <?= GridView::widget(
  28 + [
  29 + 'dataProvider' => $dataProvider,
  30 + 'filterModel' => $searchModel,
  31 + 'columns' => [
  32 + 'id',
  33 + [
  34 + 'attribute' => 'title',
  35 + 'value' => 'lang.title',
  36 + ],
  37 + 'imageUrl:image',
  38 + [
  39 + 'attribute' => 'status',
  40 + 'value' => function($model) {
  41 + /**
  42 + * @var BlogArticle $model
  43 + */
  44 + return ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active');
  45 + },
  46 + 'filter' => [
  47 + 0 => \Yii::t('blog', 'Not active'),
  48 + 1 => \Yii::t('blog', 'Active'),
  49 + ],
  50 + ],
  51 + 'created_at:date',
  52 + 'updated_at:date',
  53 + [ 'class' => 'yii\grid\ActionColumn' ],
  54 + ],
  55 + ]
  56 + ); ?>
39 57 </div>
... ...
common/modules/blog/views/blog-article/update.php
... ... @@ -13,21 +13,23 @@
13 13 * @var BlogArticleLang[] $modelLangs
14 14 * @var BlogCategory[] $categories
15 15 * @var BlogTag[] $tags
  16 + * @var array $products
  17 + * @var array $articles
16 18 */
17 19  
18   - $this->title = 'Update Blog Article: ' . $model->id;
  20 + $this->title = \Yii::t('blog', 'Update Blog Article: ') . $model->lang->title;
19 21 $this->params[ 'breadcrumbs' ][] = [
20   - 'label' => 'Blog Articles',
  22 + 'label' => \Yii::t('blog', 'Blog Articles'),
21 23 'url' => [ 'index' ],
22 24 ];
23 25 $this->params[ 'breadcrumbs' ][] = [
24   - 'label' => $model->id,
  26 + 'label' => $model->lang->title,
25 27 'url' => [
26 28 'view',
27 29 'id' => $model->id,
28 30 ],
29 31 ];
30   - $this->params[ 'breadcrumbs' ][] = 'Update';
  32 + $this->params[ 'breadcrumbs' ][] = \Yii::t('blog', 'Update');
31 33 ?>
32 34 <div class="blog-article-update">
33 35  
... ... @@ -40,6 +42,8 @@
40 42 'modelLangs' => $modelLangs,
41 43 'categories' => $categories,
42 44 'tags' => $tags,
  45 + 'products' => $products,
  46 + 'articles' => $articles,
43 47 ]
44 48 ) ?>
45 49  
... ...
common/modules/blog/views/blog-article/view.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\widgets\DetailView;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $model common\modules\blog\models\BlogArticle */
8   -
9   -$this->title = $model->id;
10   -$this->params['breadcrumbs'][] = ['label' => 'Blog Articles', 'url' => ['index']];
11   -$this->params['breadcrumbs'][] = $this->title;
  2 +
  3 + use common\modules\blog\models\BlogArticle;
  4 + use yii\helpers\Html;
  5 + use yii\web\View;
  6 + use yii\widgets\DetailView;
  7 +
  8 + /**
  9 + * @var View $this
  10 + * @var BlogArticle $model
  11 + */
  12 +
  13 + $this->title = $model->lang->title;
  14 + $this->params[ 'breadcrumbs' ][] = [
  15 + 'label' => \Yii::t('blog', 'Blog Articles'),
  16 + 'url' => [ 'index' ],
  17 + ];
  18 + $this->params[ 'breadcrumbs' ][] = $this->title;
12 19 ?>
13 20 <div class="blog-article-view">
14   -
  21 +
15 22 <h1><?= Html::encode($this->title) ?></h1>
16   -
  23 +
17 24 <p>
18   - <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
19   - <?= Html::a('Delete', ['delete', 'id' => $model->id], [
20   - 'class' => 'btn btn-danger',
21   - 'data' => [
22   - 'confirm' => 'Are you sure you want to delete this item?',
23   - 'method' => 'post',
  25 + <?= Html::a(
  26 + 'Update',
  27 + [
  28 + 'update',
  29 + 'id' => $model->id,
  30 + ],
  31 + [ 'class' => 'btn btn-primary' ]
  32 + ) ?>
  33 + <?= Html::a(
  34 + 'Delete',
  35 + [
  36 + 'delete',
  37 + 'id' => $model->id,
24 38 ],
25   - ]) ?>
  39 + [
  40 + 'class' => 'btn btn-danger',
  41 + 'data' => [
  42 + 'confirm' => 'Are you sure you want to delete this item?',
  43 + 'method' => 'post',
  44 + ],
  45 + ]
  46 + ) ?>
26 47 </p>
27   -
28   - <?= DetailView::widget([
29   - 'model' => $model,
30   - 'attributes' => [
31   - 'id',
32   - 'image',
33   - 'created_at',
34   - 'updated_at',
35   - 'deleted_at',
36   - 'sort',
37   - 'status:boolean',
38   - 'author_id',
39   - ],
40   - ]) ?>
  48 +
  49 + <?= DetailView::widget(
  50 + [
  51 + 'model' => $model,
  52 + 'attributes' => [
  53 + 'id',
  54 + 'imageUrl:image',
  55 + 'created_at:date',
  56 + 'updated_at:date',
  57 + [
  58 + 'attribute' => 'status',
  59 + 'value' => ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'),
  60 + ],
  61 + 'lang.alias',
  62 + 'lang.body:html',
  63 + ],
  64 + ]
  65 + ) ?>
41 66  
42 67 </div>
... ...
common/modules/blog/views/blog-category/_form.php
... ... @@ -2,7 +2,7 @@
2 2  
3 3 use common\modules\blog\models\BlogCategory;
4 4 use common\modules\blog\models\BlogCategoryLang;
5   - use yii\bootstrap\Dropdown;
  5 + use kartik\select2\Select2;
6 6 use yii\helpers\Html;
7 7 use yii\web\View;
8 8 use yii\widgets\ActiveForm;
... ... @@ -66,10 +66,18 @@
66 66 <?= $form->field($model, 'sort')
67 67 ->textInput() ?>
68 68  
69   - <?= $form->field($model, 'parent_id')
70   - ->dropDownList($parentCategories, [
71   - 'prompt' => \Yii::t('blog', 'Has no parent rubric'),
72   - ]) ?>
  69 + <?php echo $form->field($model, 'parent_id')
  70 + ->widget(
  71 + Select2::className(),
  72 + [
  73 + 'data' => $parentCategories,
  74 + 'options' => [ 'placeholder' => \Yii::t('blog', 'Has no parent rubric') ],
  75 + 'pluginOptions' => [
  76 + 'allowClear' => true,
  77 + ],
  78 + ]
  79 + );
  80 + ?>
73 81  
74 82 <?= $form->field($model, 'status')
75 83 ->checkbox() ?>
... ...
common/modules/blog/views/blog-category/create.php
... ... @@ -12,9 +12,9 @@
12 12 * @var array $parentCategories
13 13 */
14 14  
15   - $this->title = 'Create Blog Category';
  15 + $this->title = \Yii::t('blog', 'Create Blog Category');
16 16 $this->params[ 'breadcrumbs' ][] = [
17   - 'label' => 'Blog Categories',
  17 + 'label' => \Yii::t('blog', 'Blog Categories'),
18 18 'url' => [ 'index' ],
19 19 ];
20 20 $this->params[ 'breadcrumbs' ][] = $this->title;
... ...
common/modules/blog/views/blog-category/index.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\grid\GridView;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $searchModel common\modules\blog\models\BlogCategorySearch */
8   -/* @var $dataProvider yii\data\ActiveDataProvider */
9   -
10   -$this->title = 'Blog Categories';
11   -$this->params['breadcrumbs'][] = $this->title;
  2 +
  3 + use common\modules\blog\models\BlogCategory;
  4 + use common\modules\blog\models\BlogCategorySearch;
  5 + use yii\data\ActiveDataProvider;
  6 + use yii\helpers\Html;
  7 + use yii\grid\GridView;
  8 + use yii\web\View;
  9 +
  10 + /**
  11 + * @var View $this
  12 + * @var BlogCategorySearch $searchModel
  13 + * @var ActiveDataProvider $dataProvider
  14 + */
  15 +
  16 + $this->title = \Yii::t('blog', 'Blog Categories');
  17 + $this->params[ 'breadcrumbs' ][] = $this->title;
12 18 ?>
13 19 <div class="blog-category-index">
14   -
  20 +
15 21 <h1><?= Html::encode($this->title) ?></h1>
16 22 <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
17   -
  23 +
18 24 <p>
19   - <?= Html::a('Create Blog Category', ['create'], ['class' => 'btn btn-success']) ?>
  25 + <?= Html::a(\Yii::t('blog', 'Create Blog Category'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?>
20 26 </p>
21   - <?= GridView::widget([
22   - 'dataProvider' => $dataProvider,
23   - 'filterModel' => $searchModel,
24   - 'columns' => [
25   - ['class' => 'yii\grid\SerialColumn'],
26   -
27   - 'id',
28   - 'sort',
29   - 'image',
30   - 'parent_id',
31   - 'status:boolean',
32   -
33   - ['class' => 'yii\grid\ActionColumn'],
34   - ],
35   - ]); ?>
  27 + <?= GridView::widget(
  28 + [
  29 + 'dataProvider' => $dataProvider,
  30 + 'filterModel' => $searchModel,
  31 + 'columns' => [
  32 + 'id',
  33 + [
  34 + 'attribute' => 'title',
  35 + 'value' => 'lang.title',
  36 + ],
  37 + 'imageUrl:image',
  38 + [
  39 + 'label' => \Yii::t('blog', 'Parent category'),
  40 + 'value' => function($model) {
  41 + /**
  42 + * @var BlogCategory $model
  43 + */
  44 + if (!empty( $model->parent )) {
  45 + return $model->parent->lang->title;
  46 + } else {
  47 + return false;
  48 + };
  49 + },
  50 + ],
  51 + [
  52 + 'attribute' => 'status',
  53 + 'value' => function($model) {
  54 + /**
  55 + * @var BlogCategory $model
  56 + */
  57 + return ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active');
  58 + },
  59 + 'filter' => [
  60 + 0 => \Yii::t('blog', 'Not active'),
  61 + 1 => \Yii::t('blog', 'Active'),
  62 + ],
  63 + ],
  64 + [ 'class' => 'yii\grid\ActionColumn' ],
  65 + ],
  66 + ]
  67 + ); ?>
36 68 </div>
... ...
common/modules/blog/views/blog-category/update.php
... ... @@ -12,19 +12,19 @@
12 12 * @var array $parentCategories
13 13 */
14 14  
15   - $this->title = 'Update Blog Category: ' . $model->id;
  15 + $this->title = \Yii::t('blog', 'Update Blog Category: ') . $model->lang->title;
16 16 $this->params[ 'breadcrumbs' ][] = [
17   - 'label' => 'Blog Categories',
  17 + 'label' => \Yii::t('blog', 'Blog Categories'),
18 18 'url' => [ 'index' ],
19 19 ];
20 20 $this->params[ 'breadcrumbs' ][] = [
21   - 'label' => $model->id,
  21 + 'label' => $model->lang->title,
22 22 'url' => [
23 23 'view',
24 24 'id' => $model->id,
25 25 ],
26 26 ];
27   - $this->params[ 'breadcrumbs' ][] = 'Update';
  27 + $this->params[ 'breadcrumbs' ][] = \Yii::t('blog', 'Update');
28 28 ?>
29 29 <div class="blog-category-update">
30 30  
... ...
common/modules/blog/views/blog-category/view.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\widgets\DetailView;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $model common\modules\blog\models\BlogCategory */
8   -
9   -$this->title = $model->id;
10   -$this->params['breadcrumbs'][] = ['label' => 'Blog Categories', 'url' => ['index']];
11   -$this->params['breadcrumbs'][] = $this->title;
  2 +
  3 + use common\modules\blog\models\BlogCategory;
  4 + use yii\helpers\Html;
  5 + use yii\web\View;
  6 + use yii\widgets\DetailView;
  7 +
  8 + /**
  9 + * @var View $this
  10 + * @var BlogCategory $model
  11 + */
  12 +
  13 + $this->title = $model->lang->title;
  14 + $this->params[ 'breadcrumbs' ][] = [
  15 + 'label' => \Yii::t('blog', 'Blog Categories'),
  16 + 'url' => [ 'index' ],
  17 + ];
  18 + $this->params[ 'breadcrumbs' ][] = $this->title;
12 19 ?>
13 20 <div class="blog-category-view">
14   -
  21 +
15 22 <h1><?= Html::encode($this->title) ?></h1>
16   -
  23 +
17 24 <p>
18   - <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
19   - <?= Html::a('Delete', ['delete', 'id' => $model->id], [
20   - 'class' => 'btn btn-danger',
21   - 'data' => [
22   - 'confirm' => 'Are you sure you want to delete this item?',
23   - 'method' => 'post',
  25 + <?= Html::a(
  26 + 'Update',
  27 + [
  28 + 'update',
  29 + 'id' => $model->id,
  30 + ],
  31 + [ 'class' => 'btn btn-primary' ]
  32 + ) ?>
  33 + <?= Html::a(
  34 + 'Delete',
  35 + [
  36 + 'delete',
  37 + 'id' => $model->id,
24 38 ],
25   - ]) ?>
  39 + [
  40 + 'class' => 'btn btn-danger',
  41 + 'data' => [
  42 + 'confirm' => 'Are you sure you want to delete this item?',
  43 + 'method' => 'post',
  44 + ],
  45 + ]
  46 + ) ?>
26 47 </p>
27   -
28   - <?= DetailView::widget([
29   - 'model' => $model,
30   - 'attributes' => [
31   - 'id',
32   - 'sort',
33   - 'image',
34   - 'parent_id',
35   - 'status:boolean',
36   - ],
37   - ]) ?>
  48 +
  49 + <?= DetailView::widget(
  50 + [
  51 + 'model' => $model,
  52 + 'attributes' => [
  53 + 'id',
  54 + 'sort',
  55 + 'imageUrl:image',
  56 + [
  57 + 'attribute' => 'parent_id',
  58 + 'value' => ( !empty( $model->parent ) ) ? $model->parent->lang->title : '',
  59 + ],
  60 + 'lang.alias',
  61 + 'lang.description:text',
  62 + [
  63 + 'attribute' => 'status',
  64 + 'value' => ( $model->status ) ? \Yii::t('blog', 'Active') : \Yii::t('blog', 'Not active'),
  65 + ],
  66 + ],
  67 + ]
  68 + ) ?>
38 69  
39 70 </div>
... ...
common/modules/blog/views/blog-tag/create.php
... ... @@ -11,9 +11,9 @@
11 11 * @var BlogTag $model
12 12 */
13 13  
14   - $this->title = 'Create Blog Tag';
  14 + $this->title = \Yii::t('blog', 'Create Blog Tag');
15 15 $this->params[ 'breadcrumbs' ][] = [
16   - 'label' => 'Blog Tags',
  16 + 'label' => \Yii::t('blog', 'Blog Tags'),
17 17 'url' => [ 'index' ],
18 18 ];
19 19 $this->params[ 'breadcrumbs' ][] = $this->title;
... ...
common/modules/blog/views/blog-tag/index.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\grid\GridView;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $searchModel common\modules\blog\models\BlogTagSearch */
8   -/* @var $dataProvider yii\data\ActiveDataProvider */
9   -
10   -$this->title = 'Blog Tags';
11   -$this->params['breadcrumbs'][] = $this->title;
  2 +
  3 + use common\modules\blog\models\BlogTagSearch;
  4 + use yii\data\ActiveDataProvider;
  5 + use yii\helpers\Html;
  6 + use yii\grid\GridView;
  7 + use yii\web\View;
  8 +
  9 + /**
  10 + * @var View $this
  11 + * @var BlogTagSearch $searchModel
  12 + * @var ActiveDataProvider $dataProvider
  13 + */
  14 +
  15 + $this->title = \Yii::t('blog', 'Blog Tags');
  16 + $this->params[ 'breadcrumbs' ][] = $this->title;
12 17 ?>
13 18 <div class="blog-tag-index">
14   -
  19 +
15 20 <h1><?= Html::encode($this->title) ?></h1>
16 21 <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
17   -
  22 +
18 23 <p>
19   - <?= Html::a('Create Blog Tag', ['create'], ['class' => 'btn btn-success']) ?>
  24 + <?= Html::a(\Yii::t('blog', 'Create Blog Tag'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?>
20 25 </p>
21   - <?= GridView::widget([
22   - 'dataProvider' => $dataProvider,
23   - 'filterModel' => $searchModel,
24   - 'columns' => [
25   - ['class' => 'yii\grid\SerialColumn'],
26   -
27   - 'id',
28   -
29   - ['class' => 'yii\grid\ActionColumn'],
30   - ],
31   - ]); ?>
  26 + <?= GridView::widget(
  27 + [
  28 + 'dataProvider' => $dataProvider,
  29 + 'filterModel' => $searchModel,
  30 + 'columns' => [
  31 + 'id',
  32 + [
  33 + 'attribute' => 'label',
  34 + 'value' => 'lang.label',
  35 + ],
  36 + [
  37 + 'class' => 'yii\grid\ActionColumn',
  38 + ],
  39 + ],
  40 + ]
  41 + ); ?>
32 42 </div>
... ...
common/modules/blog/views/blog-tag/update.php
... ... @@ -11,19 +11,19 @@
11 11 * @var BlogTag $model
12 12 */
13 13  
14   - $this->title = 'Update Blog Tag: ' . $model->id;
  14 + $this->title = \Yii::t('blog', 'Update Blog Tag: ') . $model->lang->label;
15 15 $this->params[ 'breadcrumbs' ][] = [
16   - 'label' => 'Blog Tags',
  16 + 'label' => \Yii::t('blog', 'Blog Tags'),
17 17 'url' => [ 'index' ],
18 18 ];
19 19 $this->params[ 'breadcrumbs' ][] = [
20   - 'label' => $model->id,
  20 + 'label' => $model->lang->label,
21 21 'url' => [
22 22 'view',
23 23 'id' => $model->id,
24 24 ],
25 25 ];
26   - $this->params[ 'breadcrumbs' ][] = 'Update';
  26 + $this->params[ 'breadcrumbs' ][] = \Yii::t('blog', 'Update');
27 27 ?>
28 28 <div class="blog-tag-update">
29 29  
... ...
common/modules/blog/views/blog-tag/view.php
1 1 <?php
2   -
3   -use yii\helpers\Html;
4   -use yii\widgets\DetailView;
5   -
6   -/* @var $this yii\web\View */
7   -/* @var $model common\modules\blog\models\BlogTag */
8   -
9   -$this->title = $model->id;
10   -$this->params['breadcrumbs'][] = ['label' => 'Blog Tags', 'url' => ['index']];
11   -$this->params['breadcrumbs'][] = $this->title;
  2 +
  3 + use common\modules\blog\models\BlogTag;
  4 + use yii\helpers\Html;
  5 + use yii\web\View;
  6 + use yii\widgets\DetailView;
  7 +
  8 + /**
  9 + * @var View $this
  10 + * @var BlogTag $model
  11 + */
  12 +
  13 + $this->title = $model->lang->label;
  14 + $this->params[ 'breadcrumbs' ][] = [
  15 + 'label' => \Yii::t('blog', 'Blog Tags'),
  16 + 'url' => [ 'index' ],
  17 + ];
  18 + $this->params[ 'breadcrumbs' ][] = $this->title;
12 19 ?>
13 20 <div class="blog-tag-view">
14   -
  21 +
15 22 <h1><?= Html::encode($this->title) ?></h1>
16   -
  23 +
17 24 <p>
18   - <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
19   - <?= Html::a('Delete', ['delete', 'id' => $model->id], [
20   - 'class' => 'btn btn-danger',
21   - 'data' => [
22   - 'confirm' => 'Are you sure you want to delete this item?',
23   - 'method' => 'post',
  25 + <?= Html::a(
  26 + 'Update',
  27 + [
  28 + 'update',
  29 + 'id' => $model->id,
  30 + ],
  31 + [ 'class' => 'btn btn-primary' ]
  32 + ) ?>
  33 + <?= Html::a(
  34 + 'Delete',
  35 + [
  36 + 'delete',
  37 + 'id' => $model->id,
24 38 ],
25   - ]) ?>
  39 + [
  40 + 'class' => 'btn btn-danger',
  41 + 'data' => [
  42 + 'confirm' => 'Are you sure you want to delete this item?',
  43 + 'method' => 'post',
  44 + ],
  45 + ]
  46 + ) ?>
26 47 </p>
27   -
28   - <?= DetailView::widget([
29   - 'model' => $model,
30   - 'attributes' => [
31   - 'id',
32   - ],
33   - ]) ?>
  48 +
  49 + <?= DetailView::widget(
  50 + [
  51 + 'model' => $model,
  52 + 'attributes' => [
  53 + 'id',
  54 + 'lang.label',
  55 + ],
  56 + ]
  57 + ) ?>
34 58  
35 59 </div>
... ...
common/translation/ru/blog.php
1 1 <?php
2 2 return [
3   - 'Select category' => 'Выберите категорию ...',
4   - 'Select tag' => 'Выберите тэг ...',
5   - 'Has no parent rubric' => 'Без категории',
  3 + 'Select category' => 'Выберите категорию ...',
  4 + 'Select tag' => 'Выберите тэг ...',
  5 + 'Has no parent rubric' => 'Без категории',
  6 + 'Waiting for results' => 'Загрузка ...',
  7 + 'Select related products' => 'Выберите сопутствующие товары',
  8 + 'Select related articles' => 'Выберите статьи',
  9 + 'Blog Articles' => 'Статьи блога',
  10 + 'Create Blog Article' => 'Создать статью',
  11 + 'Update Blog Article: ' => 'Обновить статью: ',
  12 + 'Not active' => 'Не активна',
  13 + 'Active' => 'Активна',
  14 + 'Are you sure you want to delete this item?' => 'Вы точно хотите это удалить ?',
  15 + 'Update' => 'Обновить',
  16 + 'Blog Categories' => 'Рубрики',
  17 + 'Create Blog Category' => 'Создать рубрику',
  18 + 'Update Blog Category: ' => 'Обновить рубрику: ',
  19 + 'Blog Tags' => 'Тэги',
  20 + 'Create Blog Tag' => 'Создать тэг',
  21 + 'Update Blog Tag: ' => 'Обновить тэг: ',
6 22 ];
7 23 \ No newline at end of file
... ...