diff --git a/controllers/ArticleController.php b/controllers/ArticleController.php index f7e814e..085d796 100755 --- a/controllers/ArticleController.php +++ b/controllers/ArticleController.php @@ -1,9 +1,9 @@ generateLangs(); - // $categories = ArrayHelper::map( - // BlogCategory::find() - // ->joinWith('lang') - // ->all(), - // 'id', - // 'lang.title' - // ); - // - // $tags = ArrayHelper::map( - // BlogTag::find() - // ->joinWith('lang') - // ->all(), - // 'id', - // 'lang.label' - // ); - - if ($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request); - if ($model->save() && $model->transactionStatus) { - - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] )) { - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] as $item) { - if ($category = BlogCategory::findOne($item)) { - $model->link('blogCategories', $category); - } - } - } - - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogTags' ] )) { - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogTags' ] as $item) { - if ($category = BlogTag::findOne($item)) { - $model->link('blogTags', $category); - } - } - } - - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'products' ] )) { - foreach (\Yii::$app->request->post('BlogArticle')[ 'products' ] as $item) { - if ($product = Product::findOne($item)) { - $model->link('products', $product); - } - } - } - - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] )) { - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] as $item) { - if ($article = Product::findOne($item)) { - $model->link('blogArticles', $article); - } - } - } - - return $this->redirect( - [ - 'view', - 'id' => $model->id, - ] - ); - } + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { + + $categories = Category::find() + ->where([ 'id' => \Yii::$app->request->post('categoryIds') ]) + ->all(); + + $model->linkMany('categories', $categories); + + $tags = Tag::find() + ->where( + [ + 'id' => \Yii::$app->request->post('tagIds'), + ] + ) + ->all(); + + $model->linkMany('tags', $tags); + + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); } + return $this->render( 'create', [ 'model' => $model, 'modelLangs' => $model->modelLangs, - // 'categories' => $categories, - // 'tags' => $tags, - 'products' => [], - 'articles' => [], ] ); @@ -174,98 +136,55 @@ { $model = $this->findModel($id); $model->generateLangs(); - - $categories = ArrayHelper::map( - BlogCategory::find() - ->joinWith('lang') - ->all(), + + $model->categoryIds = ArrayHelper::map( + $model->categories, 'id', 'lang.title' ); - - $tags = ArrayHelper::map( - BlogTag::find() - ->joinWith('lang') - ->all(), + + $model->tagIds = ArrayHelper::map( + $model->tags, 'id', 'lang.label' ); - - $products = ArrayHelper::map( - $model->getProducts() - ->joinWith('lang') - ->asArray() - ->all(), - 'id', - 'lang.title' - ); - - $articles = ArrayHelper::map( - $model->getBlogArticles() - ->joinWith('lang') - ->asArray() - ->all(), + + $model->articleIds = ArrayHelper::map( + $model->articles, 'id', 'lang.title' ); - - if ($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request); - if ($model->save() && $model->transactionStatus) { - - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] )) { - $model->unlinkAll('blogCategories', true); - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] as $item) { - if ($category = BlogCategory::findOne($item)) { - $model->link('blogCategories', $category); - } - } - } - - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogTags' ] )) { - $model->unlinkAll('blogTags', true); - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogTags' ] as $item) { - if ($tag = BlogTag::findOne($item)) { - $model->link('blogTags', $tag); - } - } - } - - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'products' ] )) { - $model->unlinkAll('products', true); - foreach (\Yii::$app->request->post('BlogArticle')[ 'products' ] as $item) { - if ($product = Product::findOne($item)) { - $model->link('products', $product); - } - } - } - - if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] )) { - $model->unlinkAll('blogArticles', true); - foreach (\Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] as $item) { - if ($article = BlogArticle::findOne($item)) { - $model->link('blogArticles', $article); - } - } - } - - return $this->redirect( - [ - 'view', - 'id' => $model->id, - ] - ); - } + + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { + $categories = Category::find() + ->where([ 'id' => \Yii::$app->request->post('categoryIds') ]) + ->all(); + + $model->linkMany('categories', $categories); + + $tags = Tag::find() + ->where( + [ + 'id' => \Yii::$app->request->post('tagIds'), + ] + ) + ->all(); + + $model->linkMany('tags', $tags); + + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } return $this->render( 'update', [ 'model' => $model, 'modelLangs' => $model->modelLangs, - 'categories' => $categories, - 'tags' => $tags, - 'products' => $products, - 'articles' => $articles, ] ); @@ -290,9 +209,8 @@ /** * Finds the BlogArticle model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. - -* -*@param integer $id + * + * @param integer $id * *@return Article the loaded model * @throws NotFoundHttpException if the model cannot be found @@ -305,59 +223,6 @@ throw new NotFoundHttpException('The requested page does not exist.'); } } - - public function actionList($q = null, $id = null) - { - \Yii::$app->response->format = Response::FORMAT_JSON; - $out = [ - 'results' => [ - [ - 'id' => '', - 'text' => '', - ], - ], - ]; - if (!is_null($q)) { - $categories = Article::find() - ->joinWith('lang') - ->select( - [ - 'id', - 'text' => 'category_lang.title', - ] - ) - ->filterWhere( - [ - '!=', - 'id', - $id, - ] - ) - ->andFilterWhere( - [ - 'like', - 'category_lang.title', - $q, - ] - ) - ->andFilterWhere( - [ - '!=', - 'parent_id', - $id, - ] - ) - ->limit(20) - ->asArray() - ->all(); - - if (!empty($categories)) { - $out[ 'results' ] = $categories; - } - } - - return $out; - } /** * @param string $q @@ -365,7 +230,7 @@ * * @return array */ - public function actionArticleList($q = NULL, $id = NULL) + public function actionList(string $q = null, int $id = null) { \Yii::$app->response->format = Response::FORMAT_JSON; $out = [ @@ -375,31 +240,31 @@ ], ]; if (!is_null($q)) { - $out[ 'results' ] = BlogArticle::find() - ->joinWith('lang') - ->select( - [ - 'blog_article.id as id', - 'blog_article_lang.title as text', - ] - ) - ->where( - [ - 'like', - 'blog_article_lang.title', - $q, - ] - ) - ->andWhere( - [ - '!=', - 'blog_article.id', - $id, - ] - ) - ->limit(20) - ->asArray() - ->all(); + $out[ 'results' ] = Article::find() + ->joinWith('lang') + ->select( + [ + 'blog_article.id as id', + 'blog_article_lang.title as text', + ] + ) + ->where( + [ + 'like', + 'blog_article_lang.title', + $q, + ] + ) + ->andFilterWhere( + [ + '!=', + 'blog_article.id', + $id, + ] + ) + ->limit(20) + ->asArray() + ->all(); } return $out; } diff --git a/controllers/CategoryController.php b/controllers/CategoryController.php index d4157ac..0f4480a 100755 --- a/controllers/CategoryController.php +++ b/controllers/CategoryController.php @@ -2,12 +2,14 @@ namespace artbox\weblog\controllers; + use artbox\weblog\models\Category; use artbox\weblog\models\CategorySearch; use Yii; use yii\helpers\ArrayHelper; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; + use yii\web\Response; /** * BlogCategoryController implements the CRUD actions for BlogCategory model. @@ -81,31 +83,28 @@ */ public function actionCreate() { - $model = new BlogCategory(); + $model = new Category(); $model->generateLangs(); $parentCategories = ArrayHelper::map( - BlogCategory::find() - ->joinWith('lang') - ->where( - [ - 'parent_id' => 0, - ] - ) - ->all(), + Category::find() + ->joinWith('lang') + ->where( + [ + 'parent_id' => 0, + ] + ) + ->all(), 'id', 'lang.title' ); - if ($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request); - if ($model->save() && $model->transactionStatus) { - return $this->redirect( - [ - 'view', - 'id' => $model->id, - ] - ); - } + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); } return $this->render( 'create', @@ -131,35 +130,32 @@ $model = $this->findModel($id); $model->generateLangs(); $parentCategories = ArrayHelper::map( - BlogCategory::find() - ->joinWith('lang') - ->where( - [ - 'parent_id' => 0, - ] - ) - ->andWhere( - [ - '!=', - BlogCategory::tableName() . '_id', - $model->id, - ] - ) - ->all(), + Category::find() + ->joinWith('lang') + ->where( + [ + 'parent_id' => 0, + ] + ) + ->andWhere( + [ + '!=', + Category::tableName() . '_id', + $model->id, + ] + ) + ->all(), 'id', 'lang.title' ); - - if ($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request); - if ($model->save() && $model->transactionStatus) { - return $this->redirect( - [ - 'view', - 'id' => $model->id, - ] - ); - } + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } return $this->render( 'update', @@ -184,30 +180,62 @@ { $this->findModel($id) ->delete(); - + return $this->redirect([ 'index' ]); } - public function actionDeleteImage($id) + public function actionList(string $q = null) { - $model = $this->findModel($id); - $model->image = null; - $model->updateAttributes(['image']); - return true; + \Yii::$app->response->format = Response::FORMAT_JSON; + $out = [ + 'results' => [ + [ + 'id' => '', + 'text' => '', + ], + ], + ]; + if (!is_null($q)) { + $categories = Category::find() + ->joinWith('lang') + ->select( + [ + 'id' => 'blog_category.id', + 'text' => 'blog_category_lang.title', + ] + ) + ->andFilterWhere( + [ + 'like', + 'blog_category_lang.title', + $q, + ] + ) + ->limit(20) + ->asArray() + ->all(); + + if (!empty($categories)) { + $out[ 'results' ] = $categories; + } + } + + return $out; } /** * Finds the BlogCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. + * - * @param integer $id +*@param integer $id * - * @return BlogCategory the loaded model + * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { - if (( $model = BlogCategory::findOne($id) ) !== NULL) { + if (( $model = Category::findOne($id) ) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); diff --git a/controllers/TagController.php b/controllers/TagController.php index ad217ec..f313d3a 100755 --- a/controllers/TagController.php +++ b/controllers/TagController.php @@ -1,13 +1,15 @@ search(Yii::$app->request->queryParams); - + return $this->render( 'index', [ @@ -51,7 +53,7 @@ ] ); } - + /** * Displays a single BlogTag model. * @@ -68,7 +70,7 @@ ] ); } - + /** * Creates a new BlogTag model. * If creation is successful, the browser will be redirected to the 'view' page. @@ -77,13 +79,12 @@ */ public function actionCreate() { - $model = new BlogTag(); + $model = new Tag(); $model->generateLangs(); - + if (\Yii::$app->request->isPost) { $model->loadLangs(\Yii::$app->request); - $model->markAttributeDirty('id'); - if ($model->save() && $model->transactionStatus) { + if ($model->saveWithLangs()) { return $this->redirect( [ 'view', @@ -99,9 +100,9 @@ 'modelLangs' => $model->modelLangs, ] ); - - } + } + /** * Updates an existing BlogTag model. * If update is successful, the browser will be redirected to the 'view' page. @@ -114,11 +115,10 @@ { $model = $this->findModel($id); $model->generateLangs(); - + if (Yii::$app->request->isPost) { $model->loadLangs(\Yii::$app->request); - $model->markAttributeDirty('id'); - if ($model->save() && $model->transactionStatus) { + if ($model->saveWithLangs()) { return $this->redirect( [ 'view', @@ -134,9 +134,9 @@ 'modelLangs' => $model->modelLangs, ] ); - - } + } + /** * Deletes an existing BlogTag model. * If deletion is successful, the browser will be redirected to the 'index' page. @@ -149,22 +149,61 @@ { $this->findModel($id) ->delete(); - + return $this->redirect([ 'index' ]); } + + public function actionList(string $q = null) + { + \Yii::$app->response->format = Response::FORMAT_JSON; + $out = [ + 'results' => [ + [ + 'id' => '', + 'text' => '', + ], + ], + ]; + if (!is_null($q)) { + $categories = Tag::find() + ->joinWith('lang') + ->select( + [ + 'id' => 'blog_tag.id', + 'text' => 'blog_tag_lang.label', + ] + ) + ->andFilterWhere( + [ + 'like', + 'blog_tag_lang.label', + $q, + ] + ) + ->limit(20) + ->asArray() + ->all(); + + if (!empty($categories)) { + $out[ 'results' ] = $categories; + } + } + return $out; + } + /** * Finds the BlogTag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * - * @param integer $id +*@param integer $id * - * @return BlogTag the loaded model + * @return Tag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { - if (( $model = BlogTag::findOne($id) ) !== NULL) { + if (( $model = Tag::findOne($id) ) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); diff --git a/models/Article.php b/models/Article.php index 6fa62c1..b7e56f9 100755 --- a/models/Article.php +++ b/models/Article.php @@ -2,7 +2,9 @@ namespace artbox\weblog\models; + use artbox\catalog\behaviors\ManyToManyBehavior; use artbox\catalog\models\Product; + use artbox\core\models\Image; use yii\behaviors\TimestampBehavior; use yii\db\ActiveRecord; use artbox\core\behaviors\LanguageBehavior; @@ -12,31 +14,33 @@ /** * This is the model class for table "blog_article". - * -*@property integer $id - * @property string $image - * @property integer $created_at - * @property integer $updated_at - * @property integer $deleted_at - * @property integer $sort - * @property boolean $status - * @property integer $author_id - * @property ArticleLang[] $blogArticleLangs - * @property Language[] $languages - * @property Article[] $relatedBlogArticles - * @property Article[] $blogArticles - * @property BlogCategory[] $blogCategories - * @property BlogCategory $blogCategory - * @property Product[] $products - * @property BlogTag[] $blogTags + +* +*@property integer $id + * @property Image $image + * @property integer $created_at + * @property integer $updated_at + * @property integer $deleted_at + * @property integer $sort + * @property boolean $status + * @property integer $author_id + * @property integer $image_id + * @property ArticleLang[] $blogArticleLangs + * @property Language[] $languages + * @property Article[] $relatedBlogArticles + * @property Article[] $articles + * @property Category[] $categories + * @property Category $category + * @property Product[] $products + * @property Tag[] $tags * * * From language behavior * - * @property ArticleLang $lang - * @property ArticleLang[] $langs - * @property ArticleLang $objectLang - * @property string $ownerKey - * @property string $langKey - * @property ArticleLang[] $modelLangs - * @property bool $transactionStatus + * @property ArticleLang $lang + * @property ArticleLang[] $langs + * @property ArticleLang $objectLang + * @property string $ownerKey + * @property string $langKey + * @property ArticleLang[] $modelLangs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -48,16 +52,19 @@ * @method bool linkLangs() * @method bool saveLangs() * @method bool getTransactionStatus() + * @method bool loadWithLangs( Request $request ) + * @method bool saveWithLangs() * * End language behavior * - * * From SaveImgBehavior - * @property string|null $imageFile - * @property string|null $imageUrl - * @method string|null getImageFile( int $field ) - * @method string|null getImageUrl( int $field ) - * * End SaveImgBehavior + * @method void linkMany( string $link, array $models ) */ class Article extends ActiveRecord { + public $categoryIds = []; + + public $tagIds = []; + + public $articleIds = []; + /** * @inheritdoc */ @@ -75,6 +82,9 @@ 'language' => [ 'class' => LanguageBehavior::className(), ], + [ + 'class' => ManyToManyBehavior::className(), + ], ]; } /** @@ -130,6 +140,14 @@ /** * @return \yii\db\ActiveQuery */ + public function getImage() + { + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ public function getArticles() { return $this->hasMany(Article::className(), [ 'id' => 'blog_article_id' ]) @@ -139,19 +157,19 @@ /** * @return \yii\db\ActiveQuery */ - public function getBlogCategories() + public function getCategories() { - return $this->hasMany(BlogCategory::className(), [ 'id' => 'blog_category_id' ]) + return $this->hasMany(Category::className(), [ 'id' => 'blog_category_id' ]) ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); } /** * @return \yii\db\ActiveQuery */ - public function getBlogCategory() + public function getCategory() { - return $this->hasOne(BlogCategory::className(), [ 'id' => 'blog_category_id' ]) - ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); + return $this->hasOne(Category::className(), [ 'id' => 'blog_category_id' ]) + ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); } /** @@ -160,15 +178,15 @@ public function getProducts() { return $this->hasMany(Product::className(), [ 'id' => 'product_id' ]) - ->viaTable('blog_article_to_product', [ 'blog_article_id' => 'id' ]); + ->viaTable('blog_article_to_product', [ 'blog_article_id' => 'id' ]); } /** * @return \yii\db\ActiveQuery */ - public function getBlogTags() + public function getTags() { - return $this->hasMany(BlogTag::className(), [ 'id' => 'blog_tag_id' ]) - ->viaTable('blog_article_to_tag', [ 'blog_article_id' => 'id' ]); + return $this->hasMany(Tag::className(), [ 'id' => 'blog_tag_id' ]) + ->viaTable('blog_article_to_tag', [ 'blog_article_id' => 'id' ]); } } diff --git a/models/Category.php b/models/Category.php index 337b13b..45b1125 100755 --- a/models/Category.php +++ b/models/Category.php @@ -1,49 +1,52 @@ 255, - ], - [ [ 'parent_id' ], 'default', 'value' => 0, ], ]; } - + /** * @inheritdoc */ @@ -113,18 +112,29 @@ 'status' => 'Status', ]; } - + /** * @return \yii\db\ActiveQuery */ - public function getBlogArticles() + public function getArticles() { - return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ]) + return $this->hasMany(Article::className(), [ 'id' => 'blog_article_id' ]) ->viaTable('blog_article_to_category', [ 'blog_category_id' => 'id' ]); } - + + /** + * @return \yii\db\ActiveQuery + */ public function getParent() { - return $this->hasOne(BlogCategory::className(), [ 'id' => 'parent_id' ]); + return $this->hasOne(Category::className(), [ 'id' => 'parent_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getImage() + { + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); } } diff --git a/models/CategoryLang.php b/models/CategoryLang.php index 35a259f..e6ede7d 100755 --- a/models/CategoryLang.php +++ b/models/CategoryLang.php @@ -8,19 +8,13 @@ /** * This is the model class for table "blog_category_lang". - -* + * * @property integer $id * @property integer $blog_category_id * @property integer $language_id * @property string $title - * @property string $alias * @property string $description - * @property string $meta_title - * @property string $meta_description - * @property string $h1 - * @property string $seo_text - * @property Category $blogCategory + * @property Category $category * @property Language $language */ class CategoryLang extends ActiveRecord @@ -59,6 +53,7 @@ [ 'blog_category_id', 'language_id', + 'title', ], 'required', ], @@ -76,20 +71,11 @@ [ [ 'title', - 'alias', - 'meta_title', - 'meta_description', - 'h1', - 'seo_text', ], 'string', 'max' => 255, ], [ - [ 'alias' ], - 'unique', - ], - [ [ 'blog_category_id', 'language_id', @@ -105,7 +91,7 @@ [ 'blog_category_id' ], 'exist', 'skipOnError' => true, - 'targetClass' => BlogCategory::className(), + 'targetClass' => Category::className(), 'targetAttribute' => [ 'blog_category_id' => 'id' ], ], [ @@ -140,9 +126,9 @@ /** * @return \yii\db\ActiveQuery */ - public function getBlogCategory() + public function getCategory() { - return $this->hasOne(BlogCategory::className(), [ 'id' => 'blog_category_id' ]); + return $this->hasOne(Category::className(), [ 'id' => 'blog_category_id' ]); } /** diff --git a/models/Tag.php b/models/Tag.php index c2e3c37..2acf6b3 100755 --- a/models/Tag.php +++ b/models/Tag.php @@ -10,31 +10,32 @@ /** * This is the model class for table "blog_tag". - -* -*@property integer $id - * @property Article[] $blogArticles - * @property BlogTagLang[] $blogTagLangs - * @property Language[] $languages + * + * @property integer $id + * @property Article[] $articles + * @property TagLang[] $blogTagLangs + * @property Language[] $languages * * From language behavior * - * @property BlogTagLang $lang - * @property BlogTagLang[] $langs - * @property BlogTagLang $objectLang - * @property string $ownerKey - * @property string $langKey - * @property BlogTagLang[] $modelLangs - * @property bool $transactionStatus + * @property TagLang $lang + * @property TagLang[] $langs + * @property TagLang $objectLang + * @property string $ownerKey + * @property string $langKey + * @property TagLang[] $modelLangs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() * @method void setLangKey( string $value ) * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) - * @method BlogTagLang[] generateLangs() + * @method TagLang[] generateLangs() * @method void loadLangs( Request $request ) * @method bool linkLangs() * @method bool saveLangs() * @method bool getTransactionStatus() + * @method bool saveWithLangs() + * @method bool loadWithLangs( Request $request ) * * End language behavior * */ class Tag extends ActiveRecord @@ -85,7 +86,7 @@ /** * @return \yii\db\ActiveQuery */ - public function getBlogArticles() + public function getArticles() { return $this->hasMany(Article::className(), [ 'id' => 'blog_article_id' ]) ->viaTable('blog_article_to_tag', [ 'blog_tag_id' => 'id' ]); diff --git a/models/TagLang.php b/models/TagLang.php index 8388a04..c8332e5 100755 --- a/models/TagLang.php +++ b/models/TagLang.php @@ -1,15 +1,15 @@ [ + 'class' => SlugBehavior::className(), + 'action' => 'tag/view', + 'params' => [ + 'id' => 'blog_tag_id', + ], + 'fields' => [ + 'label' => \Yii::t('blog', 'Tag label'), + ], + 'inAttribute' => 'label', + ], + ]; + } + /** * @inheritdoc */ @@ -79,7 +100,7 @@ ], ]; } - + /** * @inheritdoc */ @@ -92,15 +113,15 @@ 'label' => 'Label', ]; } - + /** * @return \yii\db\ActiveQuery */ - public function getBlogTag() + public function getTag() { return $this->hasOne(Tag::className(), [ 'id' => 'blog_tag_id' ]); } - + /** * @return \yii\db\ActiveQuery */ diff --git a/views/blog-article/_form.php b/views/blog-article/_form.php index fef4680..b353b2a 100755 --- a/views/blog-article/_form.php +++ b/views/blog-article/_form.php @@ -2,9 +2,8 @@ use artbox\weblog\models\Article; use artbox\weblog\models\ArticleLang; - - // use artweb\artbox\blog\models\BlogCategory; - // use artweb\artbox\blog\models\BlogTag; + use artbox\weblog\models\Category; + use artbox\weblog\models\Tag; use kartik\select2\Select2; use noam148\imagemanager\components\ImageManagerInputWidget; use yii\helpers\Html; @@ -15,14 +14,14 @@ use yii\web\JsExpression; /** - * @var View $this - * @var Article $model - * @var ActiveForm $form - * @var ArticleLang[] $modelLangs - * @var BlogCategory[] $categories - * @var BlogTag[] $tags - * @var array $products - * @var array $articles + * @var View $this + * @var Article $model + * @var ActiveForm $form + * @var ArticleLang[] $modelLangs + * @var Category[] $categories + * @var Tag[] $tags + * @var array $products + * @var array $articles */ ?> @@ -43,42 +42,110 @@ ] ); ?> - - field($model, 'blogCategories') - // ->widget( - // Select2::className(), - // [ - // 'data' => $categories, - // 'theme' => Select2::THEME_BOOTSTRAP, - // 'options' => [ - // 'placeholder' => \Yii::t('blog', 'Select category'), - // 'multiple' => true, - // ], - // 'pluginOptions' => [ - // 'allowClear' => true, - // ], - // ] - // ); - ?> - - field($model, 'blogTags') - // ->widget( - // Select2::className(), - // [ - // 'data' => $tags, - // 'theme' => Select2::THEME_BOOTSTRAP, - // 'options' => [ - // 'placeholder' => \Yii::t('blog', 'Select tag'), - // 'multiple' => true, - // ], - // 'pluginOptions' => [ - // 'allowClear' => true, - // ], - // ] - // ); - ?> + +
- = Html::a( - 'Update', - [ - 'update', - 'id' => $model->id, - ], - [ 'class' => 'btn btn-primary' ] - ) ?> - = Html::a( - 'Delete', - [ - 'delete', - 'id' => $model->id, - ], - [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', - 'method' => 'post', - ], - ] - ) ?> -
+ $this->title, + ] + ); ?> + ++ = Html::a( + 'Update', + [ + 'update', + 'id' => $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + = Html::a( + 'Delete', + [ + 'delete', + 'id' => $model->id, + ], + [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ] + ) ?> +
= DetailView::widget( [ 'model' => $model, 'attributes' => [ 'id', - 'imageUrl:image', + [ + 'attribute' => 'image_id', + 'value' => function (Article $model) { + if (empty($model->image_id)) { + return ''; + } else { + return $model->image->getImg( + [ + 'width' => '500px', + ] + ); + } + }, + 'format' => 'html', + ], 'created_at:date', 'updated_at:date', [ 'attribute' => 'status', 'value' => ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'), ], - 'lang.alias', 'lang.body:html', ], ] ) ?> + +- = Html::a( - 'Update', - [ - 'update', - 'id' => $model->id, - ], - [ 'class' => 'btn btn-primary' ] - ) ?> - = Html::a( - 'Delete', - [ - 'delete', - 'id' => $model->id, - ], - [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', - 'method' => 'post', - ], - ] - ) ?> -
+ $this->title, + ] + ); ?> + ++ = Html::a( + 'Update', + [ + 'update', + 'id' => $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + = Html::a( + 'Delete', + [ + 'delete', + 'id' => $model->id, + ], + [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ] + ) ?> +
= DetailView::widget( [ 'model' => $model, 'attributes' => [ 'id', + 'lang.title', 'sort', - 'imageUrl:image', [ 'attribute' => 'parent_id', - 'value' => ( !empty( $model->parent ) ) ? $model->parent->lang->title : '', + 'value' => ( !empty($model->parent) ) ? $model->parent->lang->title : '', ], - 'lang.alias', 'lang.description:text', [ 'attribute' => 'status', @@ -66,5 +70,7 @@ ], ] ) ?> + +- = Html::a( - 'Update', - [ - 'update', - 'id' => $model->id, - ], - [ 'class' => 'btn btn-primary' ] - ) ?> - = Html::a( - 'Delete', - [ - 'delete', - 'id' => $model->id, - ], - [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', - 'method' => 'post', - ], - ] - ) ?> -
+ $this->title, + ] + ); ?> + ++ = Html::a( + 'Update', + [ + 'update', + 'id' => $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + = Html::a( + 'Delete', + [ + 'delete', + 'id' => $model->id, + ], + [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ] + ) ?> +
= DetailView::widget( [ @@ -55,5 +60,7 @@ ], ] ) ?> + +