Commit ec7e18323f44fddc1b879ea9ba7e22320f562577
1 parent
14bb41a7
image_id moved to blog_article_lang
Showing
16 changed files
with
1644 additions
and
10 deletions
Show diff stats
backend/config/main.php
| @@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
| 26 | 'alias' => 'artbox\core\seo\controllers\AliasController', | 26 | 'alias' => 'artbox\core\seo\controllers\AliasController', |
| 27 | 'seo' => 'artbox\core\controllers\SeoController', | 27 | 'seo' => 'artbox\core\controllers\SeoController', |
| 28 | 'feedback' => 'artbox\core\controllers\FeedbackController', | 28 | 'feedback' => 'artbox\core\controllers\FeedbackController', |
| 29 | - 'blog' => 'artbox\weblog\controllers\ArticleController', | 29 | + 'blog' => 'backend\controllers\ArticleController', |
| 30 | 'blog-category' => 'artbox\weblog\controllers\CategoryController', | 30 | 'blog-category' => 'artbox\weblog\controllers\CategoryController', |
| 31 | 'blog-tag' => 'artbox\weblog\controllers\TagController', | 31 | 'blog-tag' => 'artbox\weblog\controllers\TagController', |
| 32 | 'comment' => 'artbox\webcomment\controllers\ManageController', | 32 | 'comment' => 'artbox\webcomment\controllers\ManageController', |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace backend\controllers; | ||
| 4 | + | ||
| 5 | + use artbox\weblog\models\Category; | ||
| 6 | + use artbox\weblog\models\Tag; | ||
| 7 | + use Yii; | ||
| 8 | + use common\models\Article; | ||
| 9 | + use common\models\ArticleSearch; | ||
| 10 | + use yii\helpers\ArrayHelper; | ||
| 11 | + use yii\web\Controller; | ||
| 12 | + use yii\web\NotFoundHttpException; | ||
| 13 | + use yii\filters\VerbFilter; | ||
| 14 | + use yii\web\Response; | ||
| 15 | + use yii\filters\AccessControl; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * BlogArticleController implements the CRUD actions for BlogArticle model. | ||
| 19 | + */ | ||
| 20 | + class ArticleController extends Controller | ||
| 21 | + { | ||
| 22 | + /** | ||
| 23 | + * @inheritdoc | ||
| 24 | + */ | ||
| 25 | + public function getViewPath() | ||
| 26 | + { | ||
| 27 | + return '@backend/views/blog-article'; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * @inheritdoc | ||
| 32 | + */ | ||
| 33 | + public function behaviors() | ||
| 34 | + { | ||
| 35 | + return [ | ||
| 36 | + 'verbs' => [ | ||
| 37 | + 'class' => VerbFilter::className(), | ||
| 38 | + 'actions' => [ | ||
| 39 | + 'delete' => [ 'POST' ], | ||
| 40 | + ], | ||
| 41 | + ], | ||
| 42 | + 'access' => [ | ||
| 43 | + 'class' => AccessControl::className(), | ||
| 44 | + 'rules' => [ | ||
| 45 | + [ | ||
| 46 | + 'actions' => [ | ||
| 47 | + 'login', | ||
| 48 | + 'error', | ||
| 49 | + ], | ||
| 50 | + 'allow' => true, | ||
| 51 | + ], | ||
| 52 | + [ | ||
| 53 | + 'allow' => true, | ||
| 54 | + 'roles' => [ '@' ], | ||
| 55 | + ], | ||
| 56 | + ], | ||
| 57 | + ], | ||
| 58 | + ]; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * Lists all BlogArticle models. | ||
| 63 | + * | ||
| 64 | + * @return mixed | ||
| 65 | + */ | ||
| 66 | + public function actionIndex() | ||
| 67 | + { | ||
| 68 | + $searchModel = new ArticleSearch(); | ||
| 69 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
| 70 | + | ||
| 71 | + return $this->render( | ||
| 72 | + 'index', | ||
| 73 | + [ | ||
| 74 | + 'searchModel' => $searchModel, | ||
| 75 | + 'dataProvider' => $dataProvider, | ||
| 76 | + ] | ||
| 77 | + ); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * Displays a single BlogArticle model. | ||
| 82 | + * | ||
| 83 | + * @param integer $id | ||
| 84 | + * | ||
| 85 | + * @return mixed | ||
| 86 | + */ | ||
| 87 | + public function actionView($id) | ||
| 88 | + { | ||
| 89 | + return $this->render( | ||
| 90 | + 'view', | ||
| 91 | + [ | ||
| 92 | + 'model' => $this->findModel($id), | ||
| 93 | + ] | ||
| 94 | + ); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * Creates a new BlogArticle model. | ||
| 99 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
| 100 | + * | ||
| 101 | + * @return mixed | ||
| 102 | + */ | ||
| 103 | + public function actionCreate() | ||
| 104 | + { | ||
| 105 | + $model = new Article(); | ||
| 106 | + $model->generateLangs(); | ||
| 107 | + | ||
| 108 | + if (class_exists('\artbox\catalog\models\Product')) { | ||
| 109 | + $model->productIds = ArrayHelper::map( | ||
| 110 | + $model->relatedProducts, | ||
| 111 | + 'id', | ||
| 112 | + 'lang.title' | ||
| 113 | + ); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | ||
| 117 | + | ||
| 118 | + $categories = Category::find() | ||
| 119 | + ->where([ 'id' => \Yii::$app->request->post('categoryIds') ]) | ||
| 120 | + ->all(); | ||
| 121 | + | ||
| 122 | + if (class_exists('\artbox\catalog\models\Product')) { | ||
| 123 | + /** | ||
| 124 | + * @var \yii\db\ActiveQuery $query | ||
| 125 | + */ | ||
| 126 | + $query = call_user_func( | ||
| 127 | + [ | ||
| 128 | + '\artbox\catalog\models\Product', | ||
| 129 | + 'find', | ||
| 130 | + ] | ||
| 131 | + ); | ||
| 132 | + /** | ||
| 133 | + * @var \artbox\catalog\models\Product[] $products | ||
| 134 | + */ | ||
| 135 | + $products = $query->where([ 'id' => \Yii::$app->request->post('productIds') ]) | ||
| 136 | + ->all(); | ||
| 137 | + | ||
| 138 | + $model->linkMany('relatedProducts', $products); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + | ||
| 142 | + $model->linkMany('categories', $categories); | ||
| 143 | + | ||
| 144 | + $tags = Tag::find() | ||
| 145 | + ->where( | ||
| 146 | + [ | ||
| 147 | + 'id' => \Yii::$app->request->post('tagIds'), | ||
| 148 | + ] | ||
| 149 | + ) | ||
| 150 | + ->all(); | ||
| 151 | + | ||
| 152 | + $model->linkMany('tags', $tags); | ||
| 153 | + | ||
| 154 | + return $this->redirect( | ||
| 155 | + [ | ||
| 156 | + 'view', | ||
| 157 | + 'id' => $model->id, | ||
| 158 | + ] | ||
| 159 | + ); | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + return $this->render( | ||
| 163 | + 'create', | ||
| 164 | + [ | ||
| 165 | + 'model' => $model, | ||
| 166 | + 'modelLangs' => $model->modelLangs, | ||
| 167 | + ] | ||
| 168 | + ); | ||
| 169 | + | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + /** | ||
| 173 | + * Updates an existing BlogArticle model. | ||
| 174 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
| 175 | + * | ||
| 176 | + * @param integer $id | ||
| 177 | + * | ||
| 178 | + * @return mixed | ||
| 179 | + */ | ||
| 180 | + public function actionUpdate($id) | ||
| 181 | + { | ||
| 182 | + $model = $this->findModel($id); | ||
| 183 | + $model->generateLangs(); | ||
| 184 | + | ||
| 185 | + $model->categoryIds = ArrayHelper::map( | ||
| 186 | + $model->categories, | ||
| 187 | + 'id', | ||
| 188 | + 'lang.title' | ||
| 189 | + ); | ||
| 190 | + | ||
| 191 | + $model->tagIds = ArrayHelper::map( | ||
| 192 | + $model->tags, | ||
| 193 | + 'id', | ||
| 194 | + 'lang.label' | ||
| 195 | + ); | ||
| 196 | + | ||
| 197 | + $model->articleIds = ArrayHelper::map( | ||
| 198 | + $model->articles, | ||
| 199 | + 'id', | ||
| 200 | + 'lang.title' | ||
| 201 | + ); | ||
| 202 | + | ||
| 203 | + if (class_exists('\artbox\catalog\models\Product')) { | ||
| 204 | + $model->productIds = ArrayHelper::map( | ||
| 205 | + $model->relatedProducts, | ||
| 206 | + 'id', | ||
| 207 | + 'lang.title' | ||
| 208 | + ); | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | ||
| 212 | + $categories = Category::find() | ||
| 213 | + ->where([ 'id' => \Yii::$app->request->post('categoryIds') ]) | ||
| 214 | + ->all(); | ||
| 215 | + | ||
| 216 | + $model->linkMany('categories', $categories); | ||
| 217 | + | ||
| 218 | + $tags = Tag::find() | ||
| 219 | + ->where( | ||
| 220 | + [ | ||
| 221 | + 'id' => \Yii::$app->request->post('tagIds'), | ||
| 222 | + ] | ||
| 223 | + ) | ||
| 224 | + ->all(); | ||
| 225 | + | ||
| 226 | + $model->linkMany('tags', $tags); | ||
| 227 | + | ||
| 228 | + if (class_exists('\artbox\catalog\models\Product')) { | ||
| 229 | + /** | ||
| 230 | + * @var \yii\db\ActiveQuery $query | ||
| 231 | + */ | ||
| 232 | + $query = call_user_func( | ||
| 233 | + [ | ||
| 234 | + '\artbox\catalog\models\Product', | ||
| 235 | + 'find', | ||
| 236 | + ] | ||
| 237 | + ); | ||
| 238 | + /** | ||
| 239 | + * @var \artbox\catalog\models\Product[] $products | ||
| 240 | + */ | ||
| 241 | + $products = $query->where([ 'id' => \Yii::$app->request->post('productIds') ]) | ||
| 242 | + ->all(); | ||
| 243 | + | ||
| 244 | + $model->linkMany('relatedProducts', $products); | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + return $this->redirect( | ||
| 248 | + [ | ||
| 249 | + 'view', | ||
| 250 | + 'id' => $model->id, | ||
| 251 | + ] | ||
| 252 | + ); | ||
| 253 | + | ||
| 254 | + } | ||
| 255 | + return $this->render( | ||
| 256 | + 'update', | ||
| 257 | + [ | ||
| 258 | + 'model' => $model, | ||
| 259 | + 'modelLangs' => $model->modelLangs, | ||
| 260 | + ] | ||
| 261 | + ); | ||
| 262 | + | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + /** | ||
| 266 | + * Deletes an existing BlogArticle model. | ||
| 267 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
| 268 | + * | ||
| 269 | + * @param integer $id | ||
| 270 | + * | ||
| 271 | + * @return mixed | ||
| 272 | + */ | ||
| 273 | + public function actionDelete($id) | ||
| 274 | + { | ||
| 275 | + $this->findModel($id) | ||
| 276 | + ->delete(); | ||
| 277 | + | ||
| 278 | + return $this->redirect([ 'index' ]); | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + /** | ||
| 282 | + * Finds the BlogArticle model based on its primary key value. | ||
| 283 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
| 284 | + * | ||
| 285 | + * @param integer $id | ||
| 286 | + * | ||
| 287 | + * @return Article the loaded model | ||
| 288 | + * @throws NotFoundHttpException if the model cannot be found | ||
| 289 | + */ | ||
| 290 | + protected function findModel($id) | ||
| 291 | + { | ||
| 292 | + if (( $model = Article::findOne($id) ) !== null) { | ||
| 293 | + return $model; | ||
| 294 | + } else { | ||
| 295 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
| 296 | + } | ||
| 297 | + } | ||
| 298 | + | ||
| 299 | + /** | ||
| 300 | + * @param string $q | ||
| 301 | + * @param integer $id | ||
| 302 | + * | ||
| 303 | + * @return array | ||
| 304 | + */ | ||
| 305 | + public function actionList(string $q = null, int $id = null) | ||
| 306 | + { | ||
| 307 | + \Yii::$app->response->format = Response::FORMAT_JSON; | ||
| 308 | + $out = [ | ||
| 309 | + 'results' => [ | ||
| 310 | + 'id' => '', | ||
| 311 | + 'text' => '', | ||
| 312 | + ], | ||
| 313 | + ]; | ||
| 314 | + if (!is_null($q)) { | ||
| 315 | + $out[ 'results' ] = Article::find() | ||
| 316 | + ->joinWith('lang') | ||
| 317 | + ->select( | ||
| 318 | + [ | ||
| 319 | + 'blog_article.id as id', | ||
| 320 | + 'blog_article_lang.title as text', | ||
| 321 | + ] | ||
| 322 | + ) | ||
| 323 | + ->where( | ||
| 324 | + [ | ||
| 325 | + 'like', | ||
| 326 | + 'blog_article_lang.title', | ||
| 327 | + $q, | ||
| 328 | + ] | ||
| 329 | + ) | ||
| 330 | + ->andFilterWhere( | ||
| 331 | + [ | ||
| 332 | + '!=', | ||
| 333 | + 'blog_article.id', | ||
| 334 | + $id, | ||
| 335 | + ] | ||
| 336 | + ) | ||
| 337 | + ->limit(20) | ||
| 338 | + ->asArray() | ||
| 339 | + ->all(); | ||
| 340 | + } | ||
| 341 | + return $out; | ||
| 342 | + } | ||
| 343 | + } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use artbox\core\components\imagemanager\components\ImageManagerInputWidget; | ||
| 4 | + use artbox\weblog\models\Article; | ||
| 5 | + use artbox\weblog\models\ArticleLang; | ||
| 6 | + use artbox\weblog\models\Category; | ||
| 7 | + use artbox\weblog\models\Tag; | ||
| 8 | + use kartik\select2\Select2; | ||
| 9 | + use yii\helpers\Html; | ||
| 10 | + use yii\helpers\Url; | ||
| 11 | + use yii\web\View; | ||
| 12 | + use yii\widgets\ActiveForm; | ||
| 13 | + use artbox\core\widgets\LanguageForm; | ||
| 14 | + use yii\web\JsExpression; | ||
| 15 | + use yii\widgets\InputWidget; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * @var View $this | ||
| 19 | + * @var Article $model | ||
| 20 | + * @var ActiveForm $form | ||
| 21 | + * @var ArticleLang[] $modelLangs | ||
| 22 | + * @var Category[] $categories | ||
| 23 | + * @var Tag[] $tags | ||
| 24 | + * @var array $products | ||
| 25 | + * @var array $articles | ||
| 26 | + */ | ||
| 27 | +?> | ||
| 28 | + | ||
| 29 | +<div class="blog-article-form"> | ||
| 30 | + | ||
| 31 | + <?php $form = ActiveForm::begin( | ||
| 32 | + [ | ||
| 33 | + 'options' => [ 'enctype' => 'multipart/form-data' ], | ||
| 34 | + ] | ||
| 35 | + ); ?> | ||
| 36 | + | ||
| 37 | + <?php | ||
| 38 | + echo LanguageForm::widget( | ||
| 39 | + [ | ||
| 40 | + 'modelLangs' => $modelLangs, | ||
| 41 | + 'formView' => '@backend/views/blog-article/_form_language', | ||
| 42 | + 'form' => $form, | ||
| 43 | + ] | ||
| 44 | + ); | ||
| 45 | + ?> | ||
| 46 | + | ||
| 47 | + <div class="form-group"> | ||
| 48 | + <label class="control-label"><?= \Yii::t('blog', 'Categories'); ?></label> | ||
| 49 | + <?php | ||
| 50 | + echo Select2::widget( | ||
| 51 | + [ | ||
| 52 | + 'name' => 'categoryIds', | ||
| 53 | + 'options' => [ | ||
| 54 | + 'placeholder' => \Yii::t('blog', 'Search for a categories ...'), | ||
| 55 | + 'multiple' => true, | ||
| 56 | + | ||
| 57 | + ], | ||
| 58 | + | ||
| 59 | + 'value' => array_keys($model->categoryIds), | ||
| 60 | + 'data' => $model->categoryIds, | ||
| 61 | + 'toggleAllSettings' => [ | ||
| 62 | + 'selectLabel' => false, | ||
| 63 | + ], | ||
| 64 | + 'pluginOptions' => [ | ||
| 65 | + 'allowClear' => true, | ||
| 66 | + 'minimumInputLength' => 3, | ||
| 67 | + 'language' => [ | ||
| 68 | + 'errorLoading' => new JsExpression( | ||
| 69 | + "function () { return 'Waiting for results...'; }" | ||
| 70 | + ), | ||
| 71 | + ], | ||
| 72 | + 'ajax' => [ | ||
| 73 | + 'url' => Url::to([ '/blog-category/list' ]), | ||
| 74 | + 'dataType' => 'json', | ||
| 75 | + 'data' => new JsExpression( | ||
| 76 | + 'function(params) { | ||
| 77 | + return { | ||
| 78 | + q:params.term | ||
| 79 | + }; | ||
| 80 | + }' | ||
| 81 | + ), | ||
| 82 | + ], | ||
| 83 | + 'escapeMarkup' => new JsExpression( | ||
| 84 | + 'function (markup) { | ||
| 85 | + return markup; | ||
| 86 | + }' | ||
| 87 | + ), | ||
| 88 | + 'templateResult' => new JsExpression( | ||
| 89 | + 'function (brand) { | ||
| 90 | + return brand.text; | ||
| 91 | + }' | ||
| 92 | + ), | ||
| 93 | + 'templateSelection' => new JsExpression( | ||
| 94 | + 'function (brand) { | ||
| 95 | + return brand.text; | ||
| 96 | + }' | ||
| 97 | + ), | ||
| 98 | + ], | ||
| 99 | + ] | ||
| 100 | + ); | ||
| 101 | + ?> | ||
| 102 | + </div> | ||
| 103 | + | ||
| 104 | + <div class="form-group"> | ||
| 105 | + <label class="control-label"><?= \Yii::t('blog', 'Tags'); ?></label> | ||
| 106 | + <?php | ||
| 107 | + echo Select2::widget( | ||
| 108 | + [ | ||
| 109 | + 'name' => 'tagIds', | ||
| 110 | + 'options' => [ | ||
| 111 | + 'placeholder' => \Yii::t('blog', 'Search for a tags ...'), | ||
| 112 | + 'multiple' => true, | ||
| 113 | + ], | ||
| 114 | + 'toggleAllSettings' => [ | ||
| 115 | + 'selectLabel' => false, | ||
| 116 | + ], | ||
| 117 | + 'value' => array_keys($model->tagIds), | ||
| 118 | + 'data' => $model->tagIds, | ||
| 119 | + 'pluginOptions' => [ | ||
| 120 | + 'allowClear' => true, | ||
| 121 | + 'minimumInputLength' => 3, | ||
| 122 | + 'language' => [ | ||
| 123 | + 'errorLoading' => new JsExpression( | ||
| 124 | + "function () { return 'Waiting for results...'; }" | ||
| 125 | + ), | ||
| 126 | + ], | ||
| 127 | + 'ajax' => [ | ||
| 128 | + 'url' => Url::to([ '/blog-tag/list' ]), | ||
| 129 | + 'dataType' => 'json', | ||
| 130 | + 'data' => new JsExpression( | ||
| 131 | + 'function(params) { | ||
| 132 | + return { | ||
| 133 | + q:params.term | ||
| 134 | + }; | ||
| 135 | + }' | ||
| 136 | + ), | ||
| 137 | + ], | ||
| 138 | + 'escapeMarkup' => new JsExpression( | ||
| 139 | + 'function (markup) { | ||
| 140 | + return markup; | ||
| 141 | + }' | ||
| 142 | + ), | ||
| 143 | + 'templateResult' => new JsExpression( | ||
| 144 | + 'function (brand) { | ||
| 145 | + return brand.text; | ||
| 146 | + }' | ||
| 147 | + ), | ||
| 148 | + 'templateSelection' => new JsExpression( | ||
| 149 | + 'function (brand) { | ||
| 150 | + return brand.text; | ||
| 151 | + }' | ||
| 152 | + ), | ||
| 153 | + ], | ||
| 154 | + ] | ||
| 155 | + ); | ||
| 156 | + ?> | ||
| 157 | + </div> | ||
| 158 | + | ||
| 159 | + <div class="form-group"> | ||
| 160 | + <label class="control-label"><?= \Yii::t('blog', 'Articles'); ?></label> | ||
| 161 | + <?php | ||
| 162 | + if ($model->isNewRecord) { | ||
| 163 | + $condition = ''; | ||
| 164 | + } else { | ||
| 165 | + $condition = ', id: ' . $model->id; | ||
| 166 | + } | ||
| 167 | + echo Select2::widget( | ||
| 168 | + [ | ||
| 169 | + 'name' => 'articleIds', | ||
| 170 | + 'options' => [ | ||
| 171 | + 'placeholder' => \Yii::t('blog', 'Search for an articles ...'), | ||
| 172 | + 'multiple' => true, | ||
| 173 | + ], | ||
| 174 | + 'toggleAllSettings' => [ | ||
| 175 | + 'selectLabel' => false, | ||
| 176 | + ], | ||
| 177 | + 'value' => array_keys($model->articleIds), | ||
| 178 | + 'data' => $model->articleIds, | ||
| 179 | + 'pluginOptions' => [ | ||
| 180 | + 'allowClear' => true, | ||
| 181 | + 'minimumInputLength' => 3, | ||
| 182 | + 'language' => [ | ||
| 183 | + 'errorLoading' => new JsExpression( | ||
| 184 | + "function () { return 'Waiting for results...'; }" | ||
| 185 | + ), | ||
| 186 | + ], | ||
| 187 | + 'ajax' => [ | ||
| 188 | + 'url' => Url::to([ '/blog-article/list' ]), | ||
| 189 | + 'dataType' => 'json', | ||
| 190 | + 'data' => new JsExpression( | ||
| 191 | + 'function(params) { | ||
| 192 | + return { | ||
| 193 | + q:params.term' . $condition . ' | ||
| 194 | + }; | ||
| 195 | + }' | ||
| 196 | + ), | ||
| 197 | + ], | ||
| 198 | + 'escapeMarkup' => new JsExpression( | ||
| 199 | + 'function (markup) { | ||
| 200 | + return markup; | ||
| 201 | + }' | ||
| 202 | + ), | ||
| 203 | + 'templateResult' => new JsExpression( | ||
| 204 | + 'function (brand) { | ||
| 205 | + return brand.text; | ||
| 206 | + }' | ||
| 207 | + ), | ||
| 208 | + 'templateSelection' => new JsExpression( | ||
| 209 | + 'function (brand) { | ||
| 210 | + return brand.text; | ||
| 211 | + }' | ||
| 212 | + ), | ||
| 213 | + ], | ||
| 214 | + ] | ||
| 215 | + ); | ||
| 216 | + ?> | ||
| 217 | + </div> | ||
| 218 | + <?php | ||
| 219 | + if (class_exists('\artbox\catalog\models\Product')) { | ||
| 220 | + ?> | ||
| 221 | + <div class="form-group"> | ||
| 222 | + <label class="control-label"><?= \Yii::t('blog', 'Products'); ?></label> | ||
| 223 | + <?php | ||
| 224 | + echo Select2::widget( | ||
| 225 | + [ | ||
| 226 | + 'name' => 'productIds', | ||
| 227 | + 'options' => [ | ||
| 228 | + 'placeholder' => \Yii::t('blog', 'Search for products ...'), | ||
| 229 | + 'multiple' => true, | ||
| 230 | + ], | ||
| 231 | + 'toggleAllSettings' => [ | ||
| 232 | + 'selectLabel' => false, | ||
| 233 | + ], | ||
| 234 | + 'value' => array_keys($model->productIds), | ||
| 235 | + 'data' => $model->productIds, | ||
| 236 | + 'pluginOptions' => [ | ||
| 237 | + 'allowClear' => true, | ||
| 238 | + 'minimumInputLength' => 3, | ||
| 239 | + 'language' => [ | ||
| 240 | + 'errorLoading' => new JsExpression( | ||
| 241 | + "function () { return 'Waiting for results...'; }" | ||
| 242 | + ), | ||
| 243 | + ], | ||
| 244 | + 'ajax' => [ | ||
| 245 | + 'url' => Url::to([ '/product/list' ]), | ||
| 246 | + 'dataType' => 'json', | ||
| 247 | + 'data' => new JsExpression( | ||
| 248 | + 'function(params) { | ||
| 249 | + return { | ||
| 250 | + q:params.term | ||
| 251 | + }; | ||
| 252 | + }' | ||
| 253 | + ), | ||
| 254 | + ], | ||
| 255 | + 'escapeMarkup' => new JsExpression( | ||
| 256 | + 'function (markup) { | ||
| 257 | + return markup; | ||
| 258 | + }' | ||
| 259 | + ), | ||
| 260 | + 'templateResult' => new JsExpression( | ||
| 261 | + 'function (product) { | ||
| 262 | + return product.text; | ||
| 263 | + }' | ||
| 264 | + ), | ||
| 265 | + 'templateSelection' => new JsExpression( | ||
| 266 | + 'function (product) { | ||
| 267 | + return product.text; | ||
| 268 | + }' | ||
| 269 | + ), | ||
| 270 | + ], | ||
| 271 | + ] | ||
| 272 | + ); | ||
| 273 | + ?> | ||
| 274 | + </div> | ||
| 275 | + <?php | ||
| 276 | + } | ||
| 277 | + ?> | ||
| 278 | + | ||
| 279 | + <?= $form->field($model, 'sort') | ||
| 280 | + ->textInput() ?> | ||
| 281 | + | ||
| 282 | + <?= $form->field($model, 'status') | ||
| 283 | + ->checkbox( | ||
| 284 | + [ | ||
| 285 | + 'class' => 'flat', | ||
| 286 | + ] | ||
| 287 | + ) ?> | ||
| 288 | + | ||
| 289 | + <?= $form->field($model, 'author_id') | ||
| 290 | + ->textInput() ?> | ||
| 291 | + | ||
| 292 | + <div class="form-group"> | ||
| 293 | + <?= Html::submitButton( | ||
| 294 | + $model->isNewRecord ? 'Create' : 'Update', | ||
| 295 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | ||
| 296 | + ) ?> | ||
| 297 | + </div> | ||
| 298 | + | ||
| 299 | + <?php ActiveForm::end(); ?> | ||
| 300 | + | ||
| 301 | +</div> |
| 1 | +<?php | ||
| 2 | + use artbox\core\helpers\SlugifyDecorator; | ||
| 3 | + use artbox\weblog\models\ArticleLang; | ||
| 4 | + use artbox\core\models\Language; | ||
| 5 | + use dosamigos\tinymce\TinyMce; | ||
| 6 | + use yii\helpers\Url; | ||
| 7 | + use yii\web\JsExpression; | ||
| 8 | + use yii\web\View; | ||
| 9 | + use artbox\core\components\imagemanager\components\ImageManagerInputWidget; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * @var ArticleLang $model_lang | ||
| 14 | + * @var Language $language | ||
| 15 | + * @var ActiveForm $form | ||
| 16 | + * @var View $this | ||
| 17 | + */ | ||
| 18 | +?> | ||
| 19 | +<?php | ||
| 20 | + $attributeField = $form->field($model_lang, '[' . $language->id . ']title') | ||
| 21 | + ->textInput([ 'maxlength' => true ]); | ||
| 22 | + echo $attributeField; | ||
| 23 | +?> | ||
| 24 | + | ||
| 25 | +<?= SlugifyDecorator::decorate( | ||
| 26 | + $form->field($model_lang, '[' . $language->id . ']aliasValue'), | ||
| 27 | + [ '/alias/slugify' ], | ||
| 28 | + $attributeField, | ||
| 29 | + false, | ||
| 30 | + $language->id | ||
| 31 | +) | ||
| 32 | + ->textInput([ 'maxlength' => true ]); ?> | ||
| 33 | + | ||
| 34 | +<?= $form->field($model_lang, '[' . $language->id . ']body') | ||
| 35 | + ->widget( | ||
| 36 | + TinyMce::className(), | ||
| 37 | + [ | ||
| 38 | + 'options' => [ 'rows' => 30 ], | ||
| 39 | + 'language' => 'ru', | ||
| 40 | + 'clientOptions' => [ | ||
| 41 | + 'file_browser_callback' => new JsExpression( | ||
| 42 | + "function(field_name, url, type, win) { | ||
| 43 | +window.open('" . Url::to( | ||
| 44 | + [ | ||
| 45 | + 'imagemanager/manager', | ||
| 46 | + 'view-mode' => 'iframe', | ||
| 47 | + 'select-type' => 'tinymce', | ||
| 48 | + ] | ||
| 49 | + ) . "&tag_name='+field_name,'','width=800,height=540 ,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no'); | ||
| 50 | +}" | ||
| 51 | + ), | ||
| 52 | + 'plugins' => [ | ||
| 53 | + "advlist autolink lists link charmap print preview anchor", | ||
| 54 | + "searchreplace visualblocks code fullscreen", | ||
| 55 | + "insertdatetime media table contextmenu paste image", | ||
| 56 | + ], | ||
| 57 | + 'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code", | ||
| 58 | + 'image_advtab' => true, | ||
| 59 | + ], | ||
| 60 | + ] | ||
| 61 | + ); ?> | ||
| 62 | + | ||
| 63 | +<?= $form->field($model_lang, '[' . $language->id . ']body_preview') | ||
| 64 | + ->textarea( | ||
| 65 | + [ | ||
| 66 | + 'rows' => '10', | ||
| 67 | + ] | ||
| 68 | + ) ?> | ||
| 69 | +<?= $form->field($model_lang, '[' . $language->id . ']image_id') | ||
| 70 | + ->widget( | ||
| 71 | + ImageManagerInputWidget::className(), | ||
| 72 | + [ | ||
| 73 | + 'aspectRatio' => ( 16 / 9 ), | ||
| 74 | + //set the aspect ratio | ||
| 75 | + 'showPreview' => true, | ||
| 76 | + //false to hide the preview | ||
| 77 | + 'showDeletePickedImageConfirm' => false, | ||
| 78 | + //on true show warning before detach image | ||
| 79 | + ] | ||
| 80 | + ); ?> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use artbox\weblog\models\ArticleSearch; | ||
| 4 | + use yii\helpers\Html; | ||
| 5 | + use yii\widgets\ActiveForm; | ||
| 6 | + | ||
| 7 | + /* @var $this yii\web\View */ | ||
| 8 | + /* @var $model ArticleSearch */ | ||
| 9 | + /* @var $form yii\widgets\ActiveForm */ | ||
| 10 | +?> | ||
| 11 | + | ||
| 12 | +<div class="blog-article-search"> | ||
| 13 | + | ||
| 14 | + <?php $form = ActiveForm::begin( | ||
| 15 | + [ | ||
| 16 | + 'action' => [ 'index' ], | ||
| 17 | + 'method' => 'get', | ||
| 18 | + ] | ||
| 19 | + ); ?> | ||
| 20 | + | ||
| 21 | + <?= $form->field($model, 'id') ?> | ||
| 22 | + | ||
| 23 | + <?= $form->field($model, 'image') ?> | ||
| 24 | + | ||
| 25 | + <?= $form->field($model, 'created_at') ?> | ||
| 26 | + | ||
| 27 | + <?= $form->field($model, 'updated_at') ?> | ||
| 28 | + | ||
| 29 | + <?= $form->field($model, 'deleted_at') ?> | ||
| 30 | + | ||
| 31 | + <?php // echo $form->field($model, 'sort') ?> | ||
| 32 | + | ||
| 33 | + <?php // echo $form->field($model, 'status')->checkbox() ?> | ||
| 34 | + | ||
| 35 | + <?php // echo $form->field($model, 'author_id') ?> | ||
| 36 | + | ||
| 37 | + <div class="form-group"> | ||
| 38 | + <?= Html::submitButton('Search', [ 'class' => 'btn btn-primary' ]) ?> | ||
| 39 | + <?= Html::resetButton('Reset', [ 'class' => 'btn btn-default' ]) ?> | ||
| 40 | + </div> | ||
| 41 | + | ||
| 42 | + <?php ActiveForm::end(); ?> | ||
| 43 | + | ||
| 44 | +</div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use artbox\weblog\models\Article; | ||
| 4 | + use artbox\weblog\models\ArticleLang; | ||
| 5 | + use yii\web\View; | ||
| 6 | + use yiister\gentelella\widgets\Panel; | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * @var View $this | ||
| 10 | + * @var Article $model | ||
| 11 | + * @var ArticleLang[] $modelLangs | ||
| 12 | + * @var array $products | ||
| 13 | + * @var array $articles | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + $this->title = \Yii::t('blog', 'Create Blog Article'); | ||
| 17 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 18 | + 'label' => \Yii::t('blog', 'Blog Articles'), | ||
| 19 | + 'url' => [ 'index' ], | ||
| 20 | + ]; | ||
| 21 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
| 22 | +?> | ||
| 23 | +<div class="blog-article-create"> | ||
| 24 | + | ||
| 25 | + <?php $panel = Panel::begin( | ||
| 26 | + [ | ||
| 27 | + 'header' => $this->title, | ||
| 28 | + ] | ||
| 29 | + ); ?> | ||
| 30 | + | ||
| 31 | + <?= $this->render( | ||
| 32 | + '_form', | ||
| 33 | + [ | ||
| 34 | + 'model' => $model, | ||
| 35 | + 'modelLangs' => $modelLangs, | ||
| 36 | + ] | ||
| 37 | + ) ?> | ||
| 38 | + | ||
| 39 | + <?php $panel::end(); ?> | ||
| 40 | + | ||
| 41 | +</div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use common\models\Article; | ||
| 4 | + use common\models\ArticleSearch; | ||
| 5 | + use artbox\weblog\models\Category; | ||
| 6 | + use artbox\weblog\models\Tag; | ||
| 7 | + use yii\data\ActiveDataProvider; | ||
| 8 | + use yii\helpers\ArrayHelper; | ||
| 9 | + use yii\helpers\Html; | ||
| 10 | + use yii\grid\GridView; | ||
| 11 | + use yii\web\View; | ||
| 12 | + use yiister\gentelella\widgets\Panel; | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * @var View $this | ||
| 16 | + * @var ArticleSearch $searchModel | ||
| 17 | + * @var ActiveDataProvider $dataProvider | ||
| 18 | + */ | ||
| 19 | + | ||
| 20 | + $this->title = \Yii::t('blog', 'Blog Articles'); | ||
| 21 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
| 22 | +?> | ||
| 23 | +<div class="blog-article-index"> | ||
| 24 | + | ||
| 25 | + <?php $panel = Panel::begin( | ||
| 26 | + [ | ||
| 27 | + 'header' => $this->title, | ||
| 28 | + ] | ||
| 29 | + ); ?> | ||
| 30 | + <p> | ||
| 31 | + <?= Html::a( | ||
| 32 | + \Yii::t('app', 'create_item', [ 'item' => 'Blog Article' ]), | ||
| 33 | + [ 'create' ], | ||
| 34 | + [ 'class' => 'btn btn-success' ] | ||
| 35 | + ) ?> | ||
| 36 | + </p> | ||
| 37 | + <?= GridView::widget( | ||
| 38 | + [ | ||
| 39 | + 'dataProvider' => $dataProvider, | ||
| 40 | + 'filterModel' => $searchModel, | ||
| 41 | + 'columns' => [ | ||
| 42 | + 'id', | ||
| 43 | + [ | ||
| 44 | + 'attribute' => 'title', | ||
| 45 | + 'value' => 'lang.title', | ||
| 46 | + ], | ||
| 47 | + [ | ||
| 48 | + 'attribute' => 'category', | ||
| 49 | + 'label' => \Yii::t('blog', 'Categories'), | ||
| 50 | + 'value' => function (Article $model) { | ||
| 51 | + if (empty($model->categories)) { | ||
| 52 | + return \Yii::$app->formatter->asText(null); | ||
| 53 | + } else { | ||
| 54 | + return implode( | ||
| 55 | + ',<br>', | ||
| 56 | + ArrayHelper::getColumn( | ||
| 57 | + $model->categories, | ||
| 58 | + function (Category $category) { | ||
| 59 | + return $category->lang->title; | ||
| 60 | + } | ||
| 61 | + ) | ||
| 62 | + ); | ||
| 63 | + } | ||
| 64 | + }, | ||
| 65 | + 'format' => 'html', | ||
| 66 | + ], | ||
| 67 | + [ | ||
| 68 | + 'attribute' => 'tag', | ||
| 69 | + 'label' => \Yii::t('blog', 'Tags'), | ||
| 70 | + 'value' => function (Article $model) { | ||
| 71 | + if (empty($model->tags)) { | ||
| 72 | + return \Yii::$app->formatter->asText(null); | ||
| 73 | + } else { | ||
| 74 | + return implode( | ||
| 75 | + ',<br>', | ||
| 76 | + ArrayHelper::getColumn( | ||
| 77 | + $model->tags, | ||
| 78 | + function (Tag $tag) { | ||
| 79 | + return $tag->lang->label; | ||
| 80 | + } | ||
| 81 | + ) | ||
| 82 | + ); | ||
| 83 | + } | ||
| 84 | + }, | ||
| 85 | + 'format' => 'html', | ||
| 86 | + ], | ||
| 87 | + [ | ||
| 88 | + 'attribute' => 'image_id', | ||
| 89 | + 'value' => function (Article $model) { | ||
| 90 | + if (empty($model->image_id)) { | ||
| 91 | + return ''; | ||
| 92 | + } else { | ||
| 93 | + return $model->image->getImg( | ||
| 94 | + [ | ||
| 95 | + 'width' => '300px', | ||
| 96 | + ] | ||
| 97 | + ); | ||
| 98 | + } | ||
| 99 | + }, | ||
| 100 | + 'format' => 'html', | ||
| 101 | + ], | ||
| 102 | + [ | ||
| 103 | + 'attribute' => 'status', | ||
| 104 | + 'value' => function (Article $model) { | ||
| 105 | + return ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'); | ||
| 106 | + }, | ||
| 107 | + 'filter' => [ | ||
| 108 | + 0 => \Yii::t('blog', 'Not active'), | ||
| 109 | + 1 => \Yii::t('blog', 'Active'), | ||
| 110 | + ], | ||
| 111 | + ], | ||
| 112 | + 'created_at:date', | ||
| 113 | + 'updated_at:date', | ||
| 114 | + [ 'class' => 'yii\grid\ActionColumn' ], | ||
| 115 | + ], | ||
| 116 | + ] | ||
| 117 | + ); ?> | ||
| 118 | + | ||
| 119 | + <?php $panel::end(); ?> | ||
| 120 | + | ||
| 121 | +</div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use artbox\weblog\models\Article; | ||
| 4 | + use artbox\weblog\models\ArticleLang; | ||
| 5 | + use yii\web\View; | ||
| 6 | + use yiister\gentelella\widgets\Panel; | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * @var View $this | ||
| 10 | + * @var Article $model | ||
| 11 | + * @var ArticleLang[] $modelLangs | ||
| 12 | + */ | ||
| 13 | + | ||
| 14 | + $this->title = \Yii::t('blog', 'Update Blog Article: ') . $model->lang->title; | ||
| 15 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 16 | + 'label' => \Yii::t('blog', 'Blog Articles'), | ||
| 17 | + 'url' => [ 'index' ], | ||
| 18 | + ]; | ||
| 19 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 20 | + 'label' => $model->lang->title, | ||
| 21 | + 'url' => [ | ||
| 22 | + 'view', | ||
| 23 | + 'id' => $model->id, | ||
| 24 | + ], | ||
| 25 | + ]; | ||
| 26 | + $this->params[ 'breadcrumbs' ][] = \Yii::t('blog', 'Update'); | ||
| 27 | +?> | ||
| 28 | +<div class="blog-article-update"> | ||
| 29 | + | ||
| 30 | + <?php $panel = Panel::begin( | ||
| 31 | + [ | ||
| 32 | + 'header' => $this->title, | ||
| 33 | + ] | ||
| 34 | + ); ?> | ||
| 35 | + | ||
| 36 | + <?= $this->render( | ||
| 37 | + '_form', | ||
| 38 | + [ | ||
| 39 | + 'model' => $model, | ||
| 40 | + 'modelLangs' => $modelLangs, | ||
| 41 | + ] | ||
| 42 | + ) ?> | ||
| 43 | + | ||
| 44 | + <?php $panel::end(); ?> | ||
| 45 | + | ||
| 46 | +</div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use common\models\Article; | ||
| 4 | + use yii\helpers\Html; | ||
| 5 | + use yii\web\View; | ||
| 6 | + use yii\widgets\DetailView; | ||
| 7 | + use yiister\gentelella\widgets\Panel; | ||
| 8 | + | ||
| 9 | + /** | ||
| 10 | + * @var View $this | ||
| 11 | + * @var Article $model | ||
| 12 | + */ | ||
| 13 | + | ||
| 14 | + $this->title = $model->lang->title; | ||
| 15 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 16 | + 'label' => \Yii::t('blog', 'Blog Articles'), | ||
| 17 | + 'url' => [ 'index' ], | ||
| 18 | + ]; | ||
| 19 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
| 20 | +?> | ||
| 21 | +<div class="blog-article-view"> | ||
| 22 | + | ||
| 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> | ||
| 53 | + | ||
| 54 | + <?= DetailView::widget( | ||
| 55 | + [ | ||
| 56 | + 'model' => $model, | ||
| 57 | + 'attributes' => [ | ||
| 58 | + 'id', | ||
| 59 | + [ | ||
| 60 | + 'attribute' => 'image_id', | ||
| 61 | + 'value' => function (Article $model) { | ||
| 62 | + if (empty($model->lang->image_id)) { | ||
| 63 | + return ''; | ||
| 64 | + } else { | ||
| 65 | + return $model->lang->image->getImg( | ||
| 66 | + [ | ||
| 67 | + 'width' => '500px', | ||
| 68 | + ] | ||
| 69 | + ); | ||
| 70 | + } | ||
| 71 | + }, | ||
| 72 | + 'format' => 'html', | ||
| 73 | + ], | ||
| 74 | + 'created_at:date', | ||
| 75 | + 'updated_at:date', | ||
| 76 | + [ | ||
| 77 | + 'attribute' => 'status', | ||
| 78 | + 'value' => ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'), | ||
| 79 | + ], | ||
| 80 | + 'lang.body:html', | ||
| 81 | + ], | ||
| 82 | + ] | ||
| 83 | + ) ?> | ||
| 84 | + | ||
| 85 | + <?php $panel::end(); ?> | ||
| 86 | + | ||
| 87 | +</div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace common\models; | ||
| 4 | + | ||
| 5 | + use artbox\core\behaviors\ManyToManyBehavior; | ||
| 6 | + use artbox\core\models\Image; | ||
| 7 | + use artbox\webcomment\models\CommentModel; | ||
| 8 | + use artbox\weblog\models\ArticleToProduct; | ||
| 9 | + use artbox\weblog\models\Category; | ||
| 10 | + use artbox\weblog\models\Tag; | ||
| 11 | + use yii\behaviors\TimestampBehavior; | ||
| 12 | + use yii\db\ActiveRecord; | ||
| 13 | + use artbox\core\behaviors\LanguageBehavior; | ||
| 14 | + use artbox\core\models\Language; | ||
| 15 | + use yii\db\ActiveQuery; | ||
| 16 | + use yii\db\Query; | ||
| 17 | + use yii\helpers\Url; | ||
| 18 | + use yii\web\Request; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * This is the model class for table "blog_article". | ||
| 22 | + * | ||
| 23 | + * @property integer $id | ||
| 24 | + * @property Image $image | ||
| 25 | + * @property integer $created_at | ||
| 26 | + * @property integer $updated_at | ||
| 27 | + * @property integer $deleted_at | ||
| 28 | + * @property integer $sort | ||
| 29 | + * @property boolean $status | ||
| 30 | + * @property integer $author_id | ||
| 31 | + * @property integer $image_id | ||
| 32 | + * @property ArticleLang[] $blogArticleLangs | ||
| 33 | + * @property Language[] $languages | ||
| 34 | + * @property Article[] $relatedBlogArticles | ||
| 35 | + * @property Article[] $articles | ||
| 36 | + * @property Category[] $categories | ||
| 37 | + * @property Category $category | ||
| 38 | + * @property Tag[] $tags | ||
| 39 | + * @property \artbox\catalog\models\Product[] $relatedProducts | ||
| 40 | + * * * From language behavior * | ||
| 41 | + * @property ArticleLang $lang | ||
| 42 | + * @property ArticleLang[] $langs | ||
| 43 | + * @property ArticleLang $objectLang | ||
| 44 | + * @property string $ownerKey | ||
| 45 | + * @property string $langKey | ||
| 46 | + * @property ArticleLang[] $modelLangs | ||
| 47 | + * @property bool $transactionStatus | ||
| 48 | + * @method string getOwnerKey() | ||
| 49 | + * @method void setOwnerKey( string $value ) | ||
| 50 | + * @method string getLangKey() | ||
| 51 | + * @method void setLangKey( string $value ) | ||
| 52 | + * @method ActiveQuery getLangs() | ||
| 53 | + * @method ActiveQuery getLang( integer $language_id ) | ||
| 54 | + * @method ArticleLang[] generateLangs() | ||
| 55 | + * @method void loadLangs( Request $request ) | ||
| 56 | + * @method bool linkLangs() | ||
| 57 | + * @method bool saveLangs() | ||
| 58 | + * @method bool getTransactionStatus() | ||
| 59 | + * @method bool loadWithLangs( Request $request ) | ||
| 60 | + * @method bool saveWithLangs() | ||
| 61 | + * * End language behavior * | ||
| 62 | + * @method void linkMany( string $link, array $models ) | ||
| 63 | + */ | ||
| 64 | + class Article extends ActiveRecord | ||
| 65 | + { | ||
| 66 | + public $categoryIds = []; | ||
| 67 | + | ||
| 68 | + public $tagIds = []; | ||
| 69 | + | ||
| 70 | + public $articleIds = []; | ||
| 71 | + | ||
| 72 | + public $productIds = []; | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * @inheritdoc | ||
| 76 | + */ | ||
| 77 | + public static function tableName() | ||
| 78 | + { | ||
| 79 | + return 'blog_article'; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public function behaviors() | ||
| 83 | + { | ||
| 84 | + return [ | ||
| 85 | + [ | ||
| 86 | + 'class' => TimestampBehavior::className(), | ||
| 87 | + ], | ||
| 88 | + 'language' => [ | ||
| 89 | + 'class' => LanguageBehavior::className(), | ||
| 90 | + ], | ||
| 91 | + [ | ||
| 92 | + 'class' => ManyToManyBehavior::className(), | ||
| 93 | + ], | ||
| 94 | + ]; | ||
| 95 | + } | ||
| 96 | + /** | ||
| 97 | + * @inheritdoc | ||
| 98 | + */ | ||
| 99 | + public function rules() | ||
| 100 | + { | ||
| 101 | + return [ | ||
| 102 | + [ | ||
| 103 | + [ | ||
| 104 | + 'created_at', | ||
| 105 | + 'updated_at', | ||
| 106 | + 'deleted_at', | ||
| 107 | + 'sort', | ||
| 108 | + 'author_id', | ||
| 109 | + 'image_id', | ||
| 110 | + ], | ||
| 111 | + 'integer', | ||
| 112 | + ], | ||
| 113 | + [ | ||
| 114 | + [ 'status' ], | ||
| 115 | + 'boolean', | ||
| 116 | + ], | ||
| 117 | + ]; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * @inheritdoc | ||
| 122 | + */ | ||
| 123 | + public function attributeLabels() | ||
| 124 | + { | ||
| 125 | + return [ | ||
| 126 | + 'id' => 'ID', | ||
| 127 | + 'image' => 'Image', | ||
| 128 | + 'created_at' => 'Created At', | ||
| 129 | + 'updated_at' => 'Updated At', | ||
| 130 | + 'deleted_at' => 'Deleted At', | ||
| 131 | + 'sort' => 'Sort', | ||
| 132 | + 'status' => 'Status', | ||
| 133 | + 'author_id' => 'Author ID', | ||
| 134 | + ]; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + /** | ||
| 138 | + * @return \yii\db\ActiveQuery | ||
| 139 | + */ | ||
| 140 | + public function getRelatedBlogArticles() | ||
| 141 | + { | ||
| 142 | + return $this->hasMany(Article::className(), [ 'id' => 'related_blog_article_id' ]) | ||
| 143 | + ->viaTable('blog_article_to_article', [ 'blog_article_id' => 'id' ]); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * @return Query | ||
| 148 | + */ | ||
| 149 | + public function getRelatedProducts() | ||
| 150 | + { | ||
| 151 | + if (class_exists('\artbox\catalog\models\Product')) { | ||
| 152 | + return $this->hasMany('\artbox\catalog\models\Product', [ 'id' => 'product_id' ]) | ||
| 153 | + ->via('articleToProduct'); | ||
| 154 | + } else { | ||
| 155 | + return ( new Query() )->where('1 = 0'); | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + public function getCommentsCount() | ||
| 160 | + { | ||
| 161 | + | ||
| 162 | + if (class_exists('\artbox\webcomment\models\CommentModel')) { | ||
| 163 | + $comments = CommentModel::find()->where("status = 1 and entity = 'artbox\weblog\models\Article' and entity_id = ".$this->id)->count(); | ||
| 164 | + return $comments; | ||
| 165 | + } else { | ||
| 166 | + return null; | ||
| 167 | + } | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * @return Query | ||
| 172 | + */ | ||
| 173 | + public function getArticleToProduct() | ||
| 174 | + { | ||
| 175 | + | ||
| 176 | + if (class_exists('\artbox\catalog\models\Product')) { | ||
| 177 | + return $this->hasMany(ArticleToProduct::className(), [ 'article_id' => 'id' ]); | ||
| 178 | + } else { | ||
| 179 | + return ( new Query() )->where('1 = 0'); | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + /** | ||
| 184 | + * @return \yii\db\ActiveQuery | ||
| 185 | + */ | ||
| 186 | + public function getImage() | ||
| 187 | + { | ||
| 188 | + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + /** | ||
| 192 | + * @return \yii\db\ActiveQuery | ||
| 193 | + */ | ||
| 194 | + public function getArticles() | ||
| 195 | + { | ||
| 196 | + return $this->hasMany(Article::className(), [ 'id' => 'blog_article_id' ]) | ||
| 197 | + ->viaTable('blog_article_to_article', [ 'related_blog_article_id' => 'id' ]); | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + /** | ||
| 201 | + * @return \yii\db\ActiveQuery | ||
| 202 | + */ | ||
| 203 | + public function getCategories() | ||
| 204 | + { | ||
| 205 | + return $this->hasMany(Category::className(), [ 'id' => 'blog_category_id' ]) | ||
| 206 | + ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + /** | ||
| 210 | + * @return \yii\db\ActiveQuery | ||
| 211 | + */ | ||
| 212 | + public function getCategory() | ||
| 213 | + { | ||
| 214 | + return $this->hasOne(Category::className(), [ 'id' => 'blog_category_id' ]) | ||
| 215 | + ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + /** | ||
| 219 | + * @return \yii\db\ActiveQuery | ||
| 220 | + */ | ||
| 221 | + public function getTags() | ||
| 222 | + { | ||
| 223 | + return $this->hasMany(Tag::className(), [ 'id' => 'blog_tag_id' ]) | ||
| 224 | + ->viaTable('blog_article_to_tag', [ 'blog_article_id' => 'id' ]); | ||
| 225 | + } | ||
| 226 | + } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace common\models; | ||
| 4 | + | ||
| 5 | + use artbox\core\behaviors\SlugBehavior; | ||
| 6 | + use artbox\core\models\Alias; | ||
| 7 | + use artbox\core\models\Language; | ||
| 8 | + use artbox\core\models\Image; | ||
| 9 | + use yii\db\ActiveRecord; | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * This is the model class for table "blog_article_lang". | ||
| 13 | + | ||
| 14 | + * | ||
| 15 | +*@property integer $id | ||
| 16 | + * @property integer $blog_article_id | ||
| 17 | + * @property integer $language_id | ||
| 18 | + * @property string $title | ||
| 19 | + * @property string $body | ||
| 20 | + * @property string $body_preview | ||
| 21 | + * @property string $meta_title | ||
| 22 | + * @property string $meta_description | ||
| 23 | + * @property string $h1 | ||
| 24 | + * @property string $seo_text | ||
| 25 | + * @property Article $article | ||
| 26 | + * @property Language $language | ||
| 27 | + * @property Alias $alias | ||
| 28 | + */ | ||
| 29 | + class ArticleLang extends ActiveRecord | ||
| 30 | + { | ||
| 31 | + /** | ||
| 32 | + * @inheritdoc | ||
| 33 | + */ | ||
| 34 | + public static function tableName() | ||
| 35 | + { | ||
| 36 | + return 'blog_article_lang'; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public function behaviors() | ||
| 40 | + { | ||
| 41 | + return [ | ||
| 42 | + 'slug' => [ | ||
| 43 | + 'class' => SlugBehavior::className(), | ||
| 44 | + 'action' => 'blog/article', | ||
| 45 | + 'params' => [ | ||
| 46 | + 'id' => 'blog_article_id', | ||
| 47 | + ], | ||
| 48 | + 'fields' => [ | ||
| 49 | + 'title' => 'Article title', | ||
| 50 | + ], | ||
| 51 | + ], | ||
| 52 | + ]; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * @inheritdoc | ||
| 57 | + */ | ||
| 58 | + public function rules() | ||
| 59 | + { | ||
| 60 | + return [ | ||
| 61 | + [ | ||
| 62 | + [ | ||
| 63 | + 'blog_article_id', | ||
| 64 | + 'language_id', | ||
| 65 | + 'title', | ||
| 66 | + ], | ||
| 67 | + 'required', | ||
| 68 | + ], | ||
| 69 | + [ | ||
| 70 | + [ | ||
| 71 | + 'blog_article_id', | ||
| 72 | + 'language_id', | ||
| 73 | + 'image_id', | ||
| 74 | + ], | ||
| 75 | + 'integer', | ||
| 76 | + ], | ||
| 77 | + [ | ||
| 78 | + [ | ||
| 79 | + 'body', | ||
| 80 | + 'body_preview', | ||
| 81 | + ], | ||
| 82 | + 'string', | ||
| 83 | + ], | ||
| 84 | + [ | ||
| 85 | + [ | ||
| 86 | + 'title', | ||
| 87 | + ], | ||
| 88 | + 'string', | ||
| 89 | + 'max' => 255, | ||
| 90 | + ], | ||
| 91 | + | ||
| 92 | + [ | ||
| 93 | + [ | ||
| 94 | + 'blog_article_id', | ||
| 95 | + 'language_id', | ||
| 96 | + ], | ||
| 97 | + 'unique', | ||
| 98 | + 'targetAttribute' => [ | ||
| 99 | + 'blog_article_id', | ||
| 100 | + 'language_id', | ||
| 101 | + ], | ||
| 102 | + 'message' => 'The combination of Blog Article ID and Language ID has already been taken.', | ||
| 103 | + ], | ||
| 104 | + [ | ||
| 105 | + [ 'blog_article_id' ], | ||
| 106 | + 'exist', | ||
| 107 | + 'skipOnError' => true, | ||
| 108 | + 'targetClass' => Article::className(), | ||
| 109 | + 'targetAttribute' => [ 'blog_article_id' => 'id' ], | ||
| 110 | + ], | ||
| 111 | + [ | ||
| 112 | + [ 'language_id' ], | ||
| 113 | + 'exist', | ||
| 114 | + 'skipOnError' => true, | ||
| 115 | + 'targetClass' => Language::className(), | ||
| 116 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
| 117 | + ], | ||
| 118 | + ]; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 122 | + * @inheritdoc | ||
| 123 | + */ | ||
| 124 | + public function attributeLabels() | ||
| 125 | + { | ||
| 126 | + return [ | ||
| 127 | + 'id' => 'ID', | ||
| 128 | + 'blog_article_id' => 'Blog Article ID', | ||
| 129 | + 'language_id' => 'Language ID', | ||
| 130 | + 'title' => 'Title', | ||
| 131 | + 'body' => 'Body', | ||
| 132 | + 'body_preview' => 'Body Preview', | ||
| 133 | + 'alias' => 'Alias', | ||
| 134 | + 'meta_title' => 'Meta Title', | ||
| 135 | + 'meta_description' => 'Meta Description', | ||
| 136 | + 'h1' => 'H1', | ||
| 137 | + 'seo_text' => 'Seo Text', | ||
| 138 | + ]; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + /** | ||
| 142 | + * @return \yii\db\ActiveQuery | ||
| 143 | + */ | ||
| 144 | + public function getArticle() | ||
| 145 | + { | ||
| 146 | + return $this->hasOne(Article::className(), [ 'id' => 'blog_article_id' ]); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + /** | ||
| 150 | + * @return \yii\db\ActiveQuery | ||
| 151 | + */ | ||
| 152 | + public function getImage() | ||
| 153 | + { | ||
| 154 | + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * @return \yii\db\ActiveQuery | ||
| 159 | + */ | ||
| 160 | + public function getLanguage() | ||
| 161 | + { | ||
| 162 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + /** | ||
| 166 | + * @return \yii\db\ActiveQuery | ||
| 167 | + */ | ||
| 168 | + public function getAlias() | ||
| 169 | + { | ||
| 170 | + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]); | ||
| 171 | + } | ||
| 172 | + } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace common\models; | ||
| 4 | + | ||
| 5 | + use yii\base\Model; | ||
| 6 | + use yii\data\ActiveDataProvider; | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * BlogArticleSearch represents the model behind the search form about `artweb\artbox\blog\models\BlogArticle`. | ||
| 10 | + */ | ||
| 11 | + class ArticleSearch extends Article | ||
| 12 | + { | ||
| 13 | + /** | ||
| 14 | + * @var string | ||
| 15 | + */ | ||
| 16 | + public $title; | ||
| 17 | + | ||
| 18 | + public $tag; | ||
| 19 | + | ||
| 20 | + public $category; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * @inheritdoc | ||
| 24 | + */ | ||
| 25 | + public function rules() | ||
| 26 | + { | ||
| 27 | + return [ | ||
| 28 | + [ | ||
| 29 | + [ | ||
| 30 | + 'id', | ||
| 31 | + 'deleted_at', | ||
| 32 | + 'sort', | ||
| 33 | + 'author_id', | ||
| 34 | + ], | ||
| 35 | + 'integer', | ||
| 36 | + ], | ||
| 37 | + [ | ||
| 38 | + [ 'status' ], | ||
| 39 | + 'boolean', | ||
| 40 | + ], | ||
| 41 | + [ | ||
| 42 | + [ | ||
| 43 | + 'title', | ||
| 44 | + 'tag', | ||
| 45 | + 'category', | ||
| 46 | + ], | ||
| 47 | + 'string', | ||
| 48 | + ], | ||
| 49 | + ]; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * @inheritdoc | ||
| 54 | + */ | ||
| 55 | + public function behaviors() | ||
| 56 | + { | ||
| 57 | + return []; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * @inheritdoc | ||
| 62 | + */ | ||
| 63 | + public function scenarios() | ||
| 64 | + { | ||
| 65 | + // bypass scenarios() implementation in the parent class | ||
| 66 | + return Model::scenarios(); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * Creates data provider instance with search query applied | ||
| 71 | + * | ||
| 72 | + * @param array $params | ||
| 73 | + * | ||
| 74 | + * @return ActiveDataProvider | ||
| 75 | + */ | ||
| 76 | + public function search($params) | ||
| 77 | + { | ||
| 78 | + $query = Article::find() | ||
| 79 | + ->joinWith( | ||
| 80 | + [ | ||
| 81 | + 'lang', | ||
| 82 | + | ||
| 83 | + ] | ||
| 84 | + ) | ||
| 85 | + ->with( | ||
| 86 | + [ | ||
| 87 | + 'tags.lang', | ||
| 88 | + 'categories.lang', | ||
| 89 | + ] | ||
| 90 | + ); | ||
| 91 | + | ||
| 92 | + // add conditions that should always apply here | ||
| 93 | + | ||
| 94 | + $dataProvider = new ActiveDataProvider( | ||
| 95 | + [ | ||
| 96 | + 'query' => $query, | ||
| 97 | + 'sort' => [ | ||
| 98 | + 'attributes' => [ | ||
| 99 | + 'id', | ||
| 100 | + 'created_at', | ||
| 101 | + 'updated_at', | ||
| 102 | + 'title' => [ | ||
| 103 | + 'asc' => [ 'blog_article_lang.title' => SORT_ASC ], | ||
| 104 | + 'desc' => [ 'blog_article_lang.title' => SORT_DESC ], | ||
| 105 | + ], | ||
| 106 | + ], | ||
| 107 | + ], | ||
| 108 | + ] | ||
| 109 | + ); | ||
| 110 | + | ||
| 111 | + $this->load($params); | ||
| 112 | + | ||
| 113 | + if (!$this->validate()) { | ||
| 114 | + // uncomment the following line if you do not want to return any records when validation fails | ||
| 115 | + // $query->where('0=1'); | ||
| 116 | + return $dataProvider; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + // grid filtering conditions | ||
| 120 | + $query->andFilterWhere( | ||
| 121 | + [ | ||
| 122 | + 'blog_article.id' => $this->id, | ||
| 123 | + 'blog_article.status' => $this->status, | ||
| 124 | + 'author_id' => $this->author_id, | ||
| 125 | + ] | ||
| 126 | + ); | ||
| 127 | + | ||
| 128 | + $query->andFilterWhere( | ||
| 129 | + [ | ||
| 130 | + 'ilike', | ||
| 131 | + 'blog_article_lang.title', | ||
| 132 | + $this->title, | ||
| 133 | + ] | ||
| 134 | + ); | ||
| 135 | + | ||
| 136 | + $query->andFilterWhere( | ||
| 137 | + [ | ||
| 138 | + 'ilike', | ||
| 139 | + 'blog_tag_lang.label', | ||
| 140 | + $this->tag, | ||
| 141 | + ] | ||
| 142 | + ); | ||
| 143 | + | ||
| 144 | + $query->andFilterWhere( | ||
| 145 | + [ | ||
| 146 | + 'ilike', | ||
| 147 | + 'blog_category_lang.title', | ||
| 148 | + $this->category, | ||
| 149 | + ] | ||
| 150 | + ); | ||
| 151 | + | ||
| 152 | + return $dataProvider; | ||
| 153 | + } | ||
| 154 | + } |
console/migrations/m180306_103852_add_image_id_column_to_blog_article_lang.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Migration; | ||
| 4 | + | ||
| 5 | +class m180306_103852_add_image_id_column_to_blog_article_lang extends Migration | ||
| 6 | +{ | ||
| 7 | + public function up() | ||
| 8 | + { | ||
| 9 | + $this->addColumn('blog_article_lang', 'image_id', $this->integer()); | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + public function down() | ||
| 13 | + { | ||
| 14 | + $this->dropColumn('blog_article_lang', 'image_id'); | ||
| 15 | + } | ||
| 16 | +} |
frontend/controllers/BlogController.php
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | use yii\helpers\Html; | 5 | use yii\helpers\Html; |
| 6 | use yii\helpers\Url; | 6 | use yii\helpers\Url; |
| 7 | use yii\web\Controller; | 7 | use yii\web\Controller; |
| 8 | - use artbox\weblog\models\Article; | 8 | + use common\models\Article; |
| 9 | use yii\web\NotFoundHttpException; | 9 | use yii\web\NotFoundHttpException; |
| 10 | use yii\db\ActiveQuery; | 10 | use yii\db\ActiveQuery; |
| 11 | 11 | ||
| @@ -40,6 +40,7 @@ | @@ -40,6 +40,7 @@ | ||
| 40 | { | 40 | { |
| 41 | 41 | ||
| 42 | $query = Article::find() | 42 | $query = Article::find() |
| 43 | + ->with('lang.image') | ||
| 43 | ->where( | 44 | ->where( |
| 44 | [ | 45 | [ |
| 45 | 'status' => true, | 46 | 'status' => true, |
| @@ -67,12 +68,14 @@ | @@ -67,12 +68,14 @@ | ||
| 67 | protected function findModel($id) | 68 | protected function findModel($id) |
| 68 | { | 69 | { |
| 69 | $model = Article::find() | 70 | $model = Article::find() |
| 70 | - ->where( | 71 | + ->with('lang.image') |
| 72 | + | ||
| 73 | + ->where( | ||
| 71 | [ | 74 | [ |
| 72 | 'id' => $id | 75 | 'id' => $id |
| 73 | ] | 76 | ] |
| 74 | ) | 77 | ) |
| 75 | - ->with("lang") | 78 | + ->with("lang.image") |
| 76 | ->one(); | 79 | ->one(); |
| 77 | 80 | ||
| 78 | if ( $model !== NULL) { | 81 | if ( $model !== NULL) { |
| @@ -92,7 +95,7 @@ | @@ -92,7 +95,7 @@ | ||
| 92 | if (!empty($req->post("title"))){ | 95 | if (!empty($req->post("title"))){ |
| 93 | $title = Html::encode($req->post("title")); | 96 | $title = Html::encode($req->post("title")); |
| 94 | $query = Article::find() | 97 | $query = Article::find() |
| 95 | - ->joinWith("lang") | 98 | + ->joinWith("lang.image") |
| 96 | ->where( | 99 | ->where( |
| 97 | [ | 100 | [ |
| 98 | 'status' => true, | 101 | 'status' => true, |
| @@ -116,7 +119,7 @@ | @@ -116,7 +119,7 @@ | ||
| 116 | public function actionCategory($id) { | 119 | public function actionCategory($id) { |
| 117 | 120 | ||
| 118 | $query = Article::find() | 121 | $query = Article::find() |
| 119 | - ->joinWith("categories.lang") | 122 | + ->joinWith(["categories.lang", 'lang.image']) |
| 120 | ->where( | 123 | ->where( |
| 121 | [ | 124 | [ |
| 122 | 'blog_article.status' => true, | 125 | 'blog_article.status' => true, |
| @@ -135,7 +138,7 @@ | @@ -135,7 +138,7 @@ | ||
| 135 | 138 | ||
| 136 | public function actionTag($id){ | 139 | public function actionTag($id){ |
| 137 | $query = Article::find() | 140 | $query = Article::find() |
| 138 | - ->joinWith("tags.lang") | 141 | + ->joinWith(["tags.lang", 'lang.image']) |
| 139 | ->where( | 142 | ->where( |
| 140 | [ | 143 | [ |
| 141 | 'blog_article.status' => true, | 144 | 'blog_article.status' => true, |
frontend/views/blog/_article_item.php
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | * @var Article $model | 7 | * @var Article $model |
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | - use artbox\weblog\models\Article; | 10 | + use common\models\Article; |
| 11 | use yii\helpers\Url; | 11 | use yii\helpers\Url; |
| 12 | 12 | ||
| 13 | ?> | 13 | ?> |
| @@ -62,7 +62,7 @@ | @@ -62,7 +62,7 @@ | ||
| 62 | ] | 62 | ] |
| 63 | )?>" | 63 | )?>" |
| 64 | > | 64 | > |
| 65 | - <?=$model->image->getImg( | 65 | + <?=$model->lang->image->getImg( |
| 66 | [ | 66 | [ |
| 67 | 'class' => "img-responsive" | 67 | 'class' => "img-responsive" |
| 68 | ] | 68 | ] |
frontend/views/blog/view.php
| @@ -45,7 +45,7 @@ | @@ -45,7 +45,7 @@ | ||
| 45 | <div id="post-content" class="post-blog"> | 45 | <div id="post-content" class="post-blog"> |
| 46 | 46 | ||
| 47 | <p> | 47 | <p> |
| 48 | - <?= $article->image->getImg( | 48 | + <?= $article->lang->image->getImg( |
| 49 | [ | 49 | [ |
| 50 | 'class' => "img-responsive", | 50 | 'class' => "img-responsive", |
| 51 | ] | 51 | ] |