protected function launch() { if (!$this->tag instanceof Tag) { $this->tag = Tag::findOne(intval($this->tag)); } if (empty($this->tag)) { throw new InvalidConfigException(Yii::t('gromver.platform', 'Tag not found.')); } echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->tag->getTagToItems(), 'pagination' => ['pageSize' => $this->pageSize]]), 'itemLayout' => $this->itemLayout, 'model' => $this->tag]); $this->tag->hit(); }
public function init() { parent::init(); $this->language or $this->language = Yii::$app->language; $this->_tags = (new Query())->select('t.id, t.title, t.alias, t.language, count(t2m.item_id) AS weight')->from(Tag::tableName() . ' t')->innerJoin(Tag::pivotTableName() . ' t2m', 't.id=t2m.tag_id')->where(['t.language' => $this->language])->groupBy('t.id')->all(); shuffle($this->_tags); }
public function loadModel($id) { if (!($model = Tag::findOne($id))) { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested tag does not exist.')); } return $model; }
public function parseTagCloud($requestInfo) { if (preg_match('/^\\d+$/', $requestInfo->requestRoute)) { return ['grom/tag/default/view', ['id' => $requestInfo->requestRoute]]; } else { return ['grom/tag/default/view', ['id' => Tag::find()->select('id')->where(['alias' => $requestInfo->requestRoute])->scalar()]]; } }
protected function launch() { if (!$this->tag instanceof Tag) { $this->tag = Tag::findOne(intval($this->tag)); } if (empty($this->tag)) { throw new InvalidConfigException(Yii::t('gromver.platform', 'Tag must be set.')); } echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->getQuery(), 'pagination' => ['pageSize' => $this->pageSize], 'sort' => ['defaultOrder' => [$this->sort => (int) $this->dir]]]), 'itemLayout' => $this->itemLayout, 'model' => $this->tag]); }
/** * 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', 'language', $this->language])->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; }
/** * @param $event \Yii\base\Event */ public function afterSave($event) { $this->owner->getDb()->transaction(function ($db) use($event) { if (isset($this->_tags) && is_array($this->_tags)) { $oldTags = ArrayHelper::map($this->owner->tags, 'id', 'id'); $this->owner->setIsNewRecord(false); $toAppend = array_diff($this->_tags, $oldTags); $toRemove = array_diff($oldTags, $this->_tags); foreach ($toAppend as $id) { $tag = Tag::findOne($id); $this->owner->link('tags', $tag, ['item_class' => $this->owner->className()]); } if ($event->name == BaseActiveRecord::EVENT_AFTER_UPDATE) { foreach ($toRemove as $id) { $tag = Tag::findOne($id); $this->owner->unlink('tags', $tag, true); } } } }); }
<?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' => 'yii\\grid\\CheckboxColumn'], ['attribute' => 'id', 'width' => '50px'], ['attribute' => 'language', 'width' => '80px', 'value' => function ($model) { /** @var $model \gromver\platform\common\models\Tag */ return \gromver\platform\backend\widgets\Translator::widget(['model' => $model]); }, 'format' => 'html', 'filter' => Yii::$app->getLanguagesList()], 'title', 'alias', ['attribute' => 'group', 'filter' => \yii\helpers\ArrayHelper::map(\gromver\platform\common\models\Tag::find()->groupBy('group')->andWhere('[[group]]!="" AND [[group]] IS NOT NULL')->all(), 'group', 'group')], ['attribute' => 'status', 'value' => function ($model) { /** @var $model \gromver\platform\common\models\Tag */ return $model->status === \gromver\platform\common\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-default btn-xs', 'data-pjax' => '0', 'data-method' => 'post']); }, 'filter' => \gromver\platform\common\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.')); ?> ) return }
/** * Finds the Tag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tag::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.')); } }
* @var string $route */ $this->title = Yii::t('gromver.platform', 'Select Page'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="page-index"> <?php /*<h1><?= Html::encode($this->title) ?></h1>*/ ?> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'id' => 'grid', 'pjax' => true, 'pjaxSettings' => ['neverTimeout' => true], 'columns' => [['attribute' => 'id', 'width' => '50px'], ['attribute' => 'language', 'width' => '50px', 'filter' => Yii::$app->getLanguagesList()], ['attribute' => 'title', 'value' => function ($model) { /** @var $model \gromver\platform\common\models\Page */ return $model->title . '<br/>' . Html::tag('small', $model->alias, ['class' => 'text-muted']); }, 'format' => 'html'], ['attribute' => 'status', 'value' => function ($model, $index, $widget) { /** @var $model \gromver\platform\common\models\Page */ return $model->getStatusLabel(); }, 'filter' => \gromver\platform\common\models\Page::statusLabels()], ['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/default/tag-list']]], ['value' => function ($model) use($route) { 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', 'Page: {title}', ['title' => $model->title]), 'link' => \gromver\platform\common\models\MenuItem::toRoute($route, ['id' => $model->id]), '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>
<?php /** * @var $this yii\web\View * @var $tags Tag[] */ use yii\helpers\Html; use gromver\platform\common\models\Tag; echo Html::beginTag('div', ['class' => 'tag-cloud']); foreach ($tags as $tag) { echo Html::a(Html::encode($tag['title']), Tag::viewLink($tag), ['style' => 'font-size: ' . ($this->context->fontBase + $this->context->fontSpace / $this->context->maxWeight * $tag['weight']) . 'px', 'class' => 'tag']); } echo Html::endTag('div');
public function parseAllPosts($requestInfo) { if ($requestInfo->requestRoute == 'rss') { return ['grom/news/post/rss', []]; } elseif (preg_match("#^(\\d{4})/(\\d{1,2})/(\\d{1,2})\$#", $requestInfo->requestRoute, $matches)) { //новости за определенную дату return ['grom/news/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]; //алиас поста $category = Category::findOne(['path' => $categoryPath, 'language' => $requestInfo->menuMap->language]); if ($category && ($postId = Post::find()->select('id')->where(['alias' => $postAlias, 'category_id' => $category->id])->scalar())) { return ['grom/news/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 ['grom/tag/default/posts', ['id' => $tagId]]; } } }
'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.')); ?> ) return }
public function actionTagList($query = null, $language = null) { $result = Tag::find()->select('id AS value, title AS text, group AS optgroup')->filterWhere(['like', 'title', urldecode($query)])->andFilterWhere(['language' => $language])->limit(20)->asArray()->all(); echo Json::encode($result); }