예제 #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]);
 }
 /**
  * @param $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     if ($this->excludeRoots) {
         $query->excludeRoots();
     }
     $query->with(['tags', 'translations', 'parent']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['lft' => SORT_ASC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['{{%grom_category}}.id' => $this->id, '{{%grom_category}}.parent_id' => $this->parent_id, '{{%grom_category}}.created_at' => $this->created_at, '{{%grom_category}}.updated_at' => $this->updated_at, '{{%grom_category}}.status' => $this->status, '{{%grom_category}}.created_by' => $this->created_by, '{{%grom_category}}.updated_by' => $this->updated_by, '{{%grom_category}}.lft' => $this->lft, '{{%grom_category}}.rgt' => $this->rgt, '{{%grom_category}}.level' => $this->level, '{{%grom_category}}.ordering' => $this->ordering, '{{%grom_category}}.hits' => $this->hits, '{{%grom_category}}.lock' => $this->lock]);
     if ($this->published_at_timestamp) {
         $query->andWhere('{{%grom_category}}.published_at >= :timestamp_from', ['timestamp_from' => $this->published_at_timestamp]);
     }
     if ($this->published_at_to_timestamp) {
         $query->andWhere('{{%grom_category}}.published_at <= :timestamp_to', ['timestamp_to' => $this->published_at_to_timestamp]);
     }
     $query->andFilterWhere(['like', '{{%grom_category}}.language', $this->language])->andFilterWhere(['like', '{{%grom_category}}.title', $this->title])->andFilterWhere(['like', '{{%grom_category}}.alias', $this->alias])->andFilterWhere(['like', '{{%grom_category}}.path', $this->path])->andFilterWhere(['like', '{{%grom_category}}.preview_text', $this->preview_text])->andFilterWhere(['like', '{{%grom_category}}.preview_image', $this->preview_image])->andFilterWhere(['like', '{{%grom_category}}.detail_text', $this->detail_text])->andFilterWhere(['like', '{{%grom_category}}.detail_image', $this->detail_image])->andFilterWhere(['like', '{{%grom_category}}.metakey', $this->metakey])->andFilterWhere(['like', '{{%grom_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(['{{%grom_tag}}.id' => $this->tags]);
     }
     return $dataProvider;
 }
예제 #3
0
 /**
  * @param $event \gromver\platform\basic\modules\search\modules\sql\widgets\events\SqlBeforeSearchEvent
  */
 public static function sqlBeforeFrontendSearch($event)
 {
     $event->query->leftJoin('{{%grom_category}}', ['AND', ['=', 'model_class', self::className()], 'model_id={{%grom_category}}.id', ['=', '{{%grom_category}}.status', self::STATUS_PUBLISHED], ['NOT IN', '{{%grom_category}}.parent_id', Category::find()->unpublished()->select('{{%grom_category}}.id')->column()]])->addSelect('{{%grom_category}}.id')->andWhere('model_class=:categoryClassName XOR {{%grom_category}}.id IS NULL', [':categoryClassName' => self::className()]);
 }
예제 #4
0
 * @var gromver\platform\basic\modules\news\models\PostSearch $searchModel
 * @var string $route
 */
$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]]);
?>
예제 #5
0
 /**
  * @param $event \gromver\platform\basic\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('{{%grom_category}}.id')->column()]]]]]]];
 }
 /**
  * @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']));
 }