public function actionContent($id) { $backUrl = \Yii::$app->request->referrer; $content = ContentRecord::findOne($id); $this->layout = 'basic-content'; return $this->render('content', compact('content', 'backUrl')); }
/** * Gets article data for tag functionality * @param $tag string search query * @return array */ public function searchTags($tag) { $idw = FrontEndHelper::getWebIdFromTextId(\Yii::$app->request->get('web', \Yii::$app->params['defaultWeb'])); $idl = FrontEndHelper::getLanguageIdFromAcronym(); $sql = "( SELECT DISTINCT content.id AS article_id, content.title AS article_title, perex, content.updated_at AS article_updated_at, menu_item.id AS menu_item_id, menu_item.title AS menu_item_title\n\t\t\tFROM `content`\n\t\t\tINNER JOIN `article_category` ON article_category.article_id=content.id\n\t\t\tINNER JOIN `category` ON category.id=article_category.category_id\n\t\t\tINNER JOIN `menu_item_content` ON menu_item_content.category_id=category.id\n\t\t\tINNER JOIN `menu_item` ON menu_item.id=menu_item_content.menu_item_id\n\t\t\tINNER JOIN `menu` ON menu.id=menu_item.menu_id\n\t\t\tINNER JOIN `content_tag` ON content_tag.content_id=content.id\n\t\t\tINNER JOIN `tag` ON tag.id=content_tag.tag_id\n\t\t\tWHERE ((((((`content`.`content_type`=:content_type))\n\t\t\t\tAND (`content`.`active`=TRUE)) " . (Yii::$app->user->isGuest ? " AND (`content`.`public`=TRUE))" : '') . "\n\t\t\t\tAND (`content`.`language_id`=:language_id))\n\t\t\t\tAND (`menu`.`web_id`=:web_id))\n\t\t\t\tAND (`tag`.`name`=:tag))\n\t\t\tORDER BY `content`.`updated_at`"; $query = ContentRecord::findBySql($sql, [':content_type' => ContentRecord::TYPE_ARTICLE, ':language_id' => $idl, ':web_id' => $idw, ':tag' => $tag]); return $query->asArray()->all(); }
public function init() { parent::init(); if ($this->pageId) { $this->_item = ContentRecord::findOne($this->pageId); } else { throw new InvalidConfigException(\Yii::t('front', 'No required parameter given') . ' - pageId'); } if (!$this->viewName) { throw new InvalidConfigException(\Yii::t('front', 'No required parameter given') . ' - viewName'); } }
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(); }
public function init() { Widget::init(); if ($this->categoryId) { $language_id = FrontEndHelper::getLanguageIdFromAcronym(); $web_id = FrontEndHelper::getWebIdFromTextId(\Yii::$app->request->get('web', \Yii::$app->params['defaultWeb'])); $this->orderBy = 'content.content_date DESC'; $this->withDate = true; $sql = "( SELECT DISTINCT `content`.*\n\t\t\t\tFROM `content`\n\t\t\t\tINNER JOIN `article_category` ON article_category.article_id=content.id\n\t\t\t\tINNER JOIN `category` ON (category.id=article_category.category_id AND category.id=:category_id)\n\t\t\t\tINNER JOIN `menu_item_content` ON menu_item_content.category_id=category.id\n\t\t\t\tINNER JOIN `menu_item` ON menu_item.id=menu_item_content.menu_item_id\n\t\t\t\tINNER JOIN `menu` ON menu.id=menu_item.menu_id\n\t\t\t\tWHERE (((((((`content`.`content_type`=:content_type))\n\t\t\t\t\tAND ((content.content_date<:actual_date) AND (IF(content.content_end_date IS NULL, content.content_end_date IS NULL, content.content_end_date<:actual_date))))\n\t\t\t\t\tAND (NOT (`content`.`id`" . ($this->articleId ? "=" . $this->articleId : " IS NULL") . ")))\n\t\t\t\t\tAND (`content`.`active`=TRUE)) " . (Yii::$app->user->isGuest ? " AND (`content`.`public`=TRUE))" : '') . "\n\t\t\t\t\tAND (`content`.`language_id`=:language_id))\n\t\t\t\t\tAND (`menu`.`web_id`=:web_id))\n\t\t\t\tORDER BY " . $this->orderBy . ($this->itemsCount ? " LIMIT " . $this->itemsCount : ""); $query = ContentRecord::findBySql($sql, [':category_id' => $this->categoryId ?: $this->categoryId, ':content_type' => ContentRecord::TYPE_ARTICLE, ':language_id' => $language_id, ':web_id' => $web_id, ':actual_date' => Yii::$app->formatter->asDate('now', 'y-MM-dd')]); $this->_items = $query->all(); $this->setMenuUrlParts(); } else { throw new InvalidParamException(\Yii::t('front', 'No required parameter given') . ' - categoryId'); } }
public function init() { parent::init(); if (!$this->invitationsCategoryId) { $this->invitationsCategoryId = Yii::$app->params[Yii::$app->language]['defaultInvitationsCategoryId']; } if (!$this->actualitiesCategoryId) { $this->actualitiesCategoryId = Yii::$app->params[Yii::$app->language]['defaultActualitiesCategoryId']; } $language_id = FrontEndHelper::getLanguageIdFromAcronym(); $web_id = FrontEndHelper::getWebIdFromTextId(\Yii::$app->request->get('web', \Yii::$app->params['defaultWeb'])); // Invitations $sql = "( SELECT DISTINCT `content`.*\n\t\t\t\tFROM `content`\n\t\t\t\tINNER JOIN `article_category` ON article_category.article_id=content.id\n\t\t\t\tINNER JOIN `category` ON (category.id=article_category.category_id AND category.id=:category_id)\n\t\t\t\tINNER JOIN `menu_item_content` ON menu_item_content.category_id=category.id\n\t\t\t\tINNER JOIN `menu_item` ON menu_item.id=menu_item_content.menu_item_id\n\t\t\t\tINNER JOIN `menu` ON menu.id=menu_item.menu_id\n\t\t\t\tWHERE ((((((`content`.`content_type`=:content_type))\n\t\t\t\t\tAND ((content.content_date>=:actual_date) OR (content.content_end_date>=:actual_date)))\n\t\t\t\t\tAND (`content`.`active`=TRUE)) " . (Yii::$app->user->isGuest ? " AND (`content`.`public`=TRUE))" : '') . "\n\t\t\t\t\tAND (`content`.`language_id`=:language_id))\n\t\t\t\t\tAND (`menu`.`web_id`=:web_id))\n\t\t\t\tORDER BY content.content_date, content.content_time ASC" . ($this->itemsCount ? " LIMIT " . $this->itemsCount : ""); $this->_invitationsItems = ContentRecord::findBySql($sql, [':category_id' => $this->invitationsCategoryId, ':content_type' => ContentRecord::TYPE_ARTICLE, ':language_id' => $language_id, ':web_id' => $web_id, ':actual_date' => Yii::$app->formatter->asDate('now', 'y-MM-dd')])->all(); $this->setMenuUrlParts('invitations'); $invitationsCount = count($this->_invitationsItems); if ($invitationsCount < $this->itemsCount) { $limit = $this->itemsCount - $invitationsCount; $sql = "( SELECT DISTINCT `content`.*\n\t\t\t\t\tFROM `content`\n\t\t\t\t\tINNER JOIN `article_category` ON article_category.article_id=content.id\n\t\t\t\t\tINNER JOIN `category` ON (category.id=article_category.category_id AND category.id=:category_id)\n\t\t\t\t\tINNER JOIN `menu_item_content` ON menu_item_content.category_id=category.id\n\t\t\t\t\tINNER JOIN `menu_item` ON menu_item.id=menu_item_content.menu_item_id\n\t\t\t\t\tINNER JOIN `menu` ON menu.id=menu_item.menu_id\n\t\t\t\t\tWHERE (((((((`content`.`content_type`=:content_type))\n\t\t\t\t\t\tAND (IF(`content`.`content_date` IS NULL, `content`.`content_date` IS NULL, `content`.`content_date`<=:actual_date)))\n AND (IF(`content`.`content_end_date` IS NULL, `content`.`content_end_date` IS NULL, `content`.`content_end_date`>=:actual_date)))\n AND (`content`.`active`=TRUE)) " . (Yii::$app->user->isGuest ? " AND (`content`.`public`=TRUE))" : '') . "\n\t\t\t\t\t\tAND (`content`.`language_id`=:language_id))\n\t\t\t\t\t\tAND (`menu`.`web_id`=:web_id))\n\t\t\t\t\tORDER BY content.updated_at DESC" . ($this->itemsCount ? " LIMIT " . $limit : ""); $this->_actualitiesItems = ContentRecord::findBySql($sql, [':category_id' => $this->actualitiesCategoryId, ':content_type' => ContentRecord::TYPE_ARTICLE, ':language_id' => $language_id, ':web_id' => $web_id, ':actual_date' => Yii::$app->formatter->asDate('now', 'y-MM-dd')])->all(); $this->setMenuUrlParts('actualities'); } }
/** * @return static */ public function getContent() { return $this->hasOne(ContentRecord::className(), ['id' => 'content_id'])->via('menuItemContent'); }
/** * @inheritdoc */ public static function find() { return parent::find()->andWhere(['content_type' => self::TYPE_PAGE]); }
<?php /* @var $items common\models\Page[]|common\models\Article[] */ /* @var $controllerId string */ /* @var $translatedWordItems string */ /* @var $translatedWordItems2 string */ /* @var $contentType int */ use common\models\ContentRecord; use yii\helpers\Html; echo '<h2>' . Yii::t('back', 'Recent {items}', ['items' => $translatedWordItems]) . '</h2>'; if ($items) { foreach ($items as $item) { echo '<div class="row"><div class="col-xs-12">'; echo '<div class="pull-right">' . ($item->public ? '<span class="glyphicon glyphicon-eye-open" title="' . Yii::t('back', 'Public') . '"></span>' : '<span class="glyphicon glyphicon-eye-close" title="' . Yii::t('back', 'Not public') . '"></span>') . ' ' . ($item->active ? '<span class="glyphicon glyphicon-ok-circle" title="' . Yii::t('back', 'Active') . '"></span>' : '<span class="glyphicon glyphicon-remove-circle" title="' . Yii::t('back', 'Not active') . '"></span>') . '</div>'; echo '<h3 style="margin-top: 0">' . Html::a($item->title, [$controllerId . '/update', 'id' => $item->id]) . '<br><small>' . Yii::t('back', 'Last update') . ': ' . Yii::$app->formatter->format($item->updated_at, ['datetime', 'php:d.m.Y, H:i:s']) . '</small></h3>'; echo $item->perex; echo '</div></div>'; } echo '<p class="notice">' . Yii::t('back', 'Number {items2} in CMS', ['items2' => $translatedWordItems2]) . ': ' . ContentRecord::getRecordsCount($contentType) . '</p>'; } else { echo '<p class="text-warning">' . Yii::t('back', 'No {items} in CMS', ['items' => $translatedWordItems]) . '</p>'; } echo Html::a(Yii::t('back', 'Manage {items}', ['items' => $translatedWordItems]), [$controllerId . '/index'], ['class' => 'btn btn-primary']);
public static function getFirstArticleIdFromCategoryId($categoryId) { //TODO opravit - není zcela košér - nebere v potaz více webů $sql = "( SELECT DISTINCT `content`.`id`\n\t\t\t\tFROM `content`\n\t\t\t\tINNER JOIN `article_category` ON article_category.article_id=content.id\n\t\t\t\tINNER JOIN `category` ON category.id=article_category.category_id\n\t\t\t\tWHERE (((((((`article_category`.`category_id`=:category_id))\n\t\t\t\t\tAND (`content`.`content_type`=:content_type)))\n\t\t\t\t\tAND (`content`.`active`=TRUE)) " . (Yii::$app->user->isGuest ? " AND (`content`.`public`=TRUE))" : '') . "\n\t\t\t\t\tAND (`content`.`language_id`=:language_id)))\n\t\t\t\tORDER BY content.updated_at DESC LIMIT 1"; return ContentRecord::findBySql($sql, [':category_id' => $categoryId, ':content_type' => ContentRecord::TYPE_ARTICLE, ':language_id' => FrontEndHelper::getLanguageIdFromAcronym()])->scalar(); }
/** * @return \yii\db\ActiveQuery */ public function getContents() { return $this->hasMany(ContentRecord::className(), ['layout_id' => 'id']); }
/** * 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; }