public function init() { $query = Post::find()->published()->category($this->categoryId)->andWhere('published_at>=:begin AND published_at<:end', [':begin' => $this->getCurrentMonthDate(), ':end' => $this->getNextMonthDate()])->groupBy('day')->select(['count' => 'count(id)', 'day' => 'day(from_unixtime(published_at))'])->last()->asArray(); foreach ($query->all() as $item) { $this->_calendar[$item['day']] = $item['count']; } }
protected function launch() { if ($this->category && !$this->category instanceof Category) { $this->category = Category::findOne(intval($this->category)); } $categoryId = $this->category ? $this->category->id : null; echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => Post::find()->published()->category($categoryId)->day($this->year, $this->month, $this->day)->last(), 'pagination' => false, 'sort' => ['defaultOrder' => [$this->sort => (int) $this->dir]]]), 'itemLayout' => $this->itemLayout, 'prevDayPost' => Post::find()->published()->category($categoryId)->beforeDay($this->year, $this->month, $this->day)->last()->one(), 'nextDayPost' => Post::find()->published()->category($categoryId)->afterDay($this->year, $this->month, $this->day)->last()->one(), 'category' => $this->category, 'year' => $this->year, 'month' => $this->month, 'day' => $this->day, 'listViewOptions' => $this->listViewOptions]); }
protected function launch() { $tags = Post::find()->category($this->categoryId)->published()->innerJoinWith('tags', false)->select(['id' => '{{%core_tag}}.id', 'title' => '{{%core_tag}}.title', 'alias' => '{{%core_tag}}.alias', 'weight' => 'count({{%core_tag}}.id)'])->groupBy('{{%core_tag}}.id')->asArray()->all(); $maxWeight = 0; array_walk($tags, function ($v) use(&$maxWeight) { $maxWeight = max($v['weight'], $maxWeight); }); echo $this->render('tag/tagPostCloud', ['tags' => $tags, 'fontBase' => $this->fontBase, 'fontSpace' => $this->fontSpace, 'maxWeight' => $maxWeight, 'categoryId' => $this->categoryId]); $this->getView()->registerAssetBundle(TagAsset::className()); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Post::find()->with(['tags', 'category']); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['updated_at' => SORT_DESC]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['{{%news_post}}.id' => $this->id, '{{%news_post}}.category_id' => $this->category_id, '{{%news_post}}.created_at' => $this->created_at, '{{%news_post}}.updated_at' => $this->updated_at, '{{%news_post}}.status' => $this->status, '{{%news_post}}.created_by' => $this->created_by, '{{%news_post}}.updated_by' => $this->updated_by, '{{%news_post}}.ordering' => $this->ordering, '{{%news_post}}.hits' => $this->hits, '{{%news_post}}.lock' => $this->lock]); if ($this->published_at_timestamp) { $query->andWhere('{{%news_post}}.published_at >= :timestamp_from', ['timestamp_from' => $this->published_at_timestamp]); } if ($this->published_at_to_timestamp) { $query->andWhere('{{%news_post}}.published_at <= :timestamp_to', ['timestamp_to' => $this->published_at_to_timestamp]); } $query->andFilterWhere(['like', '{{%news_post}}.title', $this->title])->andFilterWhere(['like', '{{%news_post}}.alias', $this->alias])->andFilterWhere(['like', '{{%news_post}}.preview_text', $this->preview_text])->andFilterWhere(['like', '{{%news_post}}.preview_image', $this->preview_image])->andFilterWhere(['like', '{{%news_post}}.detail_text', $this->detail_text])->andFilterWhere(['like', '{{%news_post}}.detail_image', $this->detail_image])->andFilterWhere(['like', '{{%news_post}}.metakey', $this->metakey])->andFilterWhere(['like', '{{%news_post}}.metadesc', $this->metadesc]); if ($this->tags) { $query->innerJoinWith('tags')->andFilterWhere(['{{%core_tag}}.id' => $this->tags]); } return $dataProvider; }
public function actionRss($category_id = null) { return RssView::widget(['dataProvider' => new ActiveDataProvider(['query' => Post::find()->published()->category($category_id)->language(Yii::$app->language)->orderBy(['published_at' => SORT_DESC]), 'pagination' => ['pageSize' => $this->module->rssPageSize]]), 'channel' => ['title' => Yii::$app->siteName, 'link' => Url::toRoute(['', 'category_id' => $category_id], true), 'description' => $category_id ? $this->loadCategoryModel($category_id)->title : Yii::t('gromver.platform', 'All news'), 'language' => Yii::$app->language], 'items' => ['title' => function ($model) { /** @var $model \gromver\platform\news\models\Post */ return $model->title; }, 'description' => function ($model) { /** @var $model \gromver\platform\news\models\Post */ return $model->preview_text ? $model->preview_text : StringHelper::truncateWords(strip_tags($model->detail_text), 40); }, 'link' => function ($model) { /** @var $model \gromver\platform\news\models\Post */ return Url::toRoute($model->getFrontendViewLink(), true); }, 'author' => function ($model) { /** @var $model \gromver\platform\news\models\Post */ return $model->user->email . ' (' . $model->user->username . ')'; }, 'guid' => function ($model) { /** @var $model \gromver\platform\news\models\Post */ return Url::toRoute($model->getFrontendViewLink(), true) . ' ' . Yii::$app->formatter->asDatetime($model->updated_at, 'php:' . DATE_RSS); }, 'pubDate' => function ($model) { /** @var $model \gromver\platform\news\models\Post */ return Yii::$app->formatter->asDatetime($model->published_at, 'php:' . DATE_RSS); }]]); }
/** * @return \yii\web\Response * @throws \Exception */ public function actionBulkDelete() { $data = Yii::$app->request->getBodyParam('data', []); $models = Post::find()->where(['id' => $data])->all(); foreach ($models as $model) { $model->delete(); } return $this->redirect(ArrayHelper::getValue(Yii::$app->request, 'referrer', ['index'])); }
/** * @param \gromver\platform\core\components\MenuRequestInfo $requestInfo * @return array */ public function parseAllPosts($requestInfo) { if ($requestInfo->requestRoute == 'rss') { return ['news/frontend/post/rss', []]; } elseif (preg_match("#^(\\d{4})/(\\d{1,2})/(\\d{1,2})\$#", $requestInfo->requestRoute, $matches)) { //новости за определенную дату return ['news/frontend/post/day', ['year' => $matches[1], 'month' => $matches[2], 'day' => $matches[3]]]; } elseif (preg_match("#^((.*)/)(([^/]+)\\.{$this->postSuffix})\$#", $requestInfo->requestRoute, $matches)) { //ищем пост $categoryPath = $matches[2]; //путь категории поста $postAlias = $matches[4]; //алиас поста /** @var Category $category */ $category = Category::findOne(['path' => $categoryPath]); if ($category && ($postId = Post::find()->select('id')->where(['alias' => $postAlias, 'category_id' => $category->id])->scalar())) { return ['news/frontend/post/view', ['id' => $postId]]; } } elseif (preg_match("#^(tag/([^/]+))\$#", $requestInfo->requestRoute, $matches)) { //ищем тег $tagAlias = $matches[2]; if ($tagId = Tag::find()->select('id')->where(['alias' => $tagAlias])->scalar()) { return ['news/frontend/post/tag', ['tag_id' => $tagId]]; } } }
protected function getQuery() { return Post::find()->published()->category($this->categoryId)->innerJoinWith('tags', false)->andWhere(['{{%core_tag}}.id' => $this->tag->id]); }
protected function getQuery() { return Post::find()->published()->category($this->category ? $this->category->id : null)->with(['tags', 'postViewed'])->last(); }