示例#1
0
 public function init()
 {
     parent::init();
     $language_id = FrontEndHelper::getLanguageIdFromAcronym();
     $web_id = FrontEndHelper::getWebIdFromTextId(\Yii::$app->request->get('web', \Yii::$app->params['defaultWeb']));
     $query = ContentRecord::find()->distinct()->where(['content.content_type' => ContentRecord::TYPE_ARTICLE])->andWhere(['content.active' => true]);
     if (\Yii::$app->user->isGuest) {
         $query->andWhere(['content.public' => true]);
     }
     $query->andWhere(['content.language_id' => $language_id])->innerJoin('article_category', 'article_category.article_id=content.id')->innerJoin('category', 'category.id=article_category.category_id')->innerJoin('menu_item_content', 'menu_item_content.category_id=category.id')->innerJoin('menu_item', 'menu_item.id=menu_item_content.menu_item_id')->innerJoin('menu', 'menu.id=menu_item.menu_id')->andWhere(['menu.web_id' => $web_id])->orderBy(['updated_at' => SORT_DESC])->limit($this->recentArticlesCount);
     $this->_items = $query->all();
 }
示例#2
0
 /**
  * @inheritdoc
  */
 public static function find()
 {
     return parent::find()->andWhere(['content_type' => self::TYPE_PAGE]);
 }
示例#3
0
 /**
  * Returns content list options for dropdown
  * @return array
  */
 public function getContentListOptions()
 {
     $session = Yii::$app->session;
     if (!$session['language_id']) {
         $session['language_id'] = LanguageRecord::getMainLanguageId();
     }
     $items = [];
     switch ($this->content_type) {
         case MenuItemRecord::CONTENT_PAGE:
             $items = ArrayHelper::map(ContentRecord::find()->where(['language_id' => $session['language_id'], 'content_type' => ContentRecord::TYPE_PAGE])->activeStatus()->orderBy('updated_at DESC')->all(), 'id', 'title');
             break;
         case MenuItemRecord::CONTENT_CATEGORY:
             $items = ArrayHelper::map(CategoryRecord::find()->where(['language_id' => $session['language_id'], 'category_type' => CategoryRecord::TYPE_CATEGORY])->activeStatus()->orderBy('updated_at DESC')->all(), 'id', 'title');
             break;
         default:
             break;
     }
     return $items;
 }