/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tag::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'hits' => $this->hits, 'lock' => $this->lock]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'group', $this->group])->andFilterWhere(['like', 'metakey', $this->metakey])->andFilterWhere(['like', 'metadesc', $this->metadesc]); return $dataProvider; }
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' => '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),
// echo $this->render('_search', ['model' => $searchModel]); ?> <?php /*<p> <?= Html::a(Yii::t('gromver.platform', 'Create {modelClass}', [ 'modelClass' => 'Tag', ]), ['create'], ['class' => 'btn btn-success']) ?> </p>*/ ?> <?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\core\modules\tag\models\Tag $model */ return $model->title . '<br/>' . Html::tag('small', ' — ' . $model->alias, ['class' => 'text-muted']); }, 'format' => 'html'], ['attribute' => 'group', 'width' => '150px', 'vAlign' => GridView::ALIGN_MIDDLE, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => \yii\helpers\ArrayHelper::map(\gromver\platform\core\modules\tag\models\Tag::find()->groupBy('group')->andWhere('[[group]] != "" AND [[group]] IS NOT NULL')->all(), 'group', 'group'), 'theme' => \kartik\select2\Select2::THEME_BOOTSTRAP, 'pluginOptions' => ['allowClear' => true, 'multiple' => false, 'placeholder' => Yii::t('gromver.platform', 'Select ...')]]], ['attribute' => 'status', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) { /** @var $model \gromver\platform\core\modules\tag\models\Tag */ return $model->status === \gromver\platform\core\modules\tag\models\Tag::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\core\modules\tag\models\Tag::statusLabels(), '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'], ['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.')); ?>
/** * @param \gromver\platform\core\components\MenuRequestInfo $requestInfo * @return array */ public function parseAllPosts($requestInfo) { if ($requestInfo->requestRoute == 'rss') { return ['news/frontend/post/rss', []]; } elseif (preg_match("#^(\\d{4})/(\\d{1,2})/(\\d{1,2})\$#", $requestInfo->requestRoute, $matches)) { //новости за определенную дату return ['news/frontend/post/day', ['year' => $matches[1], 'month' => $matches[2], 'day' => $matches[3]]]; } elseif (preg_match("#^((.*)/)(([^/]+)\\.{$this->postSuffix})\$#", $requestInfo->requestRoute, $matches)) { //ищем пост $categoryPath = $matches[2]; //путь категории поста $postAlias = $matches[4]; //алиас поста /** @var Category $category */ $category = Category::findOne(['path' => $categoryPath]); if ($category && ($postId = Post::find()->select('id')->where(['alias' => $postAlias, 'category_id' => $category->id])->scalar())) { return ['news/frontend/post/view', ['id' => $postId]]; } } elseif (preg_match("#^(tag/([^/]+))\$#", $requestInfo->requestRoute, $matches)) { //ищем тег $tagAlias = $matches[2]; if ($tagId = Tag::find()->select('id')->where(['alias' => $tagAlias])->scalar()) { return ['news/frontend/post/tag', ['tag_id' => $tagId]]; } } }
<div class="col-sm-6"> <?php echo $form->field($model, 'alias', ['wrapperOptions' => ['class' => 'col-sm-9']])->textInput(['maxlength' => 255, 'placeholder' => Yii::t('gromver.platform', 'Auto-generate')]); ?> </div> </div> <div class="row"> <div class="col-sm-6"> <?php echo $form->field($model, 'status', ['wrapperOptions' => ['class' => 'col-sm-9']])->dropDownList(['' => Yii::t('gromver.platform', 'Select ...')] + $model->statusLabels()); ?> </div> <div class="col-sm-6"> <?php echo $form->field($model, 'group', ['wrapperOptions' => ['class' => 'col-sm-9']])->widget(\kartik\select2\Select2::className(), ['theme' => \kartik\select2\Select2::THEME_BOOTSTRAP, 'data' => \yii\helpers\ArrayHelper::map(\gromver\platform\core\modules\tag\models\Tag::find()->groupBy('group')->andWhere('[[group]] != "" AND [[group]] IS NOT NULL')->all(), 'group', 'group'), 'pluginOptions' => ['tags' => true, 'allowClear' => true, 'multiple' => false, 'placeholder' => Yii::t('gromver.platform', 'Select ...')]]); ?> </div> </div> <ul class="nav nav-tabs"> <li class="active"><a href="#meta-options" data-toggle="tab"><?php echo Yii::t('gromver.platform', 'SEO'); ?> </a></li> </ul> <br/> <div class="tab-content"> <div id="meta-options" class="tab-pane active"> <?php echo $form->field($model, 'metakey')->textInput(['maxlength' => 255]);
* @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>
/** * Отдает список групп тегов для Select2 виджета * @param string|null $q * @return array */ public function actionTagGroupList($q = null) { \Yii::$app->response->format = Response::FORMAT_JSON; $results = Tag::find()->select('group AS id, group AS text')->andFilterWhere(['like', 'group', urldecode($q)])->groupBy('group')->limit(20)->asArray()->all(); return ['results' => $results]; }