コード例 #1
0
 protected function launch()
 {
     if ($this->category && !$this->category instanceof Category) {
         $this->category = Category::findOne(intval($this->category));
     }
     echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->category ? $this->category->children()->published()->orderBy(null) : Category::find()->roots()->published(), 'pagination' => false, 'sort' => ['defaultOrder' => [$this->sort => intval($this->dir)]]]), 'itemLayout' => $this->itemLayout]);
 }
コード例 #2
0
 /**
  * @param $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     if ($this->excludeRoots) {
         $query->excludeRoots();
     }
     $query->with(['tags', 'parent']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['lft' => SORT_ASC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['{{%news_category}}.id' => $this->id, '{{%news_category}}.parent_id' => $this->parent_id, '{{%news_category}}.created_at' => $this->created_at, '{{%news_category}}.updated_at' => $this->updated_at, '{{%news_category}}.status' => $this->status, '{{%news_category}}.created_by' => $this->created_by, '{{%news_category}}.updated_by' => $this->updated_by, '{{%news_category}}.lft' => $this->lft, '{{%news_category}}.rgt' => $this->rgt, '{{%news_category}}.level' => $this->level, '{{%news_category}}.ordering' => $this->ordering, '{{%news_category}}.hits' => $this->hits, '{{%news_category}}.lock' => $this->lock]);
     if ($this->published_at_timestamp) {
         $query->andWhere('{{%news_category}}.published_at >= :timestamp_from', ['timestamp_from' => $this->published_at_timestamp]);
     }
     if ($this->published_at_to_timestamp) {
         $query->andWhere('{{%news_category}}.published_at <= :timestamp_to', ['timestamp_to' => $this->published_at_to_timestamp]);
     }
     $query->andFilterWhere(['like', '{{%news_category}}.title', $this->title])->andFilterWhere(['like', '{{%news_category}}.alias', $this->alias])->andFilterWhere(['like', '{{%news_category}}.path', $this->path])->andFilterWhere(['like', '{{%news_category}}.preview_text', $this->preview_text])->andFilterWhere(['like', '{{%news_category}}.preview_image', $this->preview_image])->andFilterWhere(['like', '{{%news_category}}.detail_text', $this->detail_text])->andFilterWhere(['like', '{{%news_category}}.detail_image', $this->detail_image])->andFilterWhere(['like', '{{%news_category}}.metakey', $this->metakey])->andFilterWhere(['like', '{{%news_category}}.metadesc', $this->metadesc]);
     if ($this->excludeCategory && ($category = Category::findOne($this->excludeCategory))) {
         /** @var $category Category */
         $query->excludeCategory($category);
     }
     if ($this->tags) {
         $query->innerJoinWith('tags')->andFilterWhere(['{{%core_tag}}.id' => $this->tags]);
     }
     return $dataProvider;
 }
コード例 #3
0
 /**
  * @return Response
  */
 public function actionOrdering()
 {
     $data = Yii::$app->request->getBodyParam('data', []);
     foreach ($data as $id => $order) {
         if ($target = Category::findOne($id)) {
             $target->updateAttributes(['ordering' => intval($order)]);
         }
     }
     Category::find()->roots()->one()->reorderNode('ordering');
     DbState::updateState(Category::tableName());
     return $this->redirect(ArrayHelper::getValue(Yii::$app->request, 'referrer', ['index']));
 }
コード例 #4
0
ファイル: index.php プロジェクト: gromver/yii2-platform-news
    <div class="page-header">
        <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    </div>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <?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]]);
コード例 #5
0
ファイル: Post.php プロジェクト: gromver/yii2-platform-news
 /**
  * @param $event \gromver\platform\core\modules\search\modules\elastic\widgets\events\ElasticBeforeSearchEvent
  */
 public static function elasticBeforeFrontendSearch($event)
 {
     $event->sender->filters[] = ['not' => ['and' => [['term' => ['model_class' => self::className()]], ['or' => [['term' => ['params.published' => false]], ['terms' => ['params.category_id' => Category::find()->unpublished()->select('{{%news_category}}.id')->column()]]]]]]];
 }
コード例 #6
0
 /**
  * @param $event \gromver\platform\core\modules\search\modules\sql\widgets\events\SqlBeforeSearchEvent
  */
 public static function sqlBeforeFrontendSearch($event)
 {
     $event->query->leftJoin('{{%news_category}}', ['AND', ['=', 'model_class', self::className()], 'model_id={{%news_category}}.id', ['=', '{{%news_category}}.status', self::STATUS_PUBLISHED], ['NOT IN', '{{%news_category}}.parent_id', Category::find()->unpublished()->select('{{%news_category}}.id')->column()]])->addSelect('{{%news_category}}.id')->andWhere('model_class=:categoryClassName XOR {{%news_category}}.id IS NULL', [':categoryClassName' => self::className()]);
 }