Commit ee5882818d99db6a96ce5c1711f0653cca715dc9
1 parent
ba196ec2
-Blog backend ready
Showing
24 changed files
with
860 additions
and
783 deletions
Show diff stats
controllers/ArticleController.php
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace artbox\weblog\controllers; |
4 | - | |
5 | - use artbox\weblog\models\BlogCategory; | |
6 | - use artbox\weblog\models\BlogTag; | |
4 | + | |
5 | + use artbox\weblog\models\Category; | |
6 | + use artbox\weblog\models\Tag; | |
7 | 7 | use Yii; |
8 | 8 | use artbox\weblog\models\Article; |
9 | 9 | use artbox\weblog\models\ArticleSearch; |
... | ... | @@ -88,75 +88,37 @@ |
88 | 88 | $model = new Article(); |
89 | 89 | $model->generateLangs(); |
90 | 90 | |
91 | - // $categories = ArrayHelper::map( | |
92 | - // BlogCategory::find() | |
93 | - // ->joinWith('lang') | |
94 | - // ->all(), | |
95 | - // 'id', | |
96 | - // 'lang.title' | |
97 | - // ); | |
98 | - // | |
99 | - // $tags = ArrayHelper::map( | |
100 | - // BlogTag::find() | |
101 | - // ->joinWith('lang') | |
102 | - // ->all(), | |
103 | - // 'id', | |
104 | - // 'lang.label' | |
105 | - // ); | |
106 | - | |
107 | - if ($model->load(Yii::$app->request->post())) { | |
108 | - $model->loadLangs(\Yii::$app->request); | |
109 | - if ($model->save() && $model->transactionStatus) { | |
110 | - | |
111 | - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] )) { | |
112 | - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] as $item) { | |
113 | - if ($category = BlogCategory::findOne($item)) { | |
114 | - $model->link('blogCategories', $category); | |
115 | - } | |
116 | - } | |
117 | - } | |
118 | - | |
119 | - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogTags' ] )) { | |
120 | - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogTags' ] as $item) { | |
121 | - if ($category = BlogTag::findOne($item)) { | |
122 | - $model->link('blogTags', $category); | |
123 | - } | |
124 | - } | |
125 | - } | |
126 | - | |
127 | - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'products' ] )) { | |
128 | - foreach (\Yii::$app->request->post('BlogArticle')[ 'products' ] as $item) { | |
129 | - if ($product = Product::findOne($item)) { | |
130 | - $model->link('products', $product); | |
131 | - } | |
132 | - } | |
133 | - } | |
134 | - | |
135 | - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] )) { | |
136 | - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] as $item) { | |
137 | - if ($article = Product::findOne($item)) { | |
138 | - $model->link('blogArticles', $article); | |
139 | - } | |
140 | - } | |
141 | - } | |
142 | - | |
143 | - return $this->redirect( | |
144 | - [ | |
145 | - 'view', | |
146 | - 'id' => $model->id, | |
147 | - ] | |
148 | - ); | |
149 | - } | |
91 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
92 | + | |
93 | + $categories = Category::find() | |
94 | + ->where([ 'id' => \Yii::$app->request->post('categoryIds') ]) | |
95 | + ->all(); | |
96 | + | |
97 | + $model->linkMany('categories', $categories); | |
98 | + | |
99 | + $tags = Tag::find() | |
100 | + ->where( | |
101 | + [ | |
102 | + 'id' => \Yii::$app->request->post('tagIds'), | |
103 | + ] | |
104 | + ) | |
105 | + ->all(); | |
106 | + | |
107 | + $model->linkMany('tags', $tags); | |
108 | + | |
109 | + return $this->redirect( | |
110 | + [ | |
111 | + 'view', | |
112 | + 'id' => $model->id, | |
113 | + ] | |
114 | + ); | |
150 | 115 | } |
116 | + | |
151 | 117 | return $this->render( |
152 | 118 | 'create', |
153 | 119 | [ |
154 | 120 | 'model' => $model, |
155 | 121 | 'modelLangs' => $model->modelLangs, |
156 | - // 'categories' => $categories, | |
157 | - // 'tags' => $tags, | |
158 | - 'products' => [], | |
159 | - 'articles' => [], | |
160 | 122 | ] |
161 | 123 | ); |
162 | 124 | |
... | ... | @@ -174,98 +136,55 @@ |
174 | 136 | { |
175 | 137 | $model = $this->findModel($id); |
176 | 138 | $model->generateLangs(); |
177 | - | |
178 | - $categories = ArrayHelper::map( | |
179 | - BlogCategory::find() | |
180 | - ->joinWith('lang') | |
181 | - ->all(), | |
139 | + | |
140 | + $model->categoryIds = ArrayHelper::map( | |
141 | + $model->categories, | |
182 | 142 | 'id', |
183 | 143 | 'lang.title' |
184 | 144 | ); |
185 | - | |
186 | - $tags = ArrayHelper::map( | |
187 | - BlogTag::find() | |
188 | - ->joinWith('lang') | |
189 | - ->all(), | |
145 | + | |
146 | + $model->tagIds = ArrayHelper::map( | |
147 | + $model->tags, | |
190 | 148 | 'id', |
191 | 149 | 'lang.label' |
192 | 150 | ); |
193 | - | |
194 | - $products = ArrayHelper::map( | |
195 | - $model->getProducts() | |
196 | - ->joinWith('lang') | |
197 | - ->asArray() | |
198 | - ->all(), | |
199 | - 'id', | |
200 | - 'lang.title' | |
201 | - ); | |
202 | - | |
203 | - $articles = ArrayHelper::map( | |
204 | - $model->getBlogArticles() | |
205 | - ->joinWith('lang') | |
206 | - ->asArray() | |
207 | - ->all(), | |
151 | + | |
152 | + $model->articleIds = ArrayHelper::map( | |
153 | + $model->articles, | |
208 | 154 | 'id', |
209 | 155 | 'lang.title' |
210 | 156 | ); |
211 | - | |
212 | - if ($model->load(Yii::$app->request->post())) { | |
213 | - $model->loadLangs(\Yii::$app->request); | |
214 | - if ($model->save() && $model->transactionStatus) { | |
215 | - | |
216 | - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] )) { | |
217 | - $model->unlinkAll('blogCategories', true); | |
218 | - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] as $item) { | |
219 | - if ($category = BlogCategory::findOne($item)) { | |
220 | - $model->link('blogCategories', $category); | |
221 | - } | |
222 | - } | |
223 | - } | |
224 | - | |
225 | - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogTags' ] )) { | |
226 | - $model->unlinkAll('blogTags', true); | |
227 | - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogTags' ] as $item) { | |
228 | - if ($tag = BlogTag::findOne($item)) { | |
229 | - $model->link('blogTags', $tag); | |
230 | - } | |
231 | - } | |
232 | - } | |
233 | - | |
234 | - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'products' ] )) { | |
235 | - $model->unlinkAll('products', true); | |
236 | - foreach (\Yii::$app->request->post('BlogArticle')[ 'products' ] as $item) { | |
237 | - if ($product = Product::findOne($item)) { | |
238 | - $model->link('products', $product); | |
239 | - } | |
240 | - } | |
241 | - } | |
242 | - | |
243 | - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] )) { | |
244 | - $model->unlinkAll('blogArticles', true); | |
245 | - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] as $item) { | |
246 | - if ($article = BlogArticle::findOne($item)) { | |
247 | - $model->link('blogArticles', $article); | |
248 | - } | |
249 | - } | |
250 | - } | |
251 | - | |
252 | - return $this->redirect( | |
253 | - [ | |
254 | - 'view', | |
255 | - 'id' => $model->id, | |
256 | - ] | |
257 | - ); | |
258 | - } | |
157 | + | |
158 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
159 | + $categories = Category::find() | |
160 | + ->where([ 'id' => \Yii::$app->request->post('categoryIds') ]) | |
161 | + ->all(); | |
162 | + | |
163 | + $model->linkMany('categories', $categories); | |
164 | + | |
165 | + $tags = Tag::find() | |
166 | + ->where( | |
167 | + [ | |
168 | + 'id' => \Yii::$app->request->post('tagIds'), | |
169 | + ] | |
170 | + ) | |
171 | + ->all(); | |
172 | + | |
173 | + $model->linkMany('tags', $tags); | |
174 | + | |
175 | + return $this->redirect( | |
176 | + [ | |
177 | + 'view', | |
178 | + 'id' => $model->id, | |
179 | + ] | |
180 | + ); | |
181 | + | |
259 | 182 | } |
260 | 183 | return $this->render( |
261 | 184 | 'update', |
262 | 185 | [ |
263 | 186 | 'model' => $model, |
264 | 187 | 'modelLangs' => $model->modelLangs, |
265 | - 'categories' => $categories, | |
266 | - 'tags' => $tags, | |
267 | - 'products' => $products, | |
268 | - 'articles' => $articles, | |
269 | 188 | ] |
270 | 189 | ); |
271 | 190 | |
... | ... | @@ -290,9 +209,8 @@ |
290 | 209 | /** |
291 | 210 | * Finds the BlogArticle model based on its primary key value. |
292 | 211 | * If the model is not found, a 404 HTTP exception will be thrown. |
293 | - | |
294 | -* | |
295 | -*@param integer $id | |
212 | + * | |
213 | + * @param integer $id | |
296 | 214 | * |
297 | 215 | *@return Article the loaded model |
298 | 216 | * @throws NotFoundHttpException if the model cannot be found |
... | ... | @@ -305,59 +223,6 @@ |
305 | 223 | throw new NotFoundHttpException('The requested page does not exist.'); |
306 | 224 | } |
307 | 225 | } |
308 | - | |
309 | - public function actionList($q = null, $id = null) | |
310 | - { | |
311 | - \Yii::$app->response->format = Response::FORMAT_JSON; | |
312 | - $out = [ | |
313 | - 'results' => [ | |
314 | - [ | |
315 | - 'id' => '', | |
316 | - 'text' => '', | |
317 | - ], | |
318 | - ], | |
319 | - ]; | |
320 | - if (!is_null($q)) { | |
321 | - $categories = Article::find() | |
322 | - ->joinWith('lang') | |
323 | - ->select( | |
324 | - [ | |
325 | - 'id', | |
326 | - 'text' => 'category_lang.title', | |
327 | - ] | |
328 | - ) | |
329 | - ->filterWhere( | |
330 | - [ | |
331 | - '!=', | |
332 | - 'id', | |
333 | - $id, | |
334 | - ] | |
335 | - ) | |
336 | - ->andFilterWhere( | |
337 | - [ | |
338 | - 'like', | |
339 | - 'category_lang.title', | |
340 | - $q, | |
341 | - ] | |
342 | - ) | |
343 | - ->andFilterWhere( | |
344 | - [ | |
345 | - '!=', | |
346 | - 'parent_id', | |
347 | - $id, | |
348 | - ] | |
349 | - ) | |
350 | - ->limit(20) | |
351 | - ->asArray() | |
352 | - ->all(); | |
353 | - | |
354 | - if (!empty($categories)) { | |
355 | - $out[ 'results' ] = $categories; | |
356 | - } | |
357 | - } | |
358 | - | |
359 | - return $out; | |
360 | - } | |
361 | 226 | |
362 | 227 | /** |
363 | 228 | * @param string $q |
... | ... | @@ -365,7 +230,7 @@ |
365 | 230 | * |
366 | 231 | * @return array |
367 | 232 | */ |
368 | - public function actionArticleList($q = NULL, $id = NULL) | |
233 | + public function actionList(string $q = null, int $id = null) | |
369 | 234 | { |
370 | 235 | \Yii::$app->response->format = Response::FORMAT_JSON; |
371 | 236 | $out = [ |
... | ... | @@ -375,31 +240,31 @@ |
375 | 240 | ], |
376 | 241 | ]; |
377 | 242 | if (!is_null($q)) { |
378 | - $out[ 'results' ] = BlogArticle::find() | |
379 | - ->joinWith('lang') | |
380 | - ->select( | |
381 | - [ | |
382 | - 'blog_article.id as id', | |
383 | - 'blog_article_lang.title as text', | |
384 | - ] | |
385 | - ) | |
386 | - ->where( | |
387 | - [ | |
388 | - 'like', | |
389 | - 'blog_article_lang.title', | |
390 | - $q, | |
391 | - ] | |
392 | - ) | |
393 | - ->andWhere( | |
394 | - [ | |
395 | - '!=', | |
396 | - 'blog_article.id', | |
397 | - $id, | |
398 | - ] | |
399 | - ) | |
400 | - ->limit(20) | |
401 | - ->asArray() | |
402 | - ->all(); | |
243 | + $out[ 'results' ] = Article::find() | |
244 | + ->joinWith('lang') | |
245 | + ->select( | |
246 | + [ | |
247 | + 'blog_article.id as id', | |
248 | + 'blog_article_lang.title as text', | |
249 | + ] | |
250 | + ) | |
251 | + ->where( | |
252 | + [ | |
253 | + 'like', | |
254 | + 'blog_article_lang.title', | |
255 | + $q, | |
256 | + ] | |
257 | + ) | |
258 | + ->andFilterWhere( | |
259 | + [ | |
260 | + '!=', | |
261 | + 'blog_article.id', | |
262 | + $id, | |
263 | + ] | |
264 | + ) | |
265 | + ->limit(20) | |
266 | + ->asArray() | |
267 | + ->all(); | |
403 | 268 | } |
404 | 269 | return $out; |
405 | 270 | } | ... | ... |
controllers/CategoryController.php
... | ... | @@ -2,12 +2,14 @@ |
2 | 2 | |
3 | 3 | namespace artbox\weblog\controllers; |
4 | 4 | |
5 | + use artbox\weblog\models\Category; | |
5 | 6 | use artbox\weblog\models\CategorySearch; |
6 | 7 | use Yii; |
7 | 8 | use yii\helpers\ArrayHelper; |
8 | 9 | use yii\web\Controller; |
9 | 10 | use yii\web\NotFoundHttpException; |
10 | 11 | use yii\filters\VerbFilter; |
12 | + use yii\web\Response; | |
11 | 13 | |
12 | 14 | /** |
13 | 15 | * BlogCategoryController implements the CRUD actions for BlogCategory model. |
... | ... | @@ -81,31 +83,28 @@ |
81 | 83 | */ |
82 | 84 | public function actionCreate() |
83 | 85 | { |
84 | - $model = new BlogCategory(); | |
86 | + $model = new Category(); | |
85 | 87 | $model->generateLangs(); |
86 | 88 | $parentCategories = ArrayHelper::map( |
87 | - BlogCategory::find() | |
88 | - ->joinWith('lang') | |
89 | - ->where( | |
90 | - [ | |
91 | - 'parent_id' => 0, | |
92 | - ] | |
93 | - ) | |
94 | - ->all(), | |
89 | + Category::find() | |
90 | + ->joinWith('lang') | |
91 | + ->where( | |
92 | + [ | |
93 | + 'parent_id' => 0, | |
94 | + ] | |
95 | + ) | |
96 | + ->all(), | |
95 | 97 | 'id', |
96 | 98 | 'lang.title' |
97 | 99 | ); |
98 | 100 | |
99 | - if ($model->load(Yii::$app->request->post())) { | |
100 | - $model->loadLangs(\Yii::$app->request); | |
101 | - if ($model->save() && $model->transactionStatus) { | |
102 | - return $this->redirect( | |
103 | - [ | |
104 | - 'view', | |
105 | - 'id' => $model->id, | |
106 | - ] | |
107 | - ); | |
108 | - } | |
101 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
102 | + return $this->redirect( | |
103 | + [ | |
104 | + 'view', | |
105 | + 'id' => $model->id, | |
106 | + ] | |
107 | + ); | |
109 | 108 | } |
110 | 109 | return $this->render( |
111 | 110 | 'create', |
... | ... | @@ -131,35 +130,32 @@ |
131 | 130 | $model = $this->findModel($id); |
132 | 131 | $model->generateLangs(); |
133 | 132 | $parentCategories = ArrayHelper::map( |
134 | - BlogCategory::find() | |
135 | - ->joinWith('lang') | |
136 | - ->where( | |
137 | - [ | |
138 | - 'parent_id' => 0, | |
139 | - ] | |
140 | - ) | |
141 | - ->andWhere( | |
142 | - [ | |
143 | - '!=', | |
144 | - BlogCategory::tableName() . '_id', | |
145 | - $model->id, | |
146 | - ] | |
147 | - ) | |
148 | - ->all(), | |
133 | + Category::find() | |
134 | + ->joinWith('lang') | |
135 | + ->where( | |
136 | + [ | |
137 | + 'parent_id' => 0, | |
138 | + ] | |
139 | + ) | |
140 | + ->andWhere( | |
141 | + [ | |
142 | + '!=', | |
143 | + Category::tableName() . '_id', | |
144 | + $model->id, | |
145 | + ] | |
146 | + ) | |
147 | + ->all(), | |
149 | 148 | 'id', |
150 | 149 | 'lang.title' |
151 | 150 | ); |
152 | - | |
153 | - if ($model->load(Yii::$app->request->post())) { | |
154 | - $model->loadLangs(\Yii::$app->request); | |
155 | - if ($model->save() && $model->transactionStatus) { | |
156 | - return $this->redirect( | |
157 | - [ | |
158 | - 'view', | |
159 | - 'id' => $model->id, | |
160 | - ] | |
161 | - ); | |
162 | - } | |
151 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
152 | + return $this->redirect( | |
153 | + [ | |
154 | + 'view', | |
155 | + 'id' => $model->id, | |
156 | + ] | |
157 | + ); | |
158 | + | |
163 | 159 | } |
164 | 160 | return $this->render( |
165 | 161 | 'update', |
... | ... | @@ -184,30 +180,62 @@ |
184 | 180 | { |
185 | 181 | $this->findModel($id) |
186 | 182 | ->delete(); |
187 | - | |
183 | + | |
188 | 184 | return $this->redirect([ 'index' ]); |
189 | 185 | } |
190 | 186 | |
191 | - public function actionDeleteImage($id) | |
187 | + public function actionList(string $q = null) | |
192 | 188 | { |
193 | - $model = $this->findModel($id); | |
194 | - $model->image = null; | |
195 | - $model->updateAttributes(['image']); | |
196 | - return true; | |
189 | + \Yii::$app->response->format = Response::FORMAT_JSON; | |
190 | + $out = [ | |
191 | + 'results' => [ | |
192 | + [ | |
193 | + 'id' => '', | |
194 | + 'text' => '', | |
195 | + ], | |
196 | + ], | |
197 | + ]; | |
198 | + if (!is_null($q)) { | |
199 | + $categories = Category::find() | |
200 | + ->joinWith('lang') | |
201 | + ->select( | |
202 | + [ | |
203 | + 'id' => 'blog_category.id', | |
204 | + 'text' => 'blog_category_lang.title', | |
205 | + ] | |
206 | + ) | |
207 | + ->andFilterWhere( | |
208 | + [ | |
209 | + 'like', | |
210 | + 'blog_category_lang.title', | |
211 | + $q, | |
212 | + ] | |
213 | + ) | |
214 | + ->limit(20) | |
215 | + ->asArray() | |
216 | + ->all(); | |
217 | + | |
218 | + if (!empty($categories)) { | |
219 | + $out[ 'results' ] = $categories; | |
220 | + } | |
221 | + } | |
222 | + | |
223 | + return $out; | |
197 | 224 | } |
198 | 225 | |
199 | 226 | /** |
200 | 227 | * Finds the BlogCategory model based on its primary key value. |
201 | 228 | * If the model is not found, a 404 HTTP exception will be thrown. |
229 | + | |
202 | 230 | * |
203 | - * @param integer $id | |
231 | +*@param integer $id | |
204 | 232 | * |
205 | - * @return BlogCategory the loaded model | |
233 | + * @return Category the loaded model | |
206 | 234 | * @throws NotFoundHttpException if the model cannot be found |
207 | 235 | */ |
208 | 236 | protected function findModel($id) |
209 | 237 | { |
210 | - if (( $model = BlogCategory::findOne($id) ) !== NULL) { | |
238 | + if (( $model = Category::findOne($id) ) !== null) { | |
211 | 239 | return $model; |
212 | 240 | } else { |
213 | 241 | throw new NotFoundHttpException('The requested page does not exist.'); | ... | ... |
controllers/TagController.php
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace artbox\weblog\controllers; |
4 | - | |
4 | + | |
5 | + use artbox\weblog\models\Tag; | |
5 | 6 | use artbox\weblog\models\TagSearch; |
6 | 7 | use Yii; |
7 | 8 | use yii\web\Controller; |
8 | 9 | use yii\web\NotFoundHttpException; |
9 | 10 | use yii\filters\VerbFilter; |
10 | - | |
11 | + use yii\web\Response; | |
12 | + | |
11 | 13 | /** |
12 | 14 | * BlogTagController implements the CRUD actions for BlogTag model. |
13 | 15 | */ |
... | ... | @@ -17,7 +19,7 @@ |
17 | 19 | { |
18 | 20 | return '@artbox/weblog/views/blog-tag'; |
19 | 21 | } |
20 | - | |
22 | + | |
21 | 23 | /** |
22 | 24 | * @inheritdoc |
23 | 25 | */ |
... | ... | @@ -32,7 +34,7 @@ |
32 | 34 | ], |
33 | 35 | ]; |
34 | 36 | } |
35 | - | |
37 | + | |
36 | 38 | /** |
37 | 39 | * Lists all BlogTag models. |
38 | 40 | * |
... | ... | @@ -42,7 +44,7 @@ |
42 | 44 | { |
43 | 45 | $searchModel = new TagSearch(); |
44 | 46 | $dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
45 | - | |
47 | + | |
46 | 48 | return $this->render( |
47 | 49 | 'index', |
48 | 50 | [ |
... | ... | @@ -51,7 +53,7 @@ |
51 | 53 | ] |
52 | 54 | ); |
53 | 55 | } |
54 | - | |
56 | + | |
55 | 57 | /** |
56 | 58 | * Displays a single BlogTag model. |
57 | 59 | * |
... | ... | @@ -68,7 +70,7 @@ |
68 | 70 | ] |
69 | 71 | ); |
70 | 72 | } |
71 | - | |
73 | + | |
72 | 74 | /** |
73 | 75 | * Creates a new BlogTag model. |
74 | 76 | * If creation is successful, the browser will be redirected to the 'view' page. |
... | ... | @@ -77,13 +79,12 @@ |
77 | 79 | */ |
78 | 80 | public function actionCreate() |
79 | 81 | { |
80 | - $model = new BlogTag(); | |
82 | + $model = new Tag(); | |
81 | 83 | $model->generateLangs(); |
82 | - | |
84 | + | |
83 | 85 | if (\Yii::$app->request->isPost) { |
84 | 86 | $model->loadLangs(\Yii::$app->request); |
85 | - $model->markAttributeDirty('id'); | |
86 | - if ($model->save() && $model->transactionStatus) { | |
87 | + if ($model->saveWithLangs()) { | |
87 | 88 | return $this->redirect( |
88 | 89 | [ |
89 | 90 | 'view', |
... | ... | @@ -99,9 +100,9 @@ |
99 | 100 | 'modelLangs' => $model->modelLangs, |
100 | 101 | ] |
101 | 102 | ); |
102 | - | |
103 | - } | |
104 | 103 | |
104 | + } | |
105 | + | |
105 | 106 | /** |
106 | 107 | * Updates an existing BlogTag model. |
107 | 108 | * If update is successful, the browser will be redirected to the 'view' page. |
... | ... | @@ -114,11 +115,10 @@ |
114 | 115 | { |
115 | 116 | $model = $this->findModel($id); |
116 | 117 | $model->generateLangs(); |
117 | - | |
118 | + | |
118 | 119 | if (Yii::$app->request->isPost) { |
119 | 120 | $model->loadLangs(\Yii::$app->request); |
120 | - $model->markAttributeDirty('id'); | |
121 | - if ($model->save() && $model->transactionStatus) { | |
121 | + if ($model->saveWithLangs()) { | |
122 | 122 | return $this->redirect( |
123 | 123 | [ |
124 | 124 | 'view', |
... | ... | @@ -134,9 +134,9 @@ |
134 | 134 | 'modelLangs' => $model->modelLangs, |
135 | 135 | ] |
136 | 136 | ); |
137 | - | |
138 | - } | |
139 | 137 | |
138 | + } | |
139 | + | |
140 | 140 | /** |
141 | 141 | * Deletes an existing BlogTag model. |
142 | 142 | * If deletion is successful, the browser will be redirected to the 'index' page. |
... | ... | @@ -149,22 +149,61 @@ |
149 | 149 | { |
150 | 150 | $this->findModel($id) |
151 | 151 | ->delete(); |
152 | - | |
152 | + | |
153 | 153 | return $this->redirect([ 'index' ]); |
154 | 154 | } |
155 | + | |
156 | + public function actionList(string $q = null) | |
157 | + { | |
158 | + \Yii::$app->response->format = Response::FORMAT_JSON; | |
159 | + $out = [ | |
160 | + 'results' => [ | |
161 | + [ | |
162 | + 'id' => '', | |
163 | + 'text' => '', | |
164 | + ], | |
165 | + ], | |
166 | + ]; | |
167 | + if (!is_null($q)) { | |
168 | + $categories = Tag::find() | |
169 | + ->joinWith('lang') | |
170 | + ->select( | |
171 | + [ | |
172 | + 'id' => 'blog_tag.id', | |
173 | + 'text' => 'blog_tag_lang.label', | |
174 | + ] | |
175 | + ) | |
176 | + ->andFilterWhere( | |
177 | + [ | |
178 | + 'like', | |
179 | + 'blog_tag_lang.label', | |
180 | + $q, | |
181 | + ] | |
182 | + ) | |
183 | + ->limit(20) | |
184 | + ->asArray() | |
185 | + ->all(); | |
186 | + | |
187 | + if (!empty($categories)) { | |
188 | + $out[ 'results' ] = $categories; | |
189 | + } | |
190 | + } | |
155 | 191 | |
192 | + return $out; | |
193 | + } | |
194 | + | |
156 | 195 | /** |
157 | 196 | * Finds the BlogTag model based on its primary key value. |
158 | 197 | * If the model is not found, a 404 HTTP exception will be thrown. |
159 | 198 | * |
160 | - * @param integer $id | |
199 | +*@param integer $id | |
161 | 200 | * |
162 | - * @return BlogTag the loaded model | |
201 | + * @return Tag the loaded model | |
163 | 202 | * @throws NotFoundHttpException if the model cannot be found |
164 | 203 | */ |
165 | 204 | protected function findModel($id) |
166 | 205 | { |
167 | - if (( $model = BlogTag::findOne($id) ) !== NULL) { | |
206 | + if (( $model = Tag::findOne($id) ) !== null) { | |
168 | 207 | return $model; |
169 | 208 | } else { |
170 | 209 | throw new NotFoundHttpException('The requested page does not exist.'); | ... | ... |
models/Article.php
... | ... | @@ -2,7 +2,9 @@ |
2 | 2 | |
3 | 3 | namespace artbox\weblog\models; |
4 | 4 | |
5 | + use artbox\catalog\behaviors\ManyToManyBehavior; | |
5 | 6 | use artbox\catalog\models\Product; |
7 | + use artbox\core\models\Image; | |
6 | 8 | use yii\behaviors\TimestampBehavior; |
7 | 9 | use yii\db\ActiveRecord; |
8 | 10 | use artbox\core\behaviors\LanguageBehavior; |
... | ... | @@ -12,31 +14,33 @@ |
12 | 14 | |
13 | 15 | /** |
14 | 16 | * This is the model class for table "blog_article". |
15 | - * | |
16 | -*@property integer $id | |
17 | - * @property string $image | |
18 | - * @property integer $created_at | |
19 | - * @property integer $updated_at | |
20 | - * @property integer $deleted_at | |
21 | - * @property integer $sort | |
22 | - * @property boolean $status | |
23 | - * @property integer $author_id | |
24 | - * @property ArticleLang[] $blogArticleLangs | |
25 | - * @property Language[] $languages | |
26 | - * @property Article[] $relatedBlogArticles | |
27 | - * @property Article[] $blogArticles | |
28 | - * @property BlogCategory[] $blogCategories | |
29 | - * @property BlogCategory $blogCategory | |
30 | - * @property Product[] $products | |
31 | - * @property BlogTag[] $blogTags | |
17 | + | |
18 | +* | |
19 | +*@property integer $id | |
20 | + * @property Image $image | |
21 | + * @property integer $created_at | |
22 | + * @property integer $updated_at | |
23 | + * @property integer $deleted_at | |
24 | + * @property integer $sort | |
25 | + * @property boolean $status | |
26 | + * @property integer $author_id | |
27 | + * @property integer $image_id | |
28 | + * @property ArticleLang[] $blogArticleLangs | |
29 | + * @property Language[] $languages | |
30 | + * @property Article[] $relatedBlogArticles | |
31 | + * @property Article[] $articles | |
32 | + * @property Category[] $categories | |
33 | + * @property Category $category | |
34 | + * @property Product[] $products | |
35 | + * @property Tag[] $tags | |
32 | 36 | * * * From language behavior * |
33 | - * @property ArticleLang $lang | |
34 | - * @property ArticleLang[] $langs | |
35 | - * @property ArticleLang $objectLang | |
36 | - * @property string $ownerKey | |
37 | - * @property string $langKey | |
38 | - * @property ArticleLang[] $modelLangs | |
39 | - * @property bool $transactionStatus | |
37 | + * @property ArticleLang $lang | |
38 | + * @property ArticleLang[] $langs | |
39 | + * @property ArticleLang $objectLang | |
40 | + * @property string $ownerKey | |
41 | + * @property string $langKey | |
42 | + * @property ArticleLang[] $modelLangs | |
43 | + * @property bool $transactionStatus | |
40 | 44 | * @method string getOwnerKey() |
41 | 45 | * @method void setOwnerKey( string $value ) |
42 | 46 | * @method string getLangKey() |
... | ... | @@ -48,16 +52,19 @@ |
48 | 52 | * @method bool linkLangs() |
49 | 53 | * @method bool saveLangs() |
50 | 54 | * @method bool getTransactionStatus() |
55 | + * @method bool loadWithLangs( Request $request ) | |
56 | + * @method bool saveWithLangs() | |
51 | 57 | * * End language behavior * |
52 | - * * From SaveImgBehavior | |
53 | - * @property string|null $imageFile | |
54 | - * @property string|null $imageUrl | |
55 | - * @method string|null getImageFile( int $field ) | |
56 | - * @method string|null getImageUrl( int $field ) | |
57 | - * * End SaveImgBehavior | |
58 | + * @method void linkMany( string $link, array $models ) | |
58 | 59 | */ |
59 | 60 | class Article extends ActiveRecord |
60 | 61 | { |
62 | + public $categoryIds = []; | |
63 | + | |
64 | + public $tagIds = []; | |
65 | + | |
66 | + public $articleIds = []; | |
67 | + | |
61 | 68 | /** |
62 | 69 | * @inheritdoc |
63 | 70 | */ |
... | ... | @@ -75,6 +82,9 @@ |
75 | 82 | 'language' => [ |
76 | 83 | 'class' => LanguageBehavior::className(), |
77 | 84 | ], |
85 | + [ | |
86 | + 'class' => ManyToManyBehavior::className(), | |
87 | + ], | |
78 | 88 | ]; |
79 | 89 | } |
80 | 90 | /** |
... | ... | @@ -130,6 +140,14 @@ |
130 | 140 | /** |
131 | 141 | * @return \yii\db\ActiveQuery |
132 | 142 | */ |
143 | + public function getImage() | |
144 | + { | |
145 | + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); | |
146 | + } | |
147 | + | |
148 | + /** | |
149 | + * @return \yii\db\ActiveQuery | |
150 | + */ | |
133 | 151 | public function getArticles() |
134 | 152 | { |
135 | 153 | return $this->hasMany(Article::className(), [ 'id' => 'blog_article_id' ]) |
... | ... | @@ -139,19 +157,19 @@ |
139 | 157 | /** |
140 | 158 | * @return \yii\db\ActiveQuery |
141 | 159 | */ |
142 | - public function getBlogCategories() | |
160 | + public function getCategories() | |
143 | 161 | { |
144 | - return $this->hasMany(BlogCategory::className(), [ 'id' => 'blog_category_id' ]) | |
162 | + return $this->hasMany(Category::className(), [ 'id' => 'blog_category_id' ]) | |
145 | 163 | ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); |
146 | 164 | } |
147 | 165 | |
148 | 166 | /** |
149 | 167 | * @return \yii\db\ActiveQuery |
150 | 168 | */ |
151 | - public function getBlogCategory() | |
169 | + public function getCategory() | |
152 | 170 | { |
153 | - return $this->hasOne(BlogCategory::className(), [ 'id' => 'blog_category_id' ]) | |
154 | - ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); | |
171 | + return $this->hasOne(Category::className(), [ 'id' => 'blog_category_id' ]) | |
172 | + ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); | |
155 | 173 | } |
156 | 174 | |
157 | 175 | /** |
... | ... | @@ -160,15 +178,15 @@ |
160 | 178 | public function getProducts() |
161 | 179 | { |
162 | 180 | return $this->hasMany(Product::className(), [ 'id' => 'product_id' ]) |
163 | - ->viaTable('blog_article_to_product', [ 'blog_article_id' => 'id' ]); | |
181 | + ->viaTable('blog_article_to_product', [ 'blog_article_id' => 'id' ]); | |
164 | 182 | } |
165 | 183 | |
166 | 184 | /** |
167 | 185 | * @return \yii\db\ActiveQuery |
168 | 186 | */ |
169 | - public function getBlogTags() | |
187 | + public function getTags() | |
170 | 188 | { |
171 | - return $this->hasMany(BlogTag::className(), [ 'id' => 'blog_tag_id' ]) | |
172 | - ->viaTable('blog_article_to_tag', [ 'blog_article_id' => 'id' ]); | |
189 | + return $this->hasMany(Tag::className(), [ 'id' => 'blog_tag_id' ]) | |
190 | + ->viaTable('blog_article_to_tag', [ 'blog_article_id' => 'id' ]); | |
173 | 191 | } |
174 | 192 | } | ... | ... |
models/Category.php
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace artbox\weblog\models; |
4 | - | |
4 | + | |
5 | + use artbox\core\models\Image; | |
5 | 6 | use yii\db\ActiveRecord; |
6 | 7 | use artbox\core\behaviors\LanguageBehavior; |
7 | 8 | use artbox\core\models\Language; |
8 | 9 | use yii\db\ActiveQuery; |
9 | 10 | use yii\web\Request; |
10 | - | |
11 | + | |
11 | 12 | /** |
12 | 13 | * This is the model class for table "blog_category". |
13 | - | |
14 | -* | |
15 | -*@property integer $id | |
16 | - * @property integer $sort | |
17 | - * @property string $image | |
18 | - * @property integer $parent_id | |
19 | - * @property boolean $status | |
20 | - * @property Article[] $blogArticles | |
21 | - * @property BlogCategoryLang[] $blogCategoryLangs | |
22 | - * @property Language[] $languages | |
23 | - * @property BlogCategory $parent | |
14 | + * | |
15 | + * @property integer $id | |
16 | + * @property integer $sort | |
17 | + * @property integer $parent_id | |
18 | + * @property boolean $status | |
19 | + * @property Article[] $articles | |
20 | + * @property CategoryLang[] $blogCategoryLangs | |
21 | + * @property Language[] $languages | |
22 | + * @property Category $parent | |
23 | + * @property Image $image | |
24 | + * @property integer $image_id | |
24 | 25 | * * 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 | |
26 | + * @property CategoryLang $lang | |
27 | + * @property CategoryLang[] $langs | |
28 | + * @property CategoryLang $objectLang | |
29 | + * @property string $ownerKey | |
30 | + * @property string $langKey | |
31 | + * @property CategoryLang[] $modelLangs | |
32 | + * @property bool $transactionStatus | |
32 | 33 | * @method string getOwnerKey() |
33 | 34 | * @method void setOwnerKey( string $value ) |
34 | 35 | * @method string getLangKey() |
35 | 36 | * @method void setLangKey( string $value ) |
36 | 37 | * @method ActiveQuery getLangs() |
37 | 38 | * @method ActiveQuery getLang( integer $language_id ) |
38 | - * @method BlogCategoryLang[] generateLangs() | |
39 | + * @method CategoryLang[] generateLangs() | |
39 | 40 | * @method void loadLangs( Request $request ) |
40 | 41 | * @method bool linkLangs() |
41 | 42 | * @method bool saveLangs() |
42 | 43 | * @method bool getTransactionStatus() |
44 | + * @method bool loadWithLangs( Request $request ) | |
45 | + * @method bool saveWithLangs() | |
43 | 46 | * * End language behavior * |
44 | 47 | * * From SaveImgBehavior * |
45 | - * @property string|null $imageFile | |
46 | - * @property string|null $imageUrl | |
48 | + * @property string|null $imageFile | |
49 | + * @property string|null $imageUrl | |
47 | 50 | * @method string|null getImageFile( int $field ) |
48 | 51 | * @method string|null getImageUrl( int $field ) |
49 | 52 | * * End SaveImgBehavior |
... | ... | @@ -57,7 +60,7 @@ |
57 | 60 | { |
58 | 61 | return 'blog_category'; |
59 | 62 | } |
60 | - | |
63 | + | |
61 | 64 | /** |
62 | 65 | * @inheritdoc |
63 | 66 | */ |
... | ... | @@ -69,7 +72,7 @@ |
69 | 72 | ], |
70 | 73 | ]; |
71 | 74 | } |
72 | - | |
75 | + | |
73 | 76 | /** |
74 | 77 | * @inheritdoc |
75 | 78 | */ |
... | ... | @@ -80,6 +83,7 @@ |
80 | 83 | [ |
81 | 84 | 'sort', |
82 | 85 | 'parent_id', |
86 | + 'image_id', | |
83 | 87 | ], |
84 | 88 | 'integer', |
85 | 89 | ], |
... | ... | @@ -88,18 +92,13 @@ |
88 | 92 | 'boolean', |
89 | 93 | ], |
90 | 94 | [ |
91 | - [ 'image' ], | |
92 | - 'string', | |
93 | - 'max' => 255, | |
94 | - ], | |
95 | - [ | |
96 | 95 | [ 'parent_id' ], |
97 | 96 | 'default', |
98 | 97 | 'value' => 0, |
99 | 98 | ], |
100 | 99 | ]; |
101 | 100 | } |
102 | - | |
101 | + | |
103 | 102 | /** |
104 | 103 | * @inheritdoc |
105 | 104 | */ |
... | ... | @@ -113,18 +112,29 @@ |
113 | 112 | 'status' => 'Status', |
114 | 113 | ]; |
115 | 114 | } |
116 | - | |
115 | + | |
117 | 116 | /** |
118 | 117 | * @return \yii\db\ActiveQuery |
119 | 118 | */ |
120 | - public function getBlogArticles() | |
119 | + public function getArticles() | |
121 | 120 | { |
122 | - return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ]) | |
121 | + return $this->hasMany(Article::className(), [ 'id' => 'blog_article_id' ]) | |
123 | 122 | ->viaTable('blog_article_to_category', [ 'blog_category_id' => 'id' ]); |
124 | 123 | } |
125 | - | |
124 | + | |
125 | + /** | |
126 | + * @return \yii\db\ActiveQuery | |
127 | + */ | |
126 | 128 | public function getParent() |
127 | 129 | { |
128 | - return $this->hasOne(BlogCategory::className(), [ 'id' => 'parent_id' ]); | |
130 | + return $this->hasOne(Category::className(), [ 'id' => 'parent_id' ]); | |
131 | + } | |
132 | + | |
133 | + /** | |
134 | + * @return \yii\db\ActiveQuery | |
135 | + */ | |
136 | + public function getImage() | |
137 | + { | |
138 | + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); | |
129 | 139 | } |
130 | 140 | } | ... | ... |
models/CategoryLang.php
... | ... | @@ -8,19 +8,13 @@ |
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This is the model class for table "blog_category_lang". |
11 | - | |
12 | -* | |
11 | + * | |
13 | 12 | * @property integer $id |
14 | 13 | * @property integer $blog_category_id |
15 | 14 | * @property integer $language_id |
16 | 15 | * @property string $title |
17 | - * @property string $alias | |
18 | 16 | * @property string $description |
19 | - * @property string $meta_title | |
20 | - * @property string $meta_description | |
21 | - * @property string $h1 | |
22 | - * @property string $seo_text | |
23 | - * @property Category $blogCategory | |
17 | + * @property Category $category | |
24 | 18 | * @property Language $language |
25 | 19 | */ |
26 | 20 | class CategoryLang extends ActiveRecord |
... | ... | @@ -59,6 +53,7 @@ |
59 | 53 | [ |
60 | 54 | 'blog_category_id', |
61 | 55 | 'language_id', |
56 | + 'title', | |
62 | 57 | ], |
63 | 58 | 'required', |
64 | 59 | ], |
... | ... | @@ -76,20 +71,11 @@ |
76 | 71 | [ |
77 | 72 | [ |
78 | 73 | 'title', |
79 | - 'alias', | |
80 | - 'meta_title', | |
81 | - 'meta_description', | |
82 | - 'h1', | |
83 | - 'seo_text', | |
84 | 74 | ], |
85 | 75 | 'string', |
86 | 76 | 'max' => 255, |
87 | 77 | ], |
88 | 78 | [ |
89 | - [ 'alias' ], | |
90 | - 'unique', | |
91 | - ], | |
92 | - [ | |
93 | 79 | [ |
94 | 80 | 'blog_category_id', |
95 | 81 | 'language_id', |
... | ... | @@ -105,7 +91,7 @@ |
105 | 91 | [ 'blog_category_id' ], |
106 | 92 | 'exist', |
107 | 93 | 'skipOnError' => true, |
108 | - 'targetClass' => BlogCategory::className(), | |
94 | + 'targetClass' => Category::className(), | |
109 | 95 | 'targetAttribute' => [ 'blog_category_id' => 'id' ], |
110 | 96 | ], |
111 | 97 | [ |
... | ... | @@ -140,9 +126,9 @@ |
140 | 126 | /** |
141 | 127 | * @return \yii\db\ActiveQuery |
142 | 128 | */ |
143 | - public function getBlogCategory() | |
129 | + public function getCategory() | |
144 | 130 | { |
145 | - return $this->hasOne(BlogCategory::className(), [ 'id' => 'blog_category_id' ]); | |
131 | + return $this->hasOne(Category::className(), [ 'id' => 'blog_category_id' ]); | |
146 | 132 | } |
147 | 133 | |
148 | 134 | /** | ... | ... |
models/Tag.php
... | ... | @@ -10,31 +10,32 @@ |
10 | 10 | |
11 | 11 | /** |
12 | 12 | * This is the model class for table "blog_tag". |
13 | - | |
14 | -* | |
15 | -*@property integer $id | |
16 | - * @property Article[] $blogArticles | |
17 | - * @property BlogTagLang[] $blogTagLangs | |
18 | - * @property Language[] $languages | |
13 | + * | |
14 | + * @property integer $id | |
15 | + * @property Article[] $articles | |
16 | + * @property TagLang[] $blogTagLangs | |
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 TagLang $lang | |
20 | + * @property TagLang[] $langs | |
21 | + * @property TagLang $objectLang | |
22 | + * @property string $ownerKey | |
23 | + * @property string $langKey | |
24 | + * @property TagLang[] $modelLangs | |
25 | + * @property bool $transactionStatus | |
27 | 26 | * @method string getOwnerKey() |
28 | 27 | * @method void setOwnerKey( string $value ) |
29 | 28 | * @method string getLangKey() |
30 | 29 | * @method void setLangKey( string $value ) |
31 | 30 | * @method ActiveQuery getLangs() |
32 | 31 | * @method ActiveQuery getLang( integer $language_id ) |
33 | - * @method BlogTagLang[] generateLangs() | |
32 | + * @method TagLang[] generateLangs() | |
34 | 33 | * @method void loadLangs( Request $request ) |
35 | 34 | * @method bool linkLangs() |
36 | 35 | * @method bool saveLangs() |
37 | 36 | * @method bool getTransactionStatus() |
37 | + * @method bool saveWithLangs() | |
38 | + * @method bool loadWithLangs( Request $request ) | |
38 | 39 | * * End language behavior * |
39 | 40 | */ |
40 | 41 | class Tag extends ActiveRecord |
... | ... | @@ -85,7 +86,7 @@ |
85 | 86 | /** |
86 | 87 | * @return \yii\db\ActiveQuery |
87 | 88 | */ |
88 | - public function getBlogArticles() | |
89 | + public function getArticles() | |
89 | 90 | { |
90 | 91 | return $this->hasMany(Article::className(), [ 'id' => 'blog_article_id' ]) |
91 | 92 | ->viaTable('blog_article_to_tag', [ 'blog_tag_id' => 'id' ]); | ... | ... |
models/TagLang.php
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace artbox\weblog\models; |
4 | - | |
4 | + | |
5 | + use artbox\core\behaviors\SlugBehavior; | |
5 | 6 | use artbox\core\models\Language; |
6 | 7 | use yii\db\ActiveRecord; |
7 | - | |
8 | + | |
8 | 9 | /** |
9 | 10 | * This is the model class for table "blog_tag_lang". |
10 | - | |
11 | -* | |
12 | -*@property integer $id | |
11 | + * | |
12 | + * @property integer $id | |
13 | 13 | * @property integer $blog_tag_id |
14 | 14 | * @property integer $language_id |
15 | 15 | * @property string $label |
... | ... | @@ -18,6 +18,7 @@ |
18 | 18 | */ |
19 | 19 | class TagLang extends ActiveRecord |
20 | 20 | { |
21 | + | |
21 | 22 | /** |
22 | 23 | * @inheritdoc |
23 | 24 | */ |
... | ... | @@ -25,7 +26,27 @@ |
25 | 26 | { |
26 | 27 | return 'blog_tag_lang'; |
27 | 28 | } |
28 | - | |
29 | + | |
30 | + /** | |
31 | + * @inheritdoc | |
32 | + */ | |
33 | + public function behaviors() | |
34 | + { | |
35 | + return [ | |
36 | + 'slug' => [ | |
37 | + 'class' => SlugBehavior::className(), | |
38 | + 'action' => 'tag/view', | |
39 | + 'params' => [ | |
40 | + 'id' => 'blog_tag_id', | |
41 | + ], | |
42 | + 'fields' => [ | |
43 | + 'label' => \Yii::t('blog', 'Tag label'), | |
44 | + ], | |
45 | + 'inAttribute' => 'label', | |
46 | + ], | |
47 | + ]; | |
48 | + } | |
49 | + | |
29 | 50 | /** |
30 | 51 | * @inheritdoc |
31 | 52 | */ |
... | ... | @@ -79,7 +100,7 @@ |
79 | 100 | ], |
80 | 101 | ]; |
81 | 102 | } |
82 | - | |
103 | + | |
83 | 104 | /** |
84 | 105 | * @inheritdoc |
85 | 106 | */ |
... | ... | @@ -92,15 +113,15 @@ |
92 | 113 | 'label' => 'Label', |
93 | 114 | ]; |
94 | 115 | } |
95 | - | |
116 | + | |
96 | 117 | /** |
97 | 118 | * @return \yii\db\ActiveQuery |
98 | 119 | */ |
99 | - public function getBlogTag() | |
120 | + public function getTag() | |
100 | 121 | { |
101 | 122 | return $this->hasOne(Tag::className(), [ 'id' => 'blog_tag_id' ]); |
102 | 123 | } |
103 | - | |
124 | + | |
104 | 125 | /** |
105 | 126 | * @return \yii\db\ActiveQuery |
106 | 127 | */ | ... | ... |
views/blog-article/_form.php
... | ... | @@ -2,9 +2,8 @@ |
2 | 2 | |
3 | 3 | use artbox\weblog\models\Article; |
4 | 4 | use artbox\weblog\models\ArticleLang; |
5 | - | |
6 | - // use artweb\artbox\blog\models\BlogCategory; | |
7 | - // use artweb\artbox\blog\models\BlogTag; | |
5 | + use artbox\weblog\models\Category; | |
6 | + use artbox\weblog\models\Tag; | |
8 | 7 | use kartik\select2\Select2; |
9 | 8 | use noam148\imagemanager\components\ImageManagerInputWidget; |
10 | 9 | use yii\helpers\Html; |
... | ... | @@ -15,14 +14,14 @@ |
15 | 14 | use yii\web\JsExpression; |
16 | 15 | |
17 | 16 | /** |
18 | - * @var View $this | |
19 | - * @var Article $model | |
20 | - * @var ActiveForm $form | |
21 | - * @var ArticleLang[] $modelLangs | |
22 | - * @var BlogCategory[] $categories | |
23 | - * @var BlogTag[] $tags | |
24 | - * @var array $products | |
25 | - * @var array $articles | |
17 | + * @var View $this | |
18 | + * @var Article $model | |
19 | + * @var ActiveForm $form | |
20 | + * @var ArticleLang[] $modelLangs | |
21 | + * @var Category[] $categories | |
22 | + * @var Tag[] $tags | |
23 | + * @var array $products | |
24 | + * @var array $articles | |
26 | 25 | */ |
27 | 26 | ?> |
28 | 27 | |
... | ... | @@ -43,42 +42,110 @@ |
43 | 42 | ] |
44 | 43 | ); |
45 | 44 | ?> |
46 | - | |
47 | - <?php | |
48 | - // echo $form->field($model, 'blogCategories') | |
49 | - // ->widget( | |
50 | - // Select2::className(), | |
51 | - // [ | |
52 | - // 'data' => $categories, | |
53 | - // 'theme' => Select2::THEME_BOOTSTRAP, | |
54 | - // 'options' => [ | |
55 | - // 'placeholder' => \Yii::t('blog', 'Select category'), | |
56 | - // 'multiple' => true, | |
57 | - // ], | |
58 | - // 'pluginOptions' => [ | |
59 | - // 'allowClear' => true, | |
60 | - // ], | |
61 | - // ] | |
62 | - // ); | |
63 | - ?> | |
64 | - | |
65 | - <?php | |
66 | - // echo $form->field($model, 'blogTags') | |
67 | - // ->widget( | |
68 | - // Select2::className(), | |
69 | - // [ | |
70 | - // 'data' => $tags, | |
71 | - // 'theme' => Select2::THEME_BOOTSTRAP, | |
72 | - // 'options' => [ | |
73 | - // 'placeholder' => \Yii::t('blog', 'Select tag'), | |
74 | - // 'multiple' => true, | |
75 | - // ], | |
76 | - // 'pluginOptions' => [ | |
77 | - // 'allowClear' => true, | |
78 | - // ], | |
79 | - // ] | |
80 | - // ); | |
81 | - ?> | |
45 | + | |
46 | + <div class="form-group"> | |
47 | + <label class="control-label"><?= \Yii::t('blog', 'Categories'); ?></label> | |
48 | + <?php | |
49 | + echo Select2::widget( | |
50 | + [ | |
51 | + 'name' => 'categoryIds', | |
52 | + 'options' => [ | |
53 | + 'placeholder' => \Yii::t('blog', 'Search for a categories ...'), | |
54 | + 'multiple' => true, | |
55 | + ], | |
56 | + 'value' => array_keys($model->categoryIds), | |
57 | + 'data' => $model->categoryIds, | |
58 | + 'pluginOptions' => [ | |
59 | + 'allowClear' => true, | |
60 | + 'minimumInputLength' => 3, | |
61 | + 'language' => [ | |
62 | + 'errorLoading' => new JsExpression( | |
63 | + "function () { return 'Waiting for results...'; }" | |
64 | + ), | |
65 | + ], | |
66 | + 'ajax' => [ | |
67 | + 'url' => Url::to([ '/blog-category/list' ]), | |
68 | + 'dataType' => 'json', | |
69 | + 'data' => new JsExpression( | |
70 | + 'function(params) { | |
71 | + return { | |
72 | + q:params.term | |
73 | + }; | |
74 | + }' | |
75 | + ), | |
76 | + ], | |
77 | + 'escapeMarkup' => new JsExpression( | |
78 | + 'function (markup) { | |
79 | + return markup; | |
80 | + }' | |
81 | + ), | |
82 | + 'templateResult' => new JsExpression( | |
83 | + 'function (brand) { | |
84 | + return brand.text; | |
85 | + }' | |
86 | + ), | |
87 | + 'templateSelection' => new JsExpression( | |
88 | + 'function (brand) { | |
89 | + return brand.text; | |
90 | + }' | |
91 | + ), | |
92 | + ], | |
93 | + ] | |
94 | + ); | |
95 | + ?> | |
96 | + </div> | |
97 | + | |
98 | + <div class="form-group"> | |
99 | + <label class="control-label"><?= \Yii::t('blog', 'Tags'); ?></label> | |
100 | + <?php | |
101 | + echo Select2::widget( | |
102 | + [ | |
103 | + 'name' => 'tagIds', | |
104 | + 'options' => [ | |
105 | + 'placeholder' => \Yii::t('blog', 'Search for a tags ...'), | |
106 | + 'multiple' => true, | |
107 | + ], | |
108 | + 'value' => array_keys($model->tagIds), | |
109 | + 'data' => $model->tagIds, | |
110 | + 'pluginOptions' => [ | |
111 | + 'allowClear' => true, | |
112 | + 'minimumInputLength' => 3, | |
113 | + 'language' => [ | |
114 | + 'errorLoading' => new JsExpression( | |
115 | + "function () { return 'Waiting for results...'; }" | |
116 | + ), | |
117 | + ], | |
118 | + 'ajax' => [ | |
119 | + 'url' => Url::to([ '/blog-tag/list' ]), | |
120 | + 'dataType' => 'json', | |
121 | + 'data' => new JsExpression( | |
122 | + 'function(params) { | |
123 | + return { | |
124 | + q:params.term | |
125 | + }; | |
126 | + }' | |
127 | + ), | |
128 | + ], | |
129 | + 'escapeMarkup' => new JsExpression( | |
130 | + 'function (markup) { | |
131 | + return markup; | |
132 | + }' | |
133 | + ), | |
134 | + 'templateResult' => new JsExpression( | |
135 | + 'function (brand) { | |
136 | + return brand.text; | |
137 | + }' | |
138 | + ), | |
139 | + 'templateSelection' => new JsExpression( | |
140 | + 'function (brand) { | |
141 | + return brand.text; | |
142 | + }' | |
143 | + ), | |
144 | + ], | |
145 | + ] | |
146 | + ); | |
147 | + ?> | |
148 | + </div> | |
82 | 149 | |
83 | 150 | <?= $form->field($model, 'image_id') |
84 | 151 | ->widget( |
... | ... | @@ -92,73 +159,63 @@ |
92 | 159 | //on true show warning before detach image |
93 | 160 | ] |
94 | 161 | ); ?> |
95 | - | |
96 | - <?php | |
97 | - // echo $form->field($model, 'products') | |
98 | - // ->widget( | |
99 | - // Select2::className(), | |
100 | - // [ | |
101 | - // 'data' => $products, | |
102 | - // 'options' => [ | |
103 | - // 'placeholder' => \Yii::t('blog', 'Select related products'), | |
104 | - // 'multiple' => true, | |
105 | - // ], | |
106 | - // 'pluginOptions' => [ | |
107 | - // 'allowClear' => true, | |
108 | - // 'minimumInputLength' => 3, | |
109 | - // 'language' => [ | |
110 | - // 'errorLoading' => new JsExpression( | |
111 | - // "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }" | |
112 | - // ), | |
113 | - // ], | |
114 | - // 'ajax' => [ | |
115 | - // 'url' => yii\helpers\Url::to([ '/blog/blog-article/product-list' ]), | |
116 | - // 'dataType' => 'json', | |
117 | - // 'data' => new JsExpression('function(params) { return {q:params.term}; }'), | |
118 | - // ], | |
119 | - // 'templateResult' => new JsExpression('function(product) { return product.text; }'), | |
120 | - // 'templateSelection' => new JsExpression('function (product) { return product.text; }'), | |
121 | - // ], | |
122 | - // ] | |
123 | - // ); | |
124 | - ?> | |
125 | - | |
126 | - <?php | |
127 | - // if (empty( $model->id )) { | |
128 | - // $data = 'function(params) { return {q:params.term}; }'; | |
129 | - // } else { | |
130 | - // $data = 'function(params) { return {q:params.term, id:' . $model->id . '}; }'; | |
131 | - // } | |
132 | - // echo $form->field($model, 'blogArticles') | |
133 | - // ->widget( | |
134 | - // Select2::className(), | |
135 | - // [ | |
136 | - // 'data' => $articles, | |
137 | - // 'options' => [ | |
138 | - // 'placeholder' => \Yii::t('blog', 'Select related articles'), | |
139 | - // 'multiple' => true, | |
140 | - // ], | |
141 | - // 'pluginOptions' => [ | |
142 | - // 'allowClear' => true, | |
143 | - // 'minimumInputLength' => 3, | |
144 | - // 'language' => [ | |
145 | - // 'errorLoading' => new JsExpression( | |
146 | - // "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }" | |
147 | - // ), | |
148 | - // ], | |
149 | - // 'ajax' => [ | |
150 | - // 'url' => yii\helpers\Url::to([ '/blog/blog-article/article-list' ]), | |
151 | - // 'dataType' => 'json', | |
152 | - // 'data' => new JsExpression( | |
153 | - // $data | |
154 | - // ), | |
155 | - // ], | |
156 | - // 'templateResult' => new JsExpression('function(article) { return article.text; }'), | |
157 | - // 'templateSelection' => new JsExpression('function (article) { return article.text; }'), | |
158 | - // ], | |
159 | - // ] | |
160 | - // ); | |
161 | - ?> | |
162 | + | |
163 | + <div class="form-group"> | |
164 | + <label class="control-label"><?= \Yii::t('blog', 'Articles'); ?></label> | |
165 | + <?php | |
166 | + if ($model->isNewRecord) { | |
167 | + $condition = ''; | |
168 | + } else { | |
169 | + $condition = ', id: ' . $model->id; | |
170 | + } | |
171 | + echo Select2::widget( | |
172 | + [ | |
173 | + 'name' => 'articleIds', | |
174 | + 'options' => [ | |
175 | + 'placeholder' => \Yii::t('blog', 'Search for an articles ...'), | |
176 | + 'multiple' => true, | |
177 | + ], | |
178 | + 'value' => array_keys($model->articleIds), | |
179 | + 'data' => $model->articleIds, | |
180 | + 'pluginOptions' => [ | |
181 | + 'allowClear' => true, | |
182 | + 'minimumInputLength' => 3, | |
183 | + 'language' => [ | |
184 | + 'errorLoading' => new JsExpression( | |
185 | + "function () { return 'Waiting for results...'; }" | |
186 | + ), | |
187 | + ], | |
188 | + 'ajax' => [ | |
189 | + 'url' => Url::to([ '/blog-article/list' ]), | |
190 | + 'dataType' => 'json', | |
191 | + 'data' => new JsExpression( | |
192 | + 'function(params) { | |
193 | + return { | |
194 | + q:params.term' . $condition . ' | |
195 | + }; | |
196 | + }' | |
197 | + ), | |
198 | + ], | |
199 | + 'escapeMarkup' => new JsExpression( | |
200 | + 'function (markup) { | |
201 | + return markup; | |
202 | + }' | |
203 | + ), | |
204 | + 'templateResult' => new JsExpression( | |
205 | + 'function (brand) { | |
206 | + return brand.text; | |
207 | + }' | |
208 | + ), | |
209 | + 'templateSelection' => new JsExpression( | |
210 | + 'function (brand) { | |
211 | + return brand.text; | |
212 | + }' | |
213 | + ), | |
214 | + ], | |
215 | + ] | |
216 | + ); | |
217 | + ?> | |
218 | + </div> | |
162 | 219 | |
163 | 220 | <?= $form->field($model, 'sort') |
164 | 221 | ->textInput() ?> |
... | ... | @@ -172,13 +229,13 @@ |
172 | 229 | |
173 | 230 | <?= $form->field($model, 'author_id') |
174 | 231 | ->textInput() ?> |
175 | - | |
176 | - <div class="form-group"> | |
177 | - <?= Html::submitButton( | |
178 | - $model->isNewRecord ? 'Create' : 'Update', | |
179 | - [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
180 | - ) ?> | |
181 | - </div> | |
232 | + | |
233 | + <div class="form-group"> | |
234 | + <?= Html::submitButton( | |
235 | + $model->isNewRecord ? 'Create' : 'Update', | |
236 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
237 | + ) ?> | |
238 | + </div> | |
182 | 239 | |
183 | 240 | <?php ActiveForm::end(); ?> |
184 | 241 | ... | ... |
views/blog-article/create.php
views/blog-article/index.php
... | ... | @@ -41,13 +41,24 @@ |
41 | 41 | 'attribute' => 'title', |
42 | 42 | 'value' => 'lang.title', |
43 | 43 | ], |
44 | - 'imageUrl:image', | |
44 | + [ | |
45 | + 'attribute' => 'image_id', | |
46 | + 'value' => function (Article $model) { | |
47 | + if (empty($model->image_id)) { | |
48 | + return ''; | |
49 | + } else { | |
50 | + return $model->image->getImg( | |
51 | + [ | |
52 | + 'width' => '300px', | |
53 | + ] | |
54 | + ); | |
55 | + } | |
56 | + }, | |
57 | + 'format' => 'html', | |
58 | + ], | |
45 | 59 | [ |
46 | 60 | 'attribute' => 'status', |
47 | - 'value' => function ($model) { | |
48 | - /** | |
49 | - * @var Article $model | |
50 | - */ | |
61 | + 'value' => function (Article $model) { | |
51 | 62 | return ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'); |
52 | 63 | }, |
53 | 64 | 'filter' => [ |
... | ... | @@ -63,5 +74,5 @@ |
63 | 74 | ); ?> |
64 | 75 | |
65 | 76 | <?php $panel::end(); ?> |
66 | - | |
77 | + | |
67 | 78 | </div> | ... | ... |
views/blog-article/update.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogArticle; | |
4 | - use artweb\artbox\blog\models\BlogArticleLang; | |
5 | - use artweb\artbox\blog\models\BlogCategory; | |
6 | - use artweb\artbox\blog\models\BlogTag; | |
7 | - use yii\helpers\Html; | |
3 | + use artbox\weblog\models\Article; | |
4 | + use artbox\weblog\models\ArticleLang; | |
8 | 5 | use yii\web\View; |
6 | + use yiister\gentelella\widgets\Panel; | |
9 | 7 | |
10 | 8 | /** |
11 | - * @var View $this | |
12 | - * @var BlogArticle $model | |
13 | - * @var BlogArticleLang[] $modelLangs | |
14 | - * @var BlogCategory[] $categories | |
15 | - * @var BlogTag[] $tags | |
16 | - * @var array $products | |
17 | - * @var array $articles | |
9 | + * @var View $this | |
10 | + * @var Article $model | |
11 | + * @var ArticleLang[] $modelLangs | |
18 | 12 | */ |
19 | 13 | |
20 | 14 | $this->title = \Yii::t('blog', 'Update Blog Article: ') . $model->lang->title; |
... | ... | @@ -33,18 +27,20 @@ |
33 | 27 | ?> |
34 | 28 | <div class="blog-article-update"> |
35 | 29 | |
36 | - <h1><?= Html::encode($this->title) ?></h1> | |
30 | + <?php $panel = Panel::begin( | |
31 | + [ | |
32 | + 'header' => $this->title, | |
33 | + ] | |
34 | + ); ?> | |
37 | 35 | |
38 | 36 | <?= $this->render( |
39 | 37 | '_form', |
40 | 38 | [ |
41 | 39 | 'model' => $model, |
42 | 40 | 'modelLangs' => $modelLangs, |
43 | - 'categories' => $categories, | |
44 | - 'tags' => $tags, | |
45 | - 'products' => $products, | |
46 | - 'articles' => $articles, | |
47 | 41 | ] |
48 | 42 | ) ?> |
43 | + | |
44 | + <?php $panel::end(); ?> | |
49 | 45 | |
50 | 46 | </div> | ... | ... |
views/blog-article/view.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogArticle; | |
3 | + use artbox\weblog\models\Article; | |
4 | 4 | use yii\helpers\Html; |
5 | 5 | use yii\web\View; |
6 | 6 | use yii\widgets\DetailView; |
7 | + use yiister\gentelella\widgets\Panel; | |
7 | 8 | |
8 | 9 | /** |
9 | - * @var View $this | |
10 | - * @var BlogArticle $model | |
10 | + * @var View $this | |
11 | + * @var Article $model | |
11 | 12 | */ |
12 | 13 | |
13 | 14 | $this->title = $model->lang->title; |
... | ... | @@ -19,49 +20,68 @@ |
19 | 20 | ?> |
20 | 21 | <div class="blog-article-view"> |
21 | 22 | |
22 | - <h1><?= Html::encode($this->title) ?></h1> | |
23 | - | |
24 | - <p> | |
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, | |
38 | - ], | |
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 | - ) ?> | |
47 | - </p> | |
23 | + <?php $panel = Panel::begin( | |
24 | + [ | |
25 | + 'header' => $this->title, | |
26 | + ] | |
27 | + ); ?> | |
28 | + | |
29 | + <p> | |
30 | + <?= Html::a( | |
31 | + 'Update', | |
32 | + [ | |
33 | + 'update', | |
34 | + 'id' => $model->id, | |
35 | + ], | |
36 | + [ 'class' => 'btn btn-primary' ] | |
37 | + ) ?> | |
38 | + <?= Html::a( | |
39 | + 'Delete', | |
40 | + [ | |
41 | + 'delete', | |
42 | + 'id' => $model->id, | |
43 | + ], | |
44 | + [ | |
45 | + 'class' => 'btn btn-danger', | |
46 | + 'data' => [ | |
47 | + 'confirm' => 'Are you sure you want to delete this item?', | |
48 | + 'method' => 'post', | |
49 | + ], | |
50 | + ] | |
51 | + ) ?> | |
52 | + </p> | |
48 | 53 | |
49 | 54 | <?= DetailView::widget( |
50 | 55 | [ |
51 | 56 | 'model' => $model, |
52 | 57 | 'attributes' => [ |
53 | 58 | 'id', |
54 | - 'imageUrl:image', | |
59 | + [ | |
60 | + 'attribute' => 'image_id', | |
61 | + 'value' => function (Article $model) { | |
62 | + if (empty($model->image_id)) { | |
63 | + return ''; | |
64 | + } else { | |
65 | + return $model->image->getImg( | |
66 | + [ | |
67 | + 'width' => '500px', | |
68 | + ] | |
69 | + ); | |
70 | + } | |
71 | + }, | |
72 | + 'format' => 'html', | |
73 | + ], | |
55 | 74 | 'created_at:date', |
56 | 75 | 'updated_at:date', |
57 | 76 | [ |
58 | 77 | 'attribute' => 'status', |
59 | 78 | 'value' => ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'), |
60 | 79 | ], |
61 | - 'lang.alias', | |
62 | 80 | 'lang.body:html', |
63 | 81 | ], |
64 | 82 | ] |
65 | 83 | ) ?> |
84 | + | |
85 | + <?php $panel::end(); ?> | |
66 | 86 | |
67 | 87 | </div> | ... | ... |
views/blog-category/_form.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogCategory; | |
4 | - use artweb\artbox\blog\models\BlogCategoryLang; | |
3 | + use artbox\core\widgets\LanguageForm; | |
4 | + use artbox\weblog\models\Category; | |
5 | + use artbox\weblog\models\CategoryLang; | |
5 | 6 | use kartik\select2\Select2; |
7 | + use noam148\imagemanager\components\ImageManagerInputWidget; | |
6 | 8 | use yii\helpers\Html; |
7 | - use yii\helpers\Url; | |
8 | 9 | use yii\web\View; |
9 | 10 | use yii\widgets\ActiveForm; |
10 | - use artweb\artbox\language\widgets\LanguageForm; | |
11 | 11 | |
12 | 12 | /** |
13 | - * @var View $this | |
14 | - * @var BlogCategory $model | |
15 | - * @var ActiveForm $form | |
16 | - * @var BlogCategoryLang[] $modelLangs | |
17 | - * @var array $parentCategories | |
13 | + * @var View $this | |
14 | + * @var Category $model | |
15 | + * @var ActiveForm $form | |
16 | + * @var CategoryLang[] $modelLangs | |
17 | + * @var array $parentCategories | |
18 | 18 | */ |
19 | 19 | ?> |
20 | 20 | |
... | ... | @@ -31,40 +31,22 @@ |
31 | 31 | echo LanguageForm::widget( |
32 | 32 | [ |
33 | 33 | 'modelLangs' => $modelLangs, |
34 | - 'formView' => '@artweb/artbox/blog/views/blog-category/_form_language', | |
34 | + 'formView' => '@artbox/weblog/views/blog-category/_form_language', | |
35 | 35 | 'form' => $form, |
36 | 36 | ] |
37 | 37 | ); |
38 | 38 | ?> |
39 | 39 | |
40 | - <?= $form->field($model, 'image') | |
40 | + <?= $form->field($model, 'image_id') | |
41 | 41 | ->widget( |
42 | - \kartik\file\FileInput::className(), | |
42 | + ImageManagerInputWidget::className(), | |
43 | 43 | [ |
44 | - 'language' => 'ru', | |
45 | - 'options' => [ | |
46 | - 'accept' => 'image/*', | |
47 | - 'multiple' => false, | |
48 | - 'deleteurl' => $model->isNewRecord?false:Url::to(['/blog/blog-category/delete-image', 'id' => $model->id]), | |
49 | - 'class' => $model->isNewRecord?'':'artbox-delete-file', | |
50 | - ], | |
51 | - 'pluginOptions' => [ | |
52 | - 'allowedFileExtensions' => [ | |
53 | - 'jpg', | |
54 | - 'gif', | |
55 | - 'png', | |
56 | - ], | |
57 | - 'initialPreview' => !empty( $model->getImageUrl(0, false) ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( | |
58 | - $model->imageUrl, | |
59 | - 'list' | |
60 | - ) : '', | |
61 | - 'initialPreviewShowDelete' => false, | |
62 | - 'overwriteInitial' => true, | |
63 | - 'showRemove' => true, | |
64 | - 'showUpload' => false, | |
65 | - 'showClose' => false, | |
66 | - 'previewFileType' => 'image', | |
67 | - ], | |
44 | + 'aspectRatio' => ( 16 / 9 ), | |
45 | + //set the aspect ratio | |
46 | + 'showPreview' => true, | |
47 | + //false to hide the preview | |
48 | + 'showDeletePickedImageConfirm' => false, | |
49 | + //on true show warning before detach image | |
68 | 50 | ] |
69 | 51 | ); ?> |
70 | 52 | |
... | ... | @@ -85,14 +67,18 @@ |
85 | 67 | ?> |
86 | 68 | |
87 | 69 | <?= $form->field($model, 'status') |
88 | - ->checkbox() ?> | |
89 | - | |
90 | - <div class="form-group"> | |
91 | - <?= Html::submitButton( | |
92 | - $model->isNewRecord ? 'Create' : 'Update', | |
93 | - [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
94 | - ) ?> | |
95 | - </div> | |
70 | + ->checkbox( | |
71 | + [ | |
72 | + 'class' => 'flat', | |
73 | + ] | |
74 | + ) ?> | |
75 | + | |
76 | + <div class="form-group"> | |
77 | + <?= Html::submitButton( | |
78 | + $model->isNewRecord ? 'Create' : 'Update', | |
79 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
80 | + ) ?> | |
81 | + </div> | |
96 | 82 | |
97 | 83 | <?php ActiveForm::end(); ?> |
98 | 84 | ... | ... |
views/blog-category/_form_language.php
1 | 1 | <?php |
2 | - use artweb\artbox\blog\models\BlogArticleLang; | |
3 | - use artweb\artbox\language\models\Language; | |
2 | + | |
3 | + use artbox\core\helpers\SlugifyDecorator; | |
4 | + use artbox\weblog\models\CategoryLang; | |
5 | + use artbox\core\models\Language; | |
4 | 6 | use yii\web\View; |
5 | 7 | use yii\widgets\ActiveForm; |
6 | 8 | |
7 | 9 | /** |
8 | - * @var BlogArticleLang $model_lang | |
9 | - * @var Language $language | |
10 | - * @var ActiveForm $form | |
11 | - * @var View $this | |
10 | + * @var CategoryLang $model_lang | |
11 | + * @var Language $language | |
12 | + * @var ActiveForm $form | |
13 | + * @var View $this | |
12 | 14 | */ |
13 | 15 | ?> |
14 | -<?= $form->field($model_lang, '[' . $language->id . ']title') | |
15 | - ->textInput([ 'maxlength' => true ]); ?> | |
16 | +<?= $attributeField = $form->field($model_lang, '[' . $language->id . ']title') | |
17 | + ->textInput([ 'maxlength' => true ]); ?> | |
16 | 18 | |
17 | -<?= $form->field($model_lang, '[' . $language->id . ']alias') | |
18 | - ->textInput([ 'maxlength' => true ]); ?> | |
19 | +<?= SlugifyDecorator::decorate( | |
20 | + $form->field($model_lang, '[' . $language->id . ']aliasValue'), | |
21 | + [ '/alias/slugify' ], | |
22 | + $attributeField | |
23 | +) | |
24 | + ->textInput([ 'maxlength' => true ]); ?> | |
19 | 25 | |
20 | 26 | <?= $form->field($model_lang, '[' . $language->id . ']description') |
21 | 27 | ->textarea( |
... | ... | @@ -23,15 +29,3 @@ |
23 | 29 | 'rows' => '10', |
24 | 30 | ] |
25 | 31 | ) ?> |
26 | - | |
27 | -<?= $form->field($model_lang, '[' . $language->id . ']meta_title') | |
28 | - ->textInput([ 'maxlength' => true ]); ?> | |
29 | - | |
30 | -<?= $form->field($model_lang, '[' . $language->id . ']meta_description') | |
31 | - ->textInput([ 'maxlength' => true ]); ?> | |
32 | - | |
33 | -<?= $form->field($model_lang, '[' . $language->id . ']seo_text') | |
34 | - ->textInput([ 'maxlength' => true ]); ?> | |
35 | - | |
36 | -<?= $form->field($model_lang, '[' . $language->id . ']h1') | |
37 | - ->textInput([ 'maxlength' => true ]); ?> | ... | ... |
views/blog-category/create.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogArticleLang; | |
4 | - use artweb\artbox\blog\models\BlogCategory; | |
5 | - use yii\helpers\Html; | |
3 | + use artbox\weblog\models\Category; | |
4 | + use artbox\weblog\models\CategoryLang; | |
6 | 5 | use yii\web\View; |
6 | + use yiister\gentelella\widgets\Panel; | |
7 | 7 | |
8 | 8 | /** |
9 | - * @var View $this | |
10 | - * @var BlogCategory $model | |
11 | - * @var BlogArticleLang[] $modelLangs | |
12 | - * @var array $parentCategories | |
9 | + * @var View $this | |
10 | + * @var Category $model | |
11 | + * @var CategoryLang[] $modelLangs | |
12 | + * @var array $parentCategories | |
13 | 13 | */ |
14 | 14 | |
15 | 15 | $this->title = \Yii::t('blog', 'Create Blog Category'); |
... | ... | @@ -21,7 +21,11 @@ |
21 | 21 | ?> |
22 | 22 | <div class="blog-category-create"> |
23 | 23 | |
24 | - <h1><?= Html::encode($this->title) ?></h1> | |
24 | + <?php $panel = Panel::begin( | |
25 | + [ | |
26 | + 'header' => $this->title, | |
27 | + ] | |
28 | + ) ?> | |
25 | 29 | |
26 | 30 | <?= $this->render( |
27 | 31 | '_form', |
... | ... | @@ -31,5 +35,7 @@ |
31 | 35 | 'parentCategories' => $parentCategories, |
32 | 36 | ] |
33 | 37 | ) ?> |
38 | + | |
39 | + <?php $panel::end(); ?> | |
34 | 40 | |
35 | 41 | </div> | ... | ... |
views/blog-category/index.php
1 | 1 | <?php |
2 | 2 | |
3 | + use artbox\weblog\models\Category; | |
4 | + use artbox\weblog\models\CategorySearch; | |
3 | 5 | use yii\data\ActiveDataProvider; |
4 | 6 | use yii\helpers\Html; |
5 | 7 | use yii\grid\GridView; |
... | ... | @@ -8,7 +10,7 @@ |
8 | 10 | |
9 | 11 | /** |
10 | 12 | * @var View $this |
11 | - * @var BlogCategorySearch $searchModel | |
13 | + * @var CategorySearch $searchModel | |
12 | 14 | * @var ActiveDataProvider $dataProvider |
13 | 15 | */ |
14 | 16 | |
... | ... | @@ -36,26 +38,34 @@ |
36 | 38 | 'attribute' => 'title', |
37 | 39 | 'value' => 'lang.title', |
38 | 40 | ], |
39 | - 'imageUrl:image', | |
41 | + [ | |
42 | + 'attribute' => 'image_id', | |
43 | + 'value' => function (Category $model) { | |
44 | + if (empty($model->image_id)) { | |
45 | + return ''; | |
46 | + } else { | |
47 | + } | |
48 | + return $model->image->getImg( | |
49 | + [ | |
50 | + 'width' => '300px', | |
51 | + ] | |
52 | + ); | |
53 | + }, | |
54 | + 'format' => 'html', | |
55 | + ], | |
40 | 56 | [ |
41 | 57 | 'label' => \Yii::t('blog', 'Parent category'), |
42 | - 'value' => function ($model) { | |
43 | - /** | |
44 | - * @var BlogCategory $model | |
45 | - */ | |
58 | + 'value' => function (Category $model) { | |
46 | 59 | if (!empty($model->parent)) { |
47 | 60 | return $model->parent->lang->title; |
48 | 61 | } else { |
49 | 62 | return false; |
50 | - }; | |
63 | + } | |
51 | 64 | }, |
52 | 65 | ], |
53 | 66 | [ |
54 | 67 | 'attribute' => 'status', |
55 | - 'value' => function ($model) { | |
56 | - /** | |
57 | - * @var BlogCategory $model | |
58 | - */ | |
68 | + 'value' => function (Category $model) { | |
59 | 69 | return ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'); |
60 | 70 | }, |
61 | 71 | 'filter' => [ | ... | ... |
views/blog-category/update.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogCategory; | |
4 | - use artweb\artbox\blog\models\BlogCategoryLang; | |
5 | - use yii\helpers\Html; | |
3 | + use artbox\weblog\models\Category; | |
4 | + use artbox\weblog\models\CategoryLang; | |
6 | 5 | use yii\web\View; |
6 | + use yiister\gentelella\widgets\Panel; | |
7 | 7 | |
8 | 8 | /** |
9 | - * @var View $this | |
10 | - * @var BlogCategory $model | |
11 | - * @var BlogCategoryLang $modelLangs | |
12 | - * @var array $parentCategories | |
9 | + * @var View $this | |
10 | + * @var Category $model | |
11 | + * @var CategoryLang $modelLangs | |
12 | + * @var array $parentCategories | |
13 | 13 | */ |
14 | 14 | |
15 | 15 | $this->title = \Yii::t('blog', 'Update Blog Category: ') . $model->lang->title; |
... | ... | @@ -28,7 +28,11 @@ |
28 | 28 | ?> |
29 | 29 | <div class="blog-category-update"> |
30 | 30 | |
31 | - <h1><?= Html::encode($this->title) ?></h1> | |
31 | + <?php $panel = Panel::begin( | |
32 | + [ | |
33 | + 'header' => $this->title, | |
34 | + ] | |
35 | + ); ?> | |
32 | 36 | |
33 | 37 | <?= $this->render( |
34 | 38 | '_form', |
... | ... | @@ -38,5 +42,7 @@ |
38 | 42 | 'parentCategories' => $parentCategories, |
39 | 43 | ] |
40 | 44 | ) ?> |
45 | + | |
46 | + <?php $panel::end(); ?> | |
41 | 47 | |
42 | 48 | </div> | ... | ... |
views/blog-category/view.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogCategory; | |
3 | + use artbox\weblog\models\Category; | |
4 | 4 | use yii\helpers\Html; |
5 | 5 | use yii\web\View; |
6 | 6 | use yii\widgets\DetailView; |
7 | + use yiister\gentelella\widgets\Panel; | |
7 | 8 | |
8 | 9 | /** |
9 | - * @var View $this | |
10 | - * @var BlogCategory $model | |
10 | + * @var View $this | |
11 | + * @var Category $model | |
11 | 12 | */ |
12 | 13 | |
13 | 14 | $this->title = $model->lang->title; |
... | ... | @@ -19,45 +20,48 @@ |
19 | 20 | ?> |
20 | 21 | <div class="blog-category-view"> |
21 | 22 | |
22 | - <h1><?= Html::encode($this->title) ?></h1> | |
23 | - | |
24 | - <p> | |
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, | |
38 | - ], | |
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 | - ) ?> | |
47 | - </p> | |
23 | + <?php $panel = Panel::begin( | |
24 | + [ | |
25 | + 'header' => $this->title, | |
26 | + ] | |
27 | + ); ?> | |
28 | + | |
29 | + <p> | |
30 | + <?= Html::a( | |
31 | + 'Update', | |
32 | + [ | |
33 | + 'update', | |
34 | + 'id' => $model->id, | |
35 | + ], | |
36 | + [ 'class' => 'btn btn-primary' ] | |
37 | + ) ?> | |
38 | + <?= Html::a( | |
39 | + 'Delete', | |
40 | + [ | |
41 | + 'delete', | |
42 | + 'id' => $model->id, | |
43 | + ], | |
44 | + [ | |
45 | + 'class' => 'btn btn-danger', | |
46 | + 'data' => [ | |
47 | + 'confirm' => 'Are you sure you want to delete this item?', | |
48 | + 'method' => 'post', | |
49 | + ], | |
50 | + ] | |
51 | + ) ?> | |
52 | + </p> | |
48 | 53 | |
49 | 54 | <?= DetailView::widget( |
50 | 55 | [ |
51 | 56 | 'model' => $model, |
52 | 57 | 'attributes' => [ |
53 | 58 | 'id', |
59 | + 'lang.title', | |
54 | 60 | 'sort', |
55 | - 'imageUrl:image', | |
56 | 61 | [ |
57 | 62 | 'attribute' => 'parent_id', |
58 | - 'value' => ( !empty( $model->parent ) ) ? $model->parent->lang->title : '', | |
63 | + 'value' => ( !empty($model->parent) ) ? $model->parent->lang->title : '', | |
59 | 64 | ], |
60 | - 'lang.alias', | |
61 | 65 | 'lang.description:text', |
62 | 66 | [ |
63 | 67 | 'attribute' => 'status', |
... | ... | @@ -66,5 +70,7 @@ |
66 | 70 | ], |
67 | 71 | ] |
68 | 72 | ) ?> |
73 | + | |
74 | + <?php $panel::end(); ?> | |
69 | 75 | |
70 | 76 | </div> | ... | ... |
views/blog-tag/_form.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogTag; | |
4 | - use artweb\artbox\blog\models\BlogTagLang; | |
3 | + use artbox\core\widgets\LanguageForm; | |
4 | + use artbox\weblog\models\Tag; | |
5 | + use artbox\weblog\models\TagLang; | |
5 | 6 | use yii\helpers\Html; |
6 | 7 | use yii\web\View; |
7 | 8 | use yii\widgets\ActiveForm; |
8 | - use artweb\artbox\language\widgets\LanguageForm; | |
9 | + | |
9 | 10 | |
10 | 11 | /** |
11 | - * @var View $this | |
12 | - * @var BlogTag $model | |
13 | - * @var ActiveForm $form | |
14 | - * @var BlogTagLang[] $modelLangs | |
12 | + * @var View $this | |
13 | + * @var Tag $model | |
14 | + * @var ActiveForm $form | |
15 | + * @var TagLang[] $modelLangs | |
15 | 16 | */ |
16 | 17 | ?> |
17 | 18 | |
... | ... | @@ -23,7 +24,7 @@ |
23 | 24 | echo LanguageForm::widget( |
24 | 25 | [ |
25 | 26 | 'modelLangs' => $modelLangs, |
26 | - 'formView' => '@artweb/artbox/blog/views/blog-tag/_form_language', | |
27 | + 'formView' => '@artbox/weblog/views/blog-tag/_form_language', | |
27 | 28 | 'form' => $form, |
28 | 29 | ] |
29 | 30 | ); | ... | ... |
views/blog-tag/_form_language.php
1 | 1 | <?php |
2 | - use artweb\artbox\blog\models\BlogArticleLang; | |
3 | - use artweb\artbox\language\models\Language; | |
2 | + | |
3 | + use artbox\core\models\Language; | |
4 | + use artbox\weblog\models\ArticleLang; | |
4 | 5 | use yii\web\View; |
5 | 6 | use yii\widgets\ActiveForm; |
6 | 7 | |
7 | 8 | /** |
8 | - * @var BlogArticleLang $model_lang | |
9 | - * @var Language $language | |
10 | - * @var ActiveForm $form | |
11 | - * @var View $this | |
9 | + * @var ArticleLang $model_lang | |
10 | + * @var Language $language | |
11 | + * @var ActiveForm $form | |
12 | + * @var View $this | |
12 | 13 | */ |
13 | 14 | ?> |
14 | 15 | <?= $form->field($model_lang, '[' . $language->id . ']label') | ... | ... |
views/blog-tag/create.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogTag; | |
4 | - use artweb\artbox\blog\models\BlogTagLang; | |
5 | - use yii\helpers\Html; | |
3 | + use artbox\weblog\models\Tag; | |
4 | + use artbox\weblog\models\TagLang; | |
6 | 5 | use yii\web\View; |
6 | + use yiister\gentelella\widgets\Panel; | |
7 | 7 | |
8 | 8 | /** |
9 | - * @var View $this | |
10 | - * @var BlogTagLang[] $modelLangs | |
11 | - * @var BlogTag $model | |
9 | + * @var View $this | |
10 | + * @var TagLang[] $modelLangs | |
11 | + * @var Tag $model | |
12 | 12 | */ |
13 | 13 | |
14 | 14 | $this->title = \Yii::t('blog', 'Create Blog Tag'); |
... | ... | @@ -20,7 +20,11 @@ |
20 | 20 | ?> |
21 | 21 | <div class="blog-tag-create"> |
22 | 22 | |
23 | - <h1><?= Html::encode($this->title) ?></h1> | |
23 | + <?php $panel = Panel::begin( | |
24 | + [ | |
25 | + 'header' => $this->title, | |
26 | + ] | |
27 | + ); ?> | |
24 | 28 | |
25 | 29 | <?= $this->render( |
26 | 30 | '_form', |
... | ... | @@ -29,5 +33,7 @@ |
29 | 33 | 'modelLangs' => $modelLangs, |
30 | 34 | ] |
31 | 35 | ) ?> |
36 | + | |
37 | + <?php $panel::end(); ?> | |
32 | 38 | |
33 | 39 | </div> | ... | ... |
views/blog-tag/update.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogTag; | |
4 | - use artweb\artbox\blog\models\BlogTagLang; | |
5 | - use yii\helpers\Html; | |
3 | + use artbox\weblog\models\Tag; | |
4 | + use artbox\weblog\models\TagLang; | |
6 | 5 | use yii\web\View; |
6 | + use yiister\gentelella\widgets\Panel; | |
7 | 7 | |
8 | 8 | /** |
9 | - * @var View $this | |
10 | - * @var BlogTagLang[] $modelLangs | |
11 | - * @var BlogTag $model | |
9 | + * @var View $this | |
10 | + * @var TagLang[] $modelLangs | |
11 | + * @var Tag $model | |
12 | 12 | */ |
13 | 13 | |
14 | 14 | $this->title = \Yii::t('blog', 'Update Blog Tag: ') . $model->lang->label; |
... | ... | @@ -27,7 +27,11 @@ |
27 | 27 | ?> |
28 | 28 | <div class="blog-tag-update"> |
29 | 29 | |
30 | - <h1><?= Html::encode($this->title) ?></h1> | |
30 | + <?php $panel = Panel::begin( | |
31 | + [ | |
32 | + 'header' => $this->title, | |
33 | + ] | |
34 | + ); ?> | |
31 | 35 | |
32 | 36 | <?= $this->render( |
33 | 37 | '_form', |
... | ... | @@ -36,5 +40,7 @@ |
36 | 40 | 'modelLangs' => $modelLangs, |
37 | 41 | ] |
38 | 42 | ) ?> |
39 | - | |
43 | + | |
44 | + <?php $panel::end(); ?> | |
45 | + | |
40 | 46 | </div> | ... | ... |
views/blog-tag/view.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artweb\artbox\blog\models\BlogTag; | |
3 | + use artbox\weblog\models\Tag; | |
4 | 4 | use yii\helpers\Html; |
5 | 5 | use yii\web\View; |
6 | 6 | use yii\widgets\DetailView; |
7 | + use yiister\gentelella\widgets\Panel; | |
7 | 8 | |
8 | 9 | /** |
9 | - * @var View $this | |
10 | - * @var BlogTag $model | |
10 | + * @var View $this | |
11 | + * @var Tag $model | |
11 | 12 | */ |
12 | 13 | |
13 | 14 | $this->title = $model->lang->label; |
... | ... | @@ -19,32 +20,36 @@ |
19 | 20 | ?> |
20 | 21 | <div class="blog-tag-view"> |
21 | 22 | |
22 | - <h1><?= Html::encode($this->title) ?></h1> | |
23 | - | |
24 | - <p> | |
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, | |
38 | - ], | |
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 | - ) ?> | |
47 | - </p> | |
23 | + <?php $panel = Panel::begin( | |
24 | + [ | |
25 | + 'header' => $this->title, | |
26 | + ] | |
27 | + ); ?> | |
28 | + | |
29 | + <p> | |
30 | + <?= Html::a( | |
31 | + 'Update', | |
32 | + [ | |
33 | + 'update', | |
34 | + 'id' => $model->id, | |
35 | + ], | |
36 | + [ 'class' => 'btn btn-primary' ] | |
37 | + ) ?> | |
38 | + <?= Html::a( | |
39 | + 'Delete', | |
40 | + [ | |
41 | + 'delete', | |
42 | + 'id' => $model->id, | |
43 | + ], | |
44 | + [ | |
45 | + 'class' => 'btn btn-danger', | |
46 | + 'data' => [ | |
47 | + 'confirm' => 'Are you sure you want to delete this item?', | |
48 | + 'method' => 'post', | |
49 | + ], | |
50 | + ] | |
51 | + ) ?> | |
52 | + </p> | |
48 | 53 | |
49 | 54 | <?= DetailView::widget( |
50 | 55 | [ |
... | ... | @@ -55,5 +60,7 @@ |
55 | 60 | ], |
56 | 61 | ] |
57 | 62 | ) ?> |
63 | + | |
64 | + <?php $panel::end(); ?> | |
58 | 65 | |
59 | 66 | </div> | ... | ... |