예제 #1
0
 public function loadModel($id)
 {
     if (!($model = Post::findOne($id))) {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested post does not exist.'));
     }
     return $model;
 }
예제 #2
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]);
 }
예제 #3
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'];
     }
 }
예제 #4
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]);
 }
예제 #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]);
 }
예제 #6
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;
 }
예제 #7
0
 protected function getQuery()
 {
     return Post::find()->published()->category($this->categoryId)->innerJoinWith('tags', false)->andWhere(['{{%grom_tag}}.id' => $this->tag->id]);
 }
예제 #8
0
 /**
  * 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.'));
     }
 }
예제 #9
0
 * @var gromver\platform\backend\modules\news\models\PostSearch $searchModel
 */
$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', 'width' => '50px'], ['attribute' => 'category_id', 'width' => '80px', 'value' => function ($model) {
    return @$model->category->title;
}, 'filter' => \yii\helpers\ArrayHelper::map(\gromver\platform\common\models\Category::find()->noRoots()->orderBy('lft')->all(), 'id', function ($model) {
    return str_repeat(" • ", max($model->level - 2, 0)) . $model->title;
})], ['attribute' => 'language', 'filter' => Yii::$app->getLanguagesList()], ['attribute' => 'title', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Post */
    return $model->title . '<br/>' . Html::tag('small', $model->alias, ['class' => 'text-muted']);
}, 'format' => 'html'], ['attribute' => 'status', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Post */
    return $model->getStatusLabel();
}, 'filter' => \gromver\platform\common\models\Post::statusLabels()], ['attribute' => 'published_at', 'format' => ['date', 'd MMM Y H:mm'], 'width' => '160px', 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['options' => ['value' => is_int($searchModel->published_at) ? date('d.m.Y', $searchModel->published_at) : ''], 'pluginOptions' => ['format' => 'dd.mm.yyyy']]], ['attribute' => 'tags', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Post */
    return implode(', ', \yii\helpers\ArrayHelper::map($model->tags, 'id', 'title'));
}, 'filterType' => \dosamigos\selectize\Selectize::className(), 'filterWidgetOptions' => ['items' => \yii\helpers\ArrayHelper::map(\gromver\platform\common\models\Tag::find()->where(['id' => $searchModel->tags])->all(), 'id', 'title', 'group'), 'clientOptions' => ['maxItems' => 1], 'url' => ['/grom/default/tag-list']]], ['value' => function ($model) {
    return Html::a(Yii::t('gromver.platform', 'Select'), '#', ['class' => 'btn btn-primary btn-xs', 'onclick' => \gromver\widgets\ModalIFrame::emitDataJs(['id' => $model->id, 'description' => Yii::t('gromver.platform', 'Post: {title}', ['title' => $model->title]), 'value' => $model->id . ':' . $model->alias])]);
}, '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>
예제 #10
0
 protected function getQuery()
 {
     return Post::find()->published()->category($this->category ? $this->category->id : null)->language($this->language)->with('tags')->last();
 }
예제 #11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPosts()
 {
     return $this->hasMany(Post::className(), ['category_id' => 'id'])->inverseOf('category');
 }
예제 #12
0
 public function createPost($requestInfo)
 {
     //пытаемся найти пункт меню ссылющийся на данный пост
     if ($path = $requestInfo->menuMap->getMenuPathByRoute(MenuItem::toRoute('grom/news/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/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);
     }
 }
예제 #13
0
    <p>
        <?= Html::a(Yii::t('gromver.platform', 'Create {modelClass}', [
    'modelClass' => 'Page',
]), ['create'], ['class' => 'btn btn-success']) ?>
    </p>*/
?>

    <?php 
echo GridView::widget(['id' => 'table-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'pjax' => true, 'pjaxSettings' => ['neverTimeout' => true], 'columns' => [['class' => 'yii\\grid\\CheckboxColumn'], ['attribute' => 'id', 'width' => '50px'], ['attribute' => 'language', 'width' => '80px', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Page */
    return \gromver\platform\backend\widgets\Translator::widget(['model' => $model]);
}, 'format' => 'raw', 'filter' => Yii::$app->getLanguagesList()], 'title', 'alias', ['attribute' => 'status', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Page */
    return $model->status === \gromver\platform\common\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-default btn-xs', 'data-pjax' => '0', 'data-method' => 'post']);
}, 'filter' => \gromver\platform\common\models\Post::statusLabels(), 'format' => 'raw', 'width' => '80px'], ['attribute' => 'tags', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Page */
    return implode(', ', \yii\helpers\ArrayHelper::map($model->tags, 'id', 'title'));
}, 'filterType' => \dosamigos\selectize\Selectize::className(), 'filterWidgetOptions' => ['items' => \yii\helpers\ArrayHelper::map(\gromver\platform\common\models\Tag::find()->where(['id' => $searchModel->tags])->all(), 'id', 'title', 'group'), 'clientOptions' => ['maxItems' => 1], 'url' => ['/grom/tag/default/tag-list']]], ['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'], ['class' => 'btn btn-success', 'data-pjax' => '0']), 'after' => 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 processAction(el) {
        var $el = $(el),
            $grid = $('#table-grid'),
            selection = $grid.yiiGridView('getSelectedRows')
        if(!selection.length) {
            alert(<?php 
echo json_encode(Yii::t('gromver.platform', 'Select items.'));
?>
예제 #14
0
 public static function model()
 {
     return \gromver\platform\common\models\Post::className();
 }