Пример #1
0
 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]);
 }
Пример #2
0
 public function init()
 {
     //todo запилить проверку на опубликованность категорий постов
     $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'];
     }
 }
Пример #3
0
 protected function launch()
 {
     $tags = Post::find()->category($this->categoryId)->published()->innerJoinWith('tags', false)->select(['id' => '{{%grom_tag}}.id', 'title' => '{{%grom_tag}}.title', 'alias' => '{{%grom_tag}}.alias', 'weight' => 'count({{%grom_tag}}.id)'])->groupBy('{{%grom_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]);
 }
Пример #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['updated_at' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['{{%grom_post}}.id' => $this->id, '{{%grom_post}}.category_id' => $this->category_id, '{{%grom_post}}.created_at' => $this->created_at, '{{%grom_post}}.updated_at' => $this->updated_at, '{{%grom_post}}.status' => $this->status, '{{%grom_post}}.created_by' => $this->created_by, '{{%grom_post}}.updated_by' => $this->updated_by, '{{%grom_post}}.ordering' => $this->ordering, '{{%grom_post}}.hits' => $this->hits, '{{%grom_post}}.lock' => $this->lock]);
     if ($this->published_at) {
         $query->andWhere('{{%grom_post}}.published_at >= :timestamp', ['timestamp' => $this->published_at]);
     }
     $query->andFilterWhere(['like', '{{%grom_post}}.title', $this->title])->andFilterWhere(['like', '{{%grom_post}}.alias', $this->alias])->andFilterWhere(['like', '{{%grom_post}}.preview_text', $this->preview_text])->andFilterWhere(['like', '{{%grom_post}}.preview_image', $this->preview_image])->andFilterWhere(['like', '{{%grom_post}}.detail_text', $this->detail_text])->andFilterWhere(['like', '{{%grom_post}}.detail_image', $this->detail_image])->andFilterWhere(['like', '{{%grom_post}}.metakey', $this->metakey])->andFilterWhere(['like', '{{%grom_post}}.metadesc', $this->metadesc]);
     if ($this->tags) {
         $query->innerJoinWith('tags')->andFilterWhere(['{{%grom_tag}}.id' => $this->tags]);
     }
     if ($this->language) {
         $query->innerJoinWith('category', false)->andFilterWhere(['like', '{{%grom_category}}.language', $this->language]);
     }
     return $dataProvider;
 }
Пример #5
0
 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->grom->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, $widget) {
         /** @var $model \gromver\platform\common\models\Post */
         return $model->title;
     }, 'description' => function ($model, $widget) {
         /** @var $model \gromver\platform\common\models\Post */
         return $model->preview_text ? $model->preview_text : StringHelper::truncateWords(strip_tags($model->detail_text), 40);
     }, 'link' => function ($model, $widget) {
         /** @var $model \gromver\platform\common\models\Post */
         return Url::toRoute($model->getViewLink(), true);
     }, 'author' => function ($model, $widget) {
         /** @var $model \gromver\platform\common\models\Post */
         return $model->user->email . ' (' . $model->user->username . ')';
     }, 'guid' => function ($model, $widget) {
         /** @var $model \gromver\platform\common\models\Post */
         return Url::toRoute($model->getViewLink(), true) . ' ' . Yii::$app->formatter->asDatetime($model->updated_at, 'php:' . DATE_RSS);
     }, 'pubDate' => function ($model, $widget) {
         /** @var $model \gromver\platform\common\models\Post */
         return Yii::$app->formatter->asDatetime($model->published_at, 'php:' . DATE_RSS);
     }]]);
 }
Пример #6
0
 protected function getQuery()
 {
     return Post::find()->published()->category($this->categoryId)->innerJoinWith('tags', false)->andWhere(['{{%grom_tag}}.id' => $this->tag->id]);
 }
Пример #7
0
 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']));
 }
Пример #8
0
 protected function getQuery()
 {
     return Post::find()->published()->category($this->category ? $this->category->id : null)->language($this->language)->with('tags')->last();
 }
Пример #9
0
 public function parseAllPosts($requestInfo)
 {
     if ($requestInfo->requestRoute == 'rss') {
         return ['grom/news/post/rss', []];
     } elseif (preg_match("#^(\\d{4})/(\\d{1,2})/(\\d{1,2})\$#", $requestInfo->requestRoute, $matches)) {
         //новости за определенную дату
         return ['grom/news/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];
         //алиас поста
         $category = Category::findOne(['path' => $categoryPath, 'language' => $requestInfo->menuMap->language]);
         if ($category && ($postId = Post::find()->select('id')->where(['alias' => $postAlias, 'category_id' => $category->id])->scalar())) {
             return ['grom/news/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 ['grom/tag/default/posts', ['id' => $tagId]];
         }
     }
 }