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, - // ], - // ] - // ); - ?> + +
+ + 'categoryIds', + 'options' => [ + 'placeholder' => \Yii::t('blog', 'Search for a categories ...'), + 'multiple' => true, + ], + 'value' => array_keys($model->categoryIds), + 'data' => $model->categoryIds, + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'language' => [ + 'errorLoading' => new JsExpression( + "function () { return 'Waiting for results...'; }" + ), + ], + 'ajax' => [ + 'url' => Url::to([ '/blog-category/list' ]), + 'dataType' => 'json', + 'data' => new JsExpression( + 'function(params) { + return { + q:params.term + }; + }' + ), + ], + 'escapeMarkup' => new JsExpression( + 'function (markup) { + return markup; + }' + ), + 'templateResult' => new JsExpression( + 'function (brand) { + return brand.text; + }' + ), + 'templateSelection' => new JsExpression( + 'function (brand) { + return brand.text; + }' + ), + ], + ] + ); + ?> +
+ +
+ + 'tagIds', + 'options' => [ + 'placeholder' => \Yii::t('blog', 'Search for a tags ...'), + 'multiple' => true, + ], + 'value' => array_keys($model->tagIds), + 'data' => $model->tagIds, + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'language' => [ + 'errorLoading' => new JsExpression( + "function () { return 'Waiting for results...'; }" + ), + ], + 'ajax' => [ + 'url' => Url::to([ '/blog-tag/list' ]), + 'dataType' => 'json', + 'data' => new JsExpression( + 'function(params) { + return { + q:params.term + }; + }' + ), + ], + 'escapeMarkup' => new JsExpression( + 'function (markup) { + return markup; + }' + ), + 'templateResult' => new JsExpression( + 'function (brand) { + return brand.text; + }' + ), + 'templateSelection' => new JsExpression( + 'function (brand) { + return brand.text; + }' + ), + ], + ] + ); + ?> +
field($model, 'image_id') ->widget( @@ -92,73 +159,63 @@ //on true show warning before detach image ] ); ?> - - field($model, 'products') - // ->widget( - // Select2::className(), - // [ - // 'data' => $products, - // 'options' => [ - // 'placeholder' => \Yii::t('blog', 'Select related products'), - // 'multiple' => true, - // ], - // 'pluginOptions' => [ - // 'allowClear' => true, - // 'minimumInputLength' => 3, - // 'language' => [ - // 'errorLoading' => new JsExpression( - // "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }" - // ), - // ], - // 'ajax' => [ - // 'url' => yii\helpers\Url::to([ '/blog/blog-article/product-list' ]), - // 'dataType' => 'json', - // 'data' => new JsExpression('function(params) { return {q:params.term}; }'), - // ], - // 'templateResult' => new JsExpression('function(product) { return product.text; }'), - // 'templateSelection' => new JsExpression('function (product) { return product.text; }'), - // ], - // ] - // ); - ?> - - id )) { - // $data = 'function(params) { return {q:params.term}; }'; - // } else { - // $data = 'function(params) { return {q:params.term, id:' . $model->id . '}; }'; - // } - // echo $form->field($model, 'blogArticles') - // ->widget( - // Select2::className(), - // [ - // 'data' => $articles, - // 'options' => [ - // 'placeholder' => \Yii::t('blog', 'Select related articles'), - // 'multiple' => true, - // ], - // 'pluginOptions' => [ - // 'allowClear' => true, - // 'minimumInputLength' => 3, - // 'language' => [ - // 'errorLoading' => new JsExpression( - // "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }" - // ), - // ], - // 'ajax' => [ - // 'url' => yii\helpers\Url::to([ '/blog/blog-article/article-list' ]), - // 'dataType' => 'json', - // 'data' => new JsExpression( - // $data - // ), - // ], - // 'templateResult' => new JsExpression('function(article) { return article.text; }'), - // 'templateSelection' => new JsExpression('function (article) { return article.text; }'), - // ], - // ] - // ); - ?> + +
+ + isNewRecord) { + $condition = ''; + } else { + $condition = ', id: ' . $model->id; + } + echo Select2::widget( + [ + 'name' => 'articleIds', + 'options' => [ + 'placeholder' => \Yii::t('blog', 'Search for an articles ...'), + 'multiple' => true, + ], + 'value' => array_keys($model->articleIds), + 'data' => $model->articleIds, + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'language' => [ + 'errorLoading' => new JsExpression( + "function () { return 'Waiting for results...'; }" + ), + ], + 'ajax' => [ + 'url' => Url::to([ '/blog-article/list' ]), + 'dataType' => 'json', + 'data' => new JsExpression( + 'function(params) { + return { + q:params.term' . $condition . ' + }; + }' + ), + ], + 'escapeMarkup' => new JsExpression( + 'function (markup) { + return markup; + }' + ), + 'templateResult' => new JsExpression( + 'function (brand) { + return brand.text; + }' + ), + 'templateSelection' => new JsExpression( + 'function (brand) { + return brand.text; + }' + ), + ], + ] + ); + ?> +
field($model, 'sort') ->textInput() ?> @@ -172,13 +229,13 @@ field($model, 'author_id') ->textInput() ?> - -
- isNewRecord ? 'Create' : 'Update', - [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] - ) ?> -
+ +
+ isNewRecord ? 'Create' : 'Update', + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] + ) ?> +
diff --git a/views/blog-article/create.php b/views/blog-article/create.php index dcec804..14ff913 100755 --- a/views/blog-article/create.php +++ b/views/blog-article/create.php @@ -33,10 +33,6 @@ [ 'model' => $model, 'modelLangs' => $modelLangs, - // 'categories' => $categories, - // 'tags' => $tags, - 'products' => $products, - 'articles' => $articles, ] ) ?> diff --git a/views/blog-article/index.php b/views/blog-article/index.php index 89c90b8..a56822e 100755 --- a/views/blog-article/index.php +++ b/views/blog-article/index.php @@ -41,13 +41,24 @@ 'attribute' => 'title', 'value' => 'lang.title', ], - 'imageUrl:image', + [ + 'attribute' => 'image_id', + 'value' => function (Article $model) { + if (empty($model->image_id)) { + return ''; + } else { + return $model->image->getImg( + [ + 'width' => '300px', + ] + ); + } + }, + 'format' => 'html', + ], [ 'attribute' => 'status', - 'value' => function ($model) { - /** - * @var Article $model - */ + 'value' => function (Article $model) { return ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'); }, 'filter' => [ @@ -63,5 +74,5 @@ ); ?> - + diff --git a/views/blog-article/update.php b/views/blog-article/update.php index 97ad490..b352f7d 100755 --- a/views/blog-article/update.php +++ b/views/blog-article/update.php @@ -1,20 +1,14 @@ title = \Yii::t('blog', 'Update Blog Article: ') . $model->lang->title; @@ -33,18 +27,20 @@ ?>
-

title) ?>

+ $this->title, + ] + ); ?> render( '_form', [ 'model' => $model, 'modelLangs' => $modelLangs, - 'categories' => $categories, - 'tags' => $tags, - 'products' => $products, - 'articles' => $articles, ] ) ?> + +
diff --git a/views/blog-article/view.php b/views/blog-article/view.php index 90f8d6a..7a5147d 100755 --- a/views/blog-article/view.php +++ b/views/blog-article/view.php @@ -1,13 +1,14 @@ title = $model->lang->title; @@ -19,49 +20,68 @@ ?>
-

title) ?>

- -

- $model->id, - ], - [ 'class' => 'btn btn-primary' ] - ) ?> - $model->id, - ], - [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', - 'method' => 'post', - ], - ] - ) ?> -

+ $this->title, + ] + ); ?> + +

+ $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + $model->id, + ], + [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ] + ) ?> +

$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', ], ] ) ?> + +
diff --git a/views/blog-category/_form.php b/views/blog-category/_form.php index 0511cd1..672bfb7 100755 --- a/views/blog-category/_form.php +++ b/views/blog-category/_form.php @@ -1,20 +1,20 @@ @@ -31,40 +31,22 @@ echo LanguageForm::widget( [ 'modelLangs' => $modelLangs, - 'formView' => '@artweb/artbox/blog/views/blog-category/_form_language', + 'formView' => '@artbox/weblog/views/blog-category/_form_language', 'form' => $form, ] ); ?> - field($model, 'image') + field($model, 'image_id') ->widget( - \kartik\file\FileInput::className(), + ImageManagerInputWidget::className(), [ - 'language' => 'ru', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => false, - 'deleteurl' => $model->isNewRecord?false:Url::to(['/blog/blog-category/delete-image', 'id' => $model->id]), - 'class' => $model->isNewRecord?'':'artbox-delete-file', - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => [ - 'jpg', - 'gif', - 'png', - ], - 'initialPreview' => !empty( $model->getImageUrl(0, false) ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( - $model->imageUrl, - 'list' - ) : '', - 'initialPreviewShowDelete' => false, - 'overwriteInitial' => true, - 'showRemove' => true, - 'showUpload' => false, - 'showClose' => false, - 'previewFileType' => 'image', - ], + 'aspectRatio' => ( 16 / 9 ), + //set the aspect ratio + 'showPreview' => true, + //false to hide the preview + 'showDeletePickedImageConfirm' => false, + //on true show warning before detach image ] ); ?> @@ -85,14 +67,18 @@ ?> field($model, 'status') - ->checkbox() ?> - -
- isNewRecord ? 'Create' : 'Update', - [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] - ) ?> -
+ ->checkbox( + [ + 'class' => 'flat', + ] + ) ?> + +
+ isNewRecord ? 'Create' : 'Update', + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] + ) ?> +
diff --git a/views/blog-category/_form_language.php b/views/blog-category/_form_language.php index 3f804a4..b5d435c 100755 --- a/views/blog-category/_form_language.php +++ b/views/blog-category/_form_language.php @@ -1,21 +1,27 @@ -field($model_lang, '[' . $language->id . ']title') - ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->id . ']title') + ->textInput([ 'maxlength' => true ]); ?> -field($model_lang, '[' . $language->id . ']alias') - ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->id . ']aliasValue'), + [ '/alias/slugify' ], + $attributeField +) + ->textInput([ 'maxlength' => true ]); ?> field($model_lang, '[' . $language->id . ']description') ->textarea( @@ -23,15 +29,3 @@ 'rows' => '10', ] ) ?> - -field($model_lang, '[' . $language->id . ']meta_title') - ->textInput([ 'maxlength' => true ]); ?> - -field($model_lang, '[' . $language->id . ']meta_description') - ->textInput([ 'maxlength' => true ]); ?> - -field($model_lang, '[' . $language->id . ']seo_text') - ->textInput([ 'maxlength' => true ]); ?> - -field($model_lang, '[' . $language->id . ']h1') - ->textInput([ 'maxlength' => true ]); ?> diff --git a/views/blog-category/create.php b/views/blog-category/create.php index 81bfa8d..09d1282 100755 --- a/views/blog-category/create.php +++ b/views/blog-category/create.php @@ -1,15 +1,15 @@ title = \Yii::t('blog', 'Create Blog Category'); @@ -21,7 +21,11 @@ ?>
-

title) ?>

+ $this->title, + ] + ) ?> render( '_form', @@ -31,5 +35,7 @@ 'parentCategories' => $parentCategories, ] ) ?> + +
diff --git a/views/blog-category/index.php b/views/blog-category/index.php index ee13bd1..ed1bb24 100755 --- a/views/blog-category/index.php +++ b/views/blog-category/index.php @@ -1,5 +1,7 @@ 'title', 'value' => 'lang.title', ], - 'imageUrl:image', + [ + 'attribute' => 'image_id', + 'value' => function (Category $model) { + if (empty($model->image_id)) { + return ''; + } else { + } + return $model->image->getImg( + [ + 'width' => '300px', + ] + ); + }, + 'format' => 'html', + ], [ 'label' => \Yii::t('blog', 'Parent category'), - 'value' => function ($model) { - /** - * @var BlogCategory $model - */ + 'value' => function (Category $model) { if (!empty($model->parent)) { return $model->parent->lang->title; } else { return false; - }; + } }, ], [ 'attribute' => 'status', - 'value' => function ($model) { - /** - * @var BlogCategory $model - */ + 'value' => function (Category $model) { return ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'); }, 'filter' => [ diff --git a/views/blog-category/update.php b/views/blog-category/update.php index 6818f17..adfc6bf 100755 --- a/views/blog-category/update.php +++ b/views/blog-category/update.php @@ -1,15 +1,15 @@ title = \Yii::t('blog', 'Update Blog Category: ') . $model->lang->title; @@ -28,7 +28,11 @@ ?>
-

title) ?>

+ $this->title, + ] + ); ?> render( '_form', @@ -38,5 +42,7 @@ 'parentCategories' => $parentCategories, ] ) ?> + +
diff --git a/views/blog-category/view.php b/views/blog-category/view.php index 34ef334..95fe1c0 100755 --- a/views/blog-category/view.php +++ b/views/blog-category/view.php @@ -1,13 +1,14 @@ title = $model->lang->title; @@ -19,45 +20,48 @@ ?>
-

title) ?>

- -

- $model->id, - ], - [ 'class' => 'btn btn-primary' ] - ) ?> - $model->id, - ], - [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', - 'method' => 'post', - ], - ] - ) ?> -

+ $this->title, + ] + ); ?> + +

+ $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + $model->id, + ], + [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ] + ) ?> +

$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 @@ ], ] ) ?> + +
diff --git a/views/blog-tag/_form.php b/views/blog-tag/_form.php index 720832c..a8f485c 100755 --- a/views/blog-tag/_form.php +++ b/views/blog-tag/_form.php @@ -1,17 +1,18 @@ @@ -23,7 +24,7 @@ echo LanguageForm::widget( [ 'modelLangs' => $modelLangs, - 'formView' => '@artweb/artbox/blog/views/blog-tag/_form_language', + 'formView' => '@artbox/weblog/views/blog-tag/_form_language', 'form' => $form, ] ); diff --git a/views/blog-tag/_form_language.php b/views/blog-tag/_form_language.php index ef7adba..a6bd3a1 100755 --- a/views/blog-tag/_form_language.php +++ b/views/blog-tag/_form_language.php @@ -1,14 +1,15 @@ field($model_lang, '[' . $language->id . ']label') diff --git a/views/blog-tag/create.php b/views/blog-tag/create.php index caddd30..cc1ef7d 100755 --- a/views/blog-tag/create.php +++ b/views/blog-tag/create.php @@ -1,14 +1,14 @@ title = \Yii::t('blog', 'Create Blog Tag'); @@ -20,7 +20,11 @@ ?>
-

title) ?>

+ $this->title, + ] + ); ?> render( '_form', @@ -29,5 +33,7 @@ 'modelLangs' => $modelLangs, ] ) ?> + +
diff --git a/views/blog-tag/update.php b/views/blog-tag/update.php index 90d8c9a..c2d40df 100755 --- a/views/blog-tag/update.php +++ b/views/blog-tag/update.php @@ -1,14 +1,14 @@ title = \Yii::t('blog', 'Update Blog Tag: ') . $model->lang->label; @@ -27,7 +27,11 @@ ?>
-

title) ?>

+ $this->title, + ] + ); ?> render( '_form', @@ -36,5 +40,7 @@ 'modelLangs' => $modelLangs, ] ) ?> - + + +
diff --git a/views/blog-tag/view.php b/views/blog-tag/view.php index f11884b..457cc43 100755 --- a/views/blog-tag/view.php +++ b/views/blog-tag/view.php @@ -1,13 +1,14 @@ title = $model->lang->label; @@ -19,32 +20,36 @@ ?>
-

title) ?>

- -

- $model->id, - ], - [ 'class' => 'btn btn-primary' ] - ) ?> - $model->id, - ], - [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', - 'method' => 'post', - ], - ] - ) ?> -

+ $this->title, + ] + ); ?> + +

+ $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + $model->id, + ], + [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ] + ) ?> +

+ +
-- libgit2 0.21.4