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' => '{{%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]);
     $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', 'translations']);
     $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_timestamp) {
         $query->andWhere('{{%grom_post}}.published_at >= :timestamp_from', ['timestamp_from' => $this->published_at_timestamp]);
     }
     if ($this->published_at_to_timestamp) {
         $query->andWhere('{{%grom_post}}.published_at <= :timestamp_to', ['timestamp_to' => $this->published_at_to_timestamp]);
     }
     $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;
 }
Example #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPosts()
 {
     return $this->hasMany(Post::className(), ['category_id' => 'id'])->inverseOf('category');
 }
Example #8
0
 */
$this->title = Yii::t('gromver.platform', 'Select Post');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="post-index">

    <?php 
/*<h1><?= Html::encode($this->title) ?></h1>*/
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'id' => 'grid', 'pjax' => true, 'pjaxSettings' => ['neverTimeout' => true], 'columns' => [['attribute' => 'id', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '60px'], ['attribute' => 'category_id', 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '80px', 'value' => function ($model) {
    return @$model->category->title;
}, 'filter' => \yii\helpers\ArrayHelper::map(\gromver\platform\basic\modules\news\models\Category::find()->excludeRoots()->orderBy('lft')->all(), 'id', function ($model) {
    return str_repeat(" • ", max($model->level - 2, 0)) . $model->title;
})], ['attribute' => 'language', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '60px', 'filter' => Yii::$app->getAcceptedLanguagesList()], ['attribute' => 'title', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \gromver\platform\basic\modules\news\models\Post */
    return $model->title . '<br/>' . Html::tag('small', $model->alias, ['class' => 'text-muted']);
}, 'format' => 'html'], ['attribute' => 'status', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \gromver\platform\basic\modules\news\models\Post */
    return $model->getStatusLabel();
}, 'width' => '100px', 'filter' => \gromver\platform\basic\modules\news\models\Post::statusLabels()], ['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\basic\modules\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\basic\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'])]]]], ['header' => Yii::t('gromver.platform', 'Action'), 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) use($route) {
    /** @var $model \gromver\platform\basic\modules\news\models\Post */
    return Html::a(Yii::t('gromver.platform', 'Select'), '#', ['class' => 'btn btn-primary btn-xs', 'onclick' => \gromver\widgets\ModalIFrame::postDataJs(['id' => $model->id, 'title' => $model->title, 'description' => Yii::t('gromver.platform', 'Post: {title}', ['title' => $model->title]), 'route' => \gromver\platform\basic\modules\menu\models\MenuItem::toRoute($route, ['id' => $model->id]), 'link' => Yii::$app->urlManager->createUrl($model->getFrontendViewLink()), 'value' => $model->id . ':' . $model->alias])]);
}, 'width' => '80px', 'mergeHeader' => true, 'format' => 'raw']], 'responsive' => true, 'hover' => true, 'condensed' => true, 'floatHeader' => true, 'floatHeaderOptions' => ['scrollingTop' => 0], 'bordered' => false, 'panel' => ['heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-th-list"></i> ' . Html::encode($this->title) . '</h3>', 'type' => 'info', 'after' => Html::a('<i class="glyphicon glyphicon-repeat"></i> ' . Yii::t('gromver.platform', 'Reset List'), [null], ['class' => 'btn btn-info']), 'showFooter' => false]]);
?>

</div>
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPost()
 {
     return $this->hasOne(Post::className(), ['id' => 'post_id']);
 }
 /**
  * @param \gromver\platform\basic\components\MenuRequestInfo $requestInfo
  * @return mixed|null|string
  */
 public function createPost($requestInfo)
 {
     //пытаемся найти пункт меню ссылющийся на данный пост
     if ($path = $requestInfo->menuMap->getMenuPathByRoute(MenuItem::toRoute('grom/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('grom/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 #11
0
 protected function getQuery()
 {
     return Post::find()->published()->category($this->categoryId)->innerJoinWith('tags', false)->andWhere(['{{%grom_tag}}.id' => $this->tag->id]);
 }
Example #12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getViewedPosts()
 {
     return $this->hasMany(Post::className(), ['id' => 'post_id'])->viaTable(PostViewed::tableName(), ['user_id' => 'id']);
 }
Example #13
0
 protected function getQuery()
 {
     return Post::find()->published()->category($this->category ? $this->category->id : null)->language($this->language)->with(['tags', 'postViewed'])->last();
 }
 /**
  * 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.'));
     }
 }
Example #15
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' => 'language', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '80px', 'value' => function ($model) {
    /** @var $model \gromver\platform\basic\modules\page\models\Page */
    return \gromver\platform\basic\modules\main\widgets\TranslationsBackend::widget(['model' => $model]);
}, 'format' => 'raw', 'filter' => Yii::$app->getAcceptedLanguagesList()], ['attribute' => 'parent_id', 'width' => '150px', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var \gromver\platform\basic\modules\page\models\Page $model */
    return $model->parent ? $model->parent->title : '';
}, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => \yii\helpers\ArrayHelper::map(\gromver\platform\basic\modules\page\models\Page::find()->where(['id' => $searchModel->parent_id])->all(), 'id', 'title'), 'theme' => \kartik\select2\Select2::THEME_BOOTSTRAP, 'pluginOptions' => ['allowClear' => true, 'placeholder' => Yii::t('gromver.platform', 'Select ...'), 'ajax' => ['url' => \yii\helpers\Url::to(['page-list'])]]]], ['attribute' => 'title', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var \gromver\platform\basic\modules\page\models\Page $model */
    return str_repeat(" • ", max($model->level - 2, 0)) . $model->title . '<br/>' . Html::tag('small', ' — ' . $model->path, ['class' => 'text-muted']);
}, 'format' => 'html'], ['attribute' => 'status', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \gromver\platform\basic\modules\page\models\Page */
    return $model->status === \gromver\platform\basic\modules\page\models\Page::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\basic\modules\news\models\Post::statusLabels(), 'format' => 'raw', 'width' => '100px'], ['attribute' => 'tags', 'width' => '120px', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \gromver\platform\basic\modules\page\models\Page */
    return implode(', ', \yii\helpers\ArrayHelper::map($model->tags, 'id', 'title'));
}, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => \yii\helpers\ArrayHelper::map(\gromver\platform\basic\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, $index) {
    /** @var \gromver\platform\basic\modules\page\models\Page $model */
    return Html::input('text', 'order', $model->ordering, ['class' => 'form-control']);
}, 'format' => 'raw', 'width' => '100px'], ['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'), $searchModel->parent_id ? ['create', 'parentId' => $searchModel->parent_id] : ['create'], ['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'),
            data = {}
Example #16
0
 /**
  * @inheritdoc
  */
 public function events()
 {
     return [Desktop::EVENT_FETCH_ITEMS => 'addDesktopItem', 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']];
 }