Пример #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
 public function loadCategoryModel($id)
 {
     if (!($model = Category::findOne($id))) {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested category does not exist.'));
     }
     return $model;
 }
Пример #3
0
 public static function filter()
 {
     $filters = [['not' => ['and' => [['type' => ['value' => 'post']], ['term' => ['published' => false]]]]]];
     if ($unpublishedCategories = Category::find()->unpublished()->select('{{%grom_category}}.id')->column()) {
         $filters[] = ['not' => ['and' => [['type' => ['value' => 'post']], ['term' => ['category_id' => $unpublishedCategories]]]]];
     }
     return $filters;
 }
Пример #4
0
 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]);
 }
Пример #5
0
 public static function filter()
 {
     $filters = [['not' => ['and' => [['type' => ['value' => 'category']], ['term' => ['published' => false]]]]]];
     if ($unpublishedCategories = \gromver\platform\common\models\Category::find()->unpublished()->select('{{%grom_category}}.id')->column()) {
         $filters[] = ['not' => ['and' => [['type' => ['value' => 'category']], ['term' => ['parent_id' => $unpublishedCategories]]]]];
     }
     return $filters;
 }
Пример #6
0
 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]);
 }
Пример #7
0
 protected function launch()
 {
     if ($this->category && !$this->category instanceof Category) {
         $this->category = Category::findOne(intval($this->category));
     }
     if (!empty($this->category)) {
         $this->language = null;
     } else {
         $this->language or $this->language = Yii::$app->language;
     }
     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]);
 }
Пример #8
0
 /**
  * @param $params
  * @return ActiveDataProvider
  */
 public function search($params, $withRoots = false)
 {
     $query = $withRoots ? Category::find() : Category::find()->noRoots();
     $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) {
         $query->andWhere('{{%grom_category}}.published_at >= :timestamp', ['timestamp' => $this->published_at]);
     }
     $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->tags) {
         $query->innerJoinWith('tags')->andFilterWhere(['{{%grom_tag}}.id' => $this->tags]);
     }
     return $dataProvider;
 }
Пример #9
0
 public function actionCategories($selected = '')
 {
     if (isset($_POST['depdrop_parents'])) {
         $parents = $_POST['depdrop_parents'];
         if ($parents != null) {
             $language = $parents[0];
             $out = array_map(function ($value) {
                 return ['id' => $value['id'], 'name' => str_repeat(" • ", $value['level'] - 1) . $value['title']];
             }, Category::find()->noRoots()->language($language)->orderBy('lft')->asArray()->all());
             echo Json::encode(['output' => $out, 'selected' => $selected ? $selected : '']);
             return;
         }
     }
     echo Json::encode(['output' => '', 'selected' => $selected]);
 }
Пример #10
0
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var gromver\platform\backend\modules\news\models\PostSearch $searchModel
 */
$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', 'width' => '50px'], ['attribute' => 'category_id', 'width' => '80px', 'value' => function ($model) {
    return @$model->category->title;
}, 'filter' => \yii\helpers\ArrayHelper::map(\gromver\platform\common\models\Category::find()->noRoots()->orderBy('lft')->all(), 'id', function ($model) {
    return str_repeat(" • ", max($model->level - 2, 0)) . $model->title;
})], ['attribute' => 'language', 'filter' => Yii::$app->getLanguagesList()], ['attribute' => 'title', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Post */
    return $model->title . '<br/>' . Html::tag('small', $model->alias, ['class' => 'text-muted']);
}, 'format' => 'html'], ['attribute' => 'status', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Post */
    return $model->getStatusLabel();
}, 'filter' => \gromver\platform\common\models\Post::statusLabels()], ['attribute' => 'published_at', 'format' => ['date', 'd MMM Y H:mm'], 'width' => '160px', 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['options' => ['value' => is_int($searchModel->published_at) ? date('d.m.Y', $searchModel->published_at) : ''], 'pluginOptions' => ['format' => 'dd.mm.yyyy']]], ['attribute' => 'tags', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Post */
    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) {
    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', 'Post: {title}', ['title' => $model->title]), '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]]);
?>
Пример #11
0
/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var \gromver\platform\backend\modules\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', 'width' => '50px'], ['attribute' => 'language', 'width' => '50px', 'filter' => Yii::$app->getLanguagesList()], ['attribute' => 'title', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\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', 'value' => function ($model, $index, $widget) {
    /** @var $model \gromver\platform\common\models\Category */
    return $model->getStatusLabel();
}, 'filter' => \gromver\platform\common\models\Category::statusLabels()], ['attribute' => 'published_at', 'format' => ['date', 'd MMM Y H:mm'], 'width' => '160px', 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['options' => ['value' => is_int($searchModel->published_at) ? date('d.m.Y', $searchModel->published_at) : ''], 'pluginOptions' => ['format' => 'dd.mm.yyyy']]], ['attribute' => 'tags', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\Category */
    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']]], ['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', 'Category: {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>
Пример #12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }
Пример #13
0
 /**
  * Находит путь к пункту меню ссылающемуся на категорию $categoryId, либо ее предка
  * Если путь ведет к предку, то достраиваем путь категории $categoryId
  * @param $categoryId
  * @param $menuMap \gromver\platform\frontend\components\MenuMap
  * @return null|string
  */
 private function findCategoryMenuPath($categoryId, $menuMap)
 {
     if (!isset($this->_categoryPaths[$menuMap->language][$categoryId])) {
         if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute('grom/news/category/view', ['id' => $categoryId]))) {
             $this->_categoryPaths[$menuMap->language][$categoryId] = $path;
         } elseif (($category = Category::findOne($categoryId)) && !$category->isRoot() && ($path = $this->findCategoryMenuPath($category->parent_id, $menuMap))) {
             $this->_categoryPaths[$menuMap->language][$categoryId] = $path . '/' . $category->alias;
         } else {
             $this->_categoryPaths[$menuMap->language][$categoryId] = false;
         }
     }
     return $this->_categoryPaths[$menuMap->language][$categoryId];
 }
Пример #14
0
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 \gromver\platform\common\models\Category $model */
    return \gromver\platform\backend\widgets\Translator::widget(['model' => $model]);
}, 'format' => 'raw', 'filter' => Yii::$app->getLanguagesList()], ['attribute' => 'title', 'value' => function ($model) {
    /** @var \gromver\platform\common\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', 'value' => function ($model) {
    /** @var \gromver\platform\common\models\Category $model */
    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']]], ['header' => Yii::t('gromver.platform', 'Posts'), 'value' => function ($model) {
    /** @var \gromver\platform\common\models\Category $model */
    return Html::a('(' . $model->getPosts()->count() . ')', ['post/index', 'PostSearch[category_id]' => $model->id], ['data-pjax' => 0]);
}, 'format' => 'raw'], ['attribute' => 'published_at', 'format' => ['date', 'd MMM Y H:mm'], 'width' => '160px', 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['options' => ['value' => is_int($searchModel->published_at) ? date('d.m.Y', $searchModel->published_at) : ''], 'pluginOptions' => ['format' => 'dd.mm.yyyy']]], ['attribute' => 'status', 'value' => function ($model, $index, $widget) {
    /** @var $model \gromver\platform\common\models\Category */
    return $model->status === \gromver\platform\common\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-default btn-xs', 'data-pjax' => '0', 'data-method' => 'post']);
}, 'filter' => \gromver\platform\common\models\Category::statusLabels(), 'format' => 'raw', 'width' => '80px'], ['attribute' => 'ordering', 'value' => function ($model, $index) {
    /** @var \gromver\platform\common\models\Category $model */
    return Html::input('text', 'order', $model->ordering, ['class' => 'form-control']);
}, 'format' => 'raw', 'width' => '100px'], ['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 = {}
        if(!selection.length) {
            alert(<?php 
Пример #15
0
 /**
  * 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.'));
     }
 }