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]); }
public function loadCategoryModel($id) { if (!($model = Category::findOne($id))) { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested category does not exist.')); } return $model; }
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->getQuery(), 'pagination' => ['pageSize' => $this->pageSize], 'sort' => ['defaultOrder' => [$this->sort => intval($this->dir)]]]), 'itemLayout' => $this->itemLayout, 'category' => $this->category, 'listViewOptions' => $this->listViewOptions]); }
/** * @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; }
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() { if ($this->category && !$this->category instanceof Category) { $this->category = Category::findOne(intval($this->category)); } if (empty($this->category)) { throw new InvalidConfigException(Yii::t('gromver.platform', 'Category not found.')); } echo $this->render($this->layout, ['model' => $this->category]); }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @param string|null $category_id * @param string|null $backUrl * @return mixed * @throws NotFoundHttpException */ public function actionCreate($category_id = null, $backUrl = null) { $model = new Post(); $model->loadDefaultValues(); $model->status = Post::STATUS_PUBLISHED; if (isset($category_id) && ($category = Category::findOne($category_id))) { /** @var Category $category */ $model->category_id = $category->id; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect($backUrl ? $backUrl : ['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
</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' => 'title', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) { /** @var \gromver\platform\news\models\Category $model */ return str_repeat(" • ", max($model->level - 2, 0)) . $model->title . '<br/>' . Html::tag('small', ' — ' . $model->path, ['class' => 'text-muted']); }, 'format' => 'html'], ['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(['/tag/backend/default/tag-list'])]]]], ['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' => 'status', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model, $index, $widget) { /** @var $model \gromver\platform\news\models\Category */ return $model->status === \gromver\platform\news\models\Category::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\Category::statusLabels(), 'format' => 'raw', 'width' => '100px'], ['attribute' => 'ordering', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model, $index) { /** @var \gromver\platform\news\models\Category $model */ return Html::input('text', 'order', $model->ordering, ['class' => 'form-control']); }, 'format' => 'raw', 'width' => '100px'], ['header' => Yii::t('gromver.platform', 'Posts'), 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) { /** @var \gromver\platform\news\models\Category $model */ return Html::a('(' . $model->getPosts()->count() . ')', ['/news/backend/post/index', 'PostSearch[category_id]' => $model->id], ['data-pjax' => 0]); }, 'mergeHeader' => true, 'format' => 'raw'], ['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-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 = {}
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.')); } }
/** * Находит путь к пункту меню ссылающемуся на категорию $categoryId, либо ее предка * Если путь ведет к предку, то достраиваем путь категории $categoryId * @param $categoryId * @param $menuMap \gromver\platform\core\components\MenuMap * @return null|string */ private function findCategoryMenuPath($categoryId, $menuMap) { /** @var Category $category */ if (!isset($this->_categoryPaths[$categoryId])) { if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute('news/frontend/category/view', ['id' => $categoryId]))) { $this->_categoryPaths[$categoryId] = $path; } elseif (($category = Category::findOne($categoryId)) && !$category->isRoot() && ($path = $this->findCategoryMenuPath($category->parent_id, $menuMap))) { $this->_categoryPaths[$categoryId] = $path . '/' . $category->alias; } else { $this->_categoryPaths[$categoryId] = false; } } return $this->_categoryPaths[$categoryId]; }
* @var yii\web\View $this * @var yii\data\ActiveDataProvider $dataProvider * @var \gromver\platform\news\models\CategorySearch $searchModel * @var string $route */ $this->title = Yii::t('gromver.platform', 'Select Category'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="category-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' => 'title', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) { /** @var $model \gromver\platform\news\models\Category */ return str_repeat(" • ", max($model->level - 1, 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\news\models\Category */ return $model->getStatusLabel(); }, 'width' => '100px', 'filter' => \gromver\platform\news\models\Category::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\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(['/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\news\models\Category */ 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', 'Category: {title}', ['title' => $model->title]), 'route' => \gromver\platform\core\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>
<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]]);
/** * @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()]]]]]]]; }
/** * @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()]); }
/** * @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']]; }