public function actionAddBasic($articleId, $languageId)
 {
     if (!empty($articleId)) {
         $article = Article::findOne($articleId);
         $article_translation = ArticleTranslation::find()->where(['article_id' => $articleId, 'language_id' => $languageId])->one();
         if (empty($article_translation)) {
             $article_translation = new ArticleTranslation();
         }
     } else {
         $article = new Article();
         $article_translation = new ArticleTranslation();
     }
     if (Yii::$app->request->isPost) {
         $article->load(Yii::$app->request->post());
         $article_translation->load(Yii::$app->request->post());
         if ($article->validate() && $article_translation->validate()) {
             $article->save();
             $article_translation->article_id = $article->id;
             $article_translation->language_id = $languageId;
             $article_translation->save();
             Yii::$app->getSession()->setFlash('success', 'Data were successfully modified.');
         } else {
             Yii::$app->getSession()->setFlash('danger', 'Failed to change the record.');
         }
     }
     if (\Yii::$app->request->isPjax) {
         return $this->renderPartial('add-basic', ['article' => $article, 'article_translation' => $article_translation, 'categories' => Category::find()->with('translations')->all(), 'selectedLanguage' => Language::findOne($languageId), 'languages' => Language::findAll(['active' => true])]);
     } else {
         return $this->render('save', ['article' => $article, 'languageId' => $languageId, 'viewName' => 'add-basic', 'params' => ['article' => $article, 'article_translation' => $article_translation, 'categories' => Category::find()->with('translations')->all(), 'selectedLanguage' => Language::findOne($languageId), 'languages' => Language::findAll(['active' => true])]]);
     }
 }
 public static function getOneArticle($id)
 {
     $model = Category::find()->andWhere(['id' => $id])->one();
     if (empty($model->id)) {
         return $id;
     }
     return $model;
 }
 public function actionSwitchShow($id)
 {
     /* @var Category $article */
     if ($article = Category::findOne($id)) {
         $article->show = !$article->show;
         $article->save();
     }
     return $this->redirect(Url::to(['/articles/category']));
 }
Пример #4
0
 public function init()
 {
     if ($this->renderCategories) {
         $categories = Category::findAll(['parent_id' => $this->categoryId, 'show' => true]);
         $this->items = array_merge($this->items, $this->handleCategories($categories));
     }
     if ($this->renderArticles) {
         $articles = Article::find()->where(['category_id' => $this->categoryId, 'show' => true])->orderBy(['position' => SORT_ASC])->all();
         $this->items = array_merge($this->items, $this->handleArticles($articles));
     }
     parent::init();
 }
 public function actionIndex($id)
 {
     /* @var Category $category */
     $category = Category::findOne($id);
     $categoryTranslation = $category->translation;
     if (!empty($categoryTranslation->seoTitle)) {
         $this->view->title = $categoryTranslation->seoTitle;
     } else {
         $this->view->title = $categoryTranslation->name;
     }
     $this->view->registerMetaTag(['name' => 'description', 'content' => html_entity_decode($categoryTranslation->seoDescription)]);
     $this->view->registerMetaTag(['name' => 'keywords', 'content' => html_entity_decode($categoryTranslation->seoKeywords)]);
     return $this->render(!empty($category->view) ? $category->view : 'index', ['category' => $category]);
 }
Пример #6
0
 /**
  * Creates a URL according to the given route and parameters.
  * @param UrlManager $manager the URL manager
  * @param string $route the route. It should not have slashes at the beginning or the end.
  * @param array $params the parameters
  * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL.
  */
 public function createUrl($manager, $route, $params)
 {
     if (($route == $this->articleRoute || $route == $this->categoryRoute) && !empty($params['id'])) {
         $id = $params['id'];
         $pathInfo = '';
         $parentId = null;
         $language = Language::findOne(['lang_id' => $manager->language]);
         if ($route == $this->articleRoute) {
             $article = Article::findOne($id);
             if ($article->getTranslation($language->id) && $article->getTranslation($language->id)->seoUrl) {
                 $pathInfo = $article->getTranslation($language->id)->seoUrl;
                 $parentId = $article->category_id;
             } else {
                 return false;
             }
         } else {
             if ($route == $this->categoryRoute) {
                 $category = Category::findOne($id);
                 if ($category->getTranslation($language->id) && $category->getTranslation($language->id)->seoUrl) {
                     $pathInfo = $category->getTranslation($language->id)->seoUrl;
                     $parentId = $category->parent_id;
                 } else {
                     return false;
                 }
             }
         }
         while ($parentId != null) {
             $category = Category::findOne($parentId);
             if ($category->getTranslation($language->id) && $category->getTranslation($language->id)->seoUrl) {
                 $pathInfo = $category->getTranslation($language->id)->seoUrl . '/' . $pathInfo;
                 $parentId = $category->parent_id;
             } else {
                 return false;
             }
         }
         if (!empty($this->prefix)) {
             $pathInfo = $this->prefix . $pathInfo;
         }
         return $pathInfo;
     }
     return false;
 }
Пример #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getChildren()
 {
     return $this->hasMany(Category::className(), ['parent_id' => 'id']);
 }
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }