Пример #1
0
 public function getImagePath($id, $type, $category)
 {
     $dir = Yii::getAlias('@frontend/web/images/articles/');
     $article = Article::findOne($id);
     $imagePath = $dir . $type . '/' . $article->{$type} . '-' . $category . '.jpg';
     return $imagePath;
 }
Пример #2
0
 public function run()
 {
     $query = Article::find()->orderBy(['created_at' => SORT_DESC])->limit($this->count);
     if ($this->condition != null) {
         $query->where($this->condition);
     }
     $articles = $query->all();
     return $this->render('last-articles', ['articles' => $articles]);
 }
Пример #3
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 = null)
 {
     if (empty($id)) {
         $article = Article::find()->one();
     } else {
         $article = Article::findOne($id);
     }
     $articleTranslation = $article->translation;
     $this->view->title = $articleTranslation->seoTitle;
     $this->view->registerMetaTag(['name' => 'description', 'content' => html_entity_decode($articleTranslation->seoDescription)]);
     $this->view->registerMetaTag(['name' => 'keywords', 'content' => html_entity_decode($articleTranslation->seoKeywords)]);
     // default view name
     $articleView = 'index';
     if (!empty($article->view)) {
         $articleView = $article->view;
     } else {
         if (!empty($article->category)) {
             if (!empty($article->category->article_view)) {
                 $articleView = $article->category->article_view;
             }
         }
     }
     return $this->render($articleView, ['article' => $article]);
 }
Пример #5
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;
 }
 public function actionSwitchShow($id)
 {
     /* @var Article $article */
     if ($article = Article::findOne($id)) {
         $article->show = !$article->show;
         $article->save();
     }
     return $this->redirect(Url::to(['/articles/article']));
 }
Пример #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getArticles()
 {
     return $this->hasMany(Article::className(), ['category_id' => 'id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getArticle()
 {
     return $this->hasOne(Article::className(), ['id' => 'article_id']);
 }