public function loadModel($id)
 {
     if (!($model = Post::findOne($id))) {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested post does not exist.'));
     }
     return $model;
 }
Example #2
0
 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'];
     }
 }
Example #3
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]);
 }
 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());
 }
Example #5
0
 protected function launch()
 {
     if ($this->post && !$this->post instanceof Post) {
         $this->post = Post::findOne(intval($this->post));
     }
     if (empty($this->post)) {
         throw new InvalidConfigException(Yii::t('gromver.platform', 'Post not found.'));
     }
     if ($this->useHighlights) {
         CkeditorHighlightAsset::register($this->getView());
     }
     echo $this->render($this->layout, ['model' => $this->post]);
 }
 /**
  * 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;
 }
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.'));
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPost()
 {
     return $this->hasOne(Post::className(), ['id' => 'post_id']);
 }
 /**
  * @param \gromver\platform\core\components\MenuRequestInfo $requestInfo
  * @return mixed|null|string
  */
 public function createPost($requestInfo)
 {
     //пытаемся найти пункт меню ссылющийся на данный пост
     if ($path = $requestInfo->menuMap->getMenuPathByRoute(MenuItem::toRoute('news/frontend/post/view', ['id' => $requestInfo->requestParams['id']]))) {
         unset($requestInfo->requestParams['id'], $requestInfo->requestParams['category_id'], $requestInfo->requestParams['alias']);
         return MenuItem::toRoute($path, $requestInfo->requestParams);
     }
     //ищем пункт меню ссылающийся на категорию данного поста либо ее предков
     if (isset($requestInfo->requestParams['category_id']) && isset($requestInfo->requestParams['alias'])) {
         //можем привязаться к пункту меню ссылающемуся на категорию новостей к которой принадлежит данный пост(напрямую либо косвенно)
         if ($path = $this->findCategoryMenuPath($requestInfo->requestParams['category_id'], $requestInfo->menuMap)) {
             $path .= '/' . $requestInfo->requestParams['alias'] . '.' . $this->postSuffix;
             unset($requestInfo->requestParams['id'], $requestInfo->requestParams['category_id'], $requestInfo->requestParams['alias']);
             return MenuItem::toRoute($path, $requestInfo->requestParams);
         }
     }
     //привязываем ко всем новостям, если пукнт меню существует
     if ($path = $requestInfo->menuMap->getMenuPathByRoute('news/frontend/post/index')) {
         $path .= '/' . Post::findOne($requestInfo->requestParams['id'])->category->path . '/' . $requestInfo->requestParams['alias'] . '.' . $this->postSuffix;
         unset($requestInfo->requestParams['id'], $requestInfo->requestParams['category_id'], $requestInfo->requestParams['alias']);
         return MenuItem::toRoute($path, $requestInfo->requestParams);
     }
 }
Example #10
0
?>

    <?php 
echo GridView::widget(['id' => 'table-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'pjax' => true, 'pjaxSettings' => ['neverTimeout' => true], 'columns' => [['class' => '\\kartik\\grid\\CheckboxColumn'], ['attribute' => 'id', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '60px'], ['attribute' => 'category_id', 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '80px', 'value' => function ($model) {
    /** @var $model \gromver\platform\news\models\Post */
    return @$model->category->title;
}, 'filter' => \yii\helpers\ArrayHelper::map(\gromver\platform\news\models\Category::find()->excludeRoots()->orderBy('lft')->all(), 'id', function ($model) {
    /** @var $model \gromver\platform\news\models\Category */
    return str_repeat(" • ", max($model->level - 2, 0)) . $model->title;
})], ['attribute' => 'title', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var \gromver\platform\news\models\Post $model */
    return $model->title . '<br/>' . Html::tag('small', ' — ' . $model->alias, ['class' => 'text-muted']);
}, 'format' => 'html'], ['attribute' => 'status', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \gromver\platform\news\models\Post */
    return $model->status === \gromver\platform\news\models\Post::STATUS_PUBLISHED ? Html::a('<i class="glyphicon glyphicon-ok-circle"></i>', \yii\helpers\Url::to(['unpublish', 'id' => $model->id]), ['class' => 'btn btn-default btn-xs', 'data-pjax' => '0', 'data-method' => 'post']) : Html::a('<i class="glyphicon glyphicon-remove-circle"></i>', \yii\helpers\Url::to(['publish', 'id' => $model->id]), ['class' => 'btn btn-danger btn-xs', 'data-pjax' => '0', 'data-method' => 'post']);
}, 'filter' => \gromver\platform\news\models\Post::statusLabels(), 'format' => 'raw', 'width' => '80px'], ['attribute' => 'published_at', 'vAlign' => GridView::ALIGN_MIDDLE, 'format' => ['date', 'd MMM Y H:mm'], 'width' => '160px', 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['pluginOptions' => ['format' => 'dd.mm.yyyy'], 'type' => \kartik\date\DatePicker::TYPE_RANGE, 'attribute2' => 'published_at_to']], ['attribute' => 'tags', 'width' => '120px', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \gromver\platform\news\models\Category */
    return implode(', ', \yii\helpers\ArrayHelper::map($model->tags, 'id', 'title'));
}, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => \yii\helpers\ArrayHelper::map(\gromver\platform\core\modules\tag\models\Tag::find()->where(['id' => $searchModel->tags])->all(), 'id', 'title'), 'theme' => \kartik\select2\Select2::THEME_BOOTSTRAP, 'pluginOptions' => ['allowClear' => true, 'placeholder' => Yii::t('gromver.platform', 'Select ...'), 'ajax' => ['url' => \yii\helpers\Url::to(['/grom/tag/backend/default/tag-list'])]]]], ['attribute' => 'ordering', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \gromver\platform\news\models\Post */
    return Html::input('text', 'order', $model->ordering, ['class' => 'form-control']);
}, 'format' => 'raw', 'width' => '80px'], ['class' => 'kartik\\grid\\ActionColumn', 'deleteOptions' => ['data-method' => 'delete']]], 'responsive' => true, 'hover' => true, 'condensed' => true, 'floatHeader' => true, 'bordered' => false, 'panel' => ['heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-th-list"></i> ' . Html::encode($this->title) . ' </h3>', 'type' => 'info', 'before' => Html::a('<i class="glyphicon glyphicon-plus"></i> ' . Yii::t('gromver.platform', 'Add'), ['create', 'category_id' => $searchModel->category_id], ['class' => 'btn btn-success', 'data-pjax' => '0']), 'after' => Html::a('<i class="glyphicon glyphicon-sort-by-attributes"></i> ' . Yii::t('gromver.platform', 'Ordering'), ['ordering'], ['class' => 'btn btn-default', 'data-pjax' => '0', 'onclick' => 'processOrdering(this); return false']) . ' ' . Html::a('<i class="glyphicon glyphicon-trash"></i> ' . Yii::t('gromver.platform', 'Delete'), ['bulk-delete'], ['class' => 'btn btn-danger', 'data-pjax' => '0', 'onclick' => 'processAction(this); return false']) . ' ' . Html::a('<i class="glyphicon glyphicon-repeat"></i> ' . Yii::t('gromver.platform', 'Reset List'), ['index'], ['class' => 'btn btn-info']), 'showFooter' => false]]);
?>

</div>

<script>
    function processOrdering(el) {
        var $el = $(el),
            $grid = $('#table-grid'),
            selection = $grid.yiiGridView('getSelectedRows'),
Example #11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPosts()
 {
     return $this->hasMany(Post::className(), ['category_id' => 'id'])->inverseOf('category');
 }
Example #12
0
 protected function getQuery()
 {
     return Post::find()->published()->category($this->categoryId)->innerJoinWith('tags', false)->andWhere(['{{%core_tag}}.id' => $this->tag->id]);
 }
Example #13
0
 /**
  * @inheritdoc
  */
 public function events()
 {
     return [Desktop::EVENT_FETCH_ITEMS => 'addDesktopItem', ParamsManager::EVENT_FETCH_MODULE_PARAMS => 'addParams', MenuItemRoutes::EVENT_FETCH_ITEMS => 'addMenuItemRoutes', MenuUrlRule::EVENT_FETCH_MODULE_ROUTERS => 'addMenuRouter', ElasticModule::EVENT_BEFORE_CREATE_INDEX . Post::className() => [Post::className(), 'elasticBeforeCreateIndex'], ElasticSearchResults::EVENT_BEFORE_SEARCH . Post::className() => [Post::className(), 'elasticBeforeFrontendSearch'], ElasticSearchResults::EVENT_BEFORE_SEARCH . Category::className() => [Category::className(), 'elasticBeforeFrontendSearch'], SqlSearchResults::EVENT_BEFORE_SEARCH . Post::className() => [Post::className(), 'sqlBeforeFrontendSearch'], SqlSearchResults::EVENT_BEFORE_SEARCH . Category::className() => [Category::className(), 'sqlBeforeFrontendSearch']];
 }
Example #14
0
 protected function getQuery()
 {
     return Post::find()->published()->category($this->category ? $this->category->id : null)->with(['tags', 'postViewed'])->last();
 }