コード例 #1
1
ファイル: Module.php プロジェクト: gromver/yii2-platform
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param \yii\web\Application $app the application currently running
  */
 public function bootstrap($app)
 {
     $app->set($this->id, $this);
     Yii::$container->set('gromver\\models\\fields\\EditorField', ['controller' => 'grom/media/manager']);
     Yii::$container->set('gromver\\models\\fields\\MediaField', ['controller' => 'grom/media/manager']);
     Yii::$container->set('gromver\\modulequery\\ModuleQuery', ['cache' => $app->cache, 'cacheDependency' => new ExpressionDependency(['expression' => '\\Yii::$app->getModulesHash()'])]);
     Yii::$container->set('gromver\\platform\\frontend\\components\\MenuMap', ['cache' => $app->cache, 'cacheDependency' => Table::dependency(MenuItem::tableName())]);
     /** @var MenuManager $manager */
     $manager = \Yii::createObject(MenuManager::className());
     $rules = [$manager];
     if (is_array($this->blockModules) && count($this->blockModules)) {
         $rules['grom/<module:(' . implode('|', $this->blockModules) . ')><path:(/.*)?>'] = 'grom/default/page-not-found';
         //блокируем доступ к контент модулям напрямую
     }
     $app->urlManager->addRules($rules, false);
     //вставляем в начало списка
     $app->set('menuManager', $manager);
     ModuleQuery::instance()->implement('\\gromver\\platform\\common\\interfaces\\BootstrapInterface')->invoke('bootstrap', [$app]);
 }
コード例 #2
0
 public function createTagItems($requestInfo)
 {
     if ($path = $requestInfo->menuMap->getMenuPathByRoute('grom/tag/default/index')) {
         $path .= '/' . (isset($requestInfo->requestParams['alias']) ? $requestInfo->requestParams['alias'] : $requestInfo->requestParams['id']);
         unset($requestInfo->requestParams['id'], $requestInfo->requestParams['alias']);
         return MenuItem::toRoute($path, $requestInfo->requestParams);
     }
 }
コード例 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MenuItem::find()->noRoots();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['lft' => SORT_ASC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'menu_type_id' => $this->menu_type_id, 'parent_id' => $this->parent_id, 'status' => $this->status, 'link_type' => $this->link_type, 'secure' => $this->secure, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'lft' => $this->lft, 'rgt' => $this->rgt, 'level' => $this->level, 'ordering' => $this->ordering, 'hits' => $this->hits, 'lock' => $this->lock]);
     $query->andFilterWhere(['like', 'language', $this->language])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'path', $this->path])->andFilterWhere(['like', 'note', $this->note])->andFilterWhere(['like', 'link', $this->link])->andFilterWhere(['like', 'link_params', $this->link_params])->andFilterWhere(['like', 'layout_path', $this->layout_path])->andFilterWhere(['like', 'access_rule', $this->access_rule])->andFilterWhere(['like', 'metakey', $this->metakey])->andFilterWhere(['like', 'metadesc', $this->metadesc])->andFilterWhere(['like', 'robots', $this->robots]);
     return $dataProvider;
 }
コード例 #4
0
ファイル: SiteMenu.php プロジェクト: gromver/yii2-platform
 public function init()
 {
     parent::init();
     if (empty($this->type)) {
         throw new InvalidConfigException(Yii::t('gromver.platform', 'Menu type must be set.'));
     }
     $this->language or $this->language = Yii::$app->language;
     $this->_rawItems = Yii::$app->db->cache(function ($db) {
         return MenuItem::find()->type($this->type)->published()->language($this->language)->asArray()->orderBy('lft')->all($db);
     }, $this->cacheDuration, Table::dependency(MenuItem::tableName()));
     $i = 0;
     $this->_items = $this->prepareMenuItems($i, 2);
 }
コード例 #5
0
 public function createSearch($requestInfo)
 {
     if ($path = $requestInfo->menuMap->getMenuPathByRoute('grom/search/default/index')) {
         return MenuItem::toRoute($path, $requestInfo->requestParams);
     }
 }
コード例 #6
0
ファイル: MenuType.php プロジェクト: gromver/yii2-platform
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getItems()
 {
     return $this->hasMany(MenuItem::className(), ['menu_type_id' => 'id'])->orderBy('lft');
 }
コード例 #7
0
ファイル: select.php プロジェクト: gromver/yii2-platform
 * @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>
コード例 #8
0
 /**
  * Finds the MenuItem model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return MenuItem the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MenuItem::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.'));
     }
 }
コード例 #9
0
ファイル: Routers.php プロジェクト: gromver/yii2-platform
 /**
  * Renders the content of a menu item.
  * Note that the container and the sub-menus are not rendered here.
  * @param array $item the menu item to be rendered. Please refer to [[items]] to see what data might be in the item.
  * @return string the rendering result
  */
 protected function renderItem($item)
 {
     $routers = '';
     $header = '';
     if (isset($item['label'])) {
         $template = ArrayHelper::getValue($item, 'headerTemplate', $this->headerTemplate);
         $header = strtr($template, ['{icon}' => $item['icon'], '{label}' => $item['label']]);
     }
     foreach ($item['routers'] as $router) {
         $template = ArrayHelper::getValue($router, 'template', $this->routerTemplate);
         $routerContent = strtr($template, ['{icon}' => $router['icon'], '{link}' => isset($router['url']) ? Html::a($router['label'], $router['url']) : Html::a($router['label'], '#', ['onclick' => ModalIFrame::emitDataJs(['link' => MenuItem::toRoute($router['route'])])])]);
         $routerOptions = array_merge($this->routerOptions, $router['options']);
         $routers .= Html::tag(ArrayHelper::remove($routerOptions, 'tag', 'div'), $routerContent, $routerOptions);
     }
     $template = ArrayHelper::getValue($item, 'template', $this->itemTemplate);
     return strtr($template, ['{header}' => $header, '{routers}' => $routers]);
 }
コード例 #10
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];
 }
コード例 #11
0
ファイル: MenuManager.php プロジェクト: gromver/yii2-platform
 /**
  * Creates a URL according to the given route and parameters.
  * @param UrlManager $manager the URL manager
  * @param string $route the route. It should not have slashes at the beginning or the end.
  * @param array $params the parameters
  * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL.
  */
 public function createUrl($manager, $route, $params)
 {
     $language = $manager->getLanguageContext();
     if ($path = $this->getMenuMap($language)->getMenuPathByRoute(MenuItem::toRoute($route, $params))) {
         return $path;
     }
     $requestInfo = new MenuRequest(['menuMap' => $this->getMenuMap($language), 'requestRoute' => $route, 'requestParams' => $params]);
     foreach ($this->_createUrlRules as $rule) {
         if ($result = $rule->process($requestInfo, $this)) {
             return $result;
         }
     }
     return false;
 }
コード例 #12
0
ファイル: select.php プロジェクト: gromver/yii2-platform
/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var gromver\platform\backend\modules\menu\models\MenuItemSearch $searchModel
 */
$this->title = Yii::t('gromver.platform', 'Select Menu Item');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="menu-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\MenuItem */
    return str_repeat(" • ", max($model->level - 2, 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\MenuItem */
    return $model->getStatusLabel();
}, 'filter' => \gromver\platform\common\models\MenuItem::statusLabels()], ['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', 'Menu Item: {title}', ['title' => $model->title]), 'link' => Yii::$app->urlManagerFrontend->createUrl($model->viewLink), '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>
コード例 #13
0
ファイル: index.php プロジェクト: gromver/yii2-platform
?>

    <?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\MenuItem */
    return \gromver\platform\backend\widgets\Translator::widget(['model' => $model]);
}, 'format' => 'raw', 'filter' => Yii::$app->getLanguagesList()], ['attribute' => 'menu_type_id', 'width' => '100px', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\MenuItem */
    return $model->menuType->title;
}, 'filter' => \yii\helpers\ArrayHelper::map(\gromver\platform\common\models\MenuType::find()->all(), 'id', 'title')], ['attribute' => 'title', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\MenuItem */
    return str_repeat(" • ", max($model->level - 2, 0)) . $model->title . '<br/>' . Html::tag('small', $model->path);
}, 'format' => 'html'], 'link', ['attribute' => 'status', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\MenuItem */
    return Html::beginTag('div', ['class' => 'btn-group']) . Html::a('<i class="glyphicon glyphicon-star"></i>', \yii\helpers\Url::to(['status', 'id' => $model->id, 'status' => $model::STATUS_MAIN_PAGE]), ['class' => 'btn btn-xs' . ($model::STATUS_MAIN_PAGE == $model->status ? ' btn-success active' : ' btn-default'), 'data-pjax' => 0, 'data-method' => 'post']) . Html::a('<i class="glyphicon glyphicon-ok-circle"></i>', \yii\helpers\Url::to(['status', 'id' => $model->id, 'status' => $model::STATUS_PUBLISHED]), ['class' => 'btn btn-xs' . ($model::STATUS_PUBLISHED == $model->status ? ' btn-primary active' : ' btn-default'), 'data-pjax' => 0, 'data-method' => 'post']) . Html::a('<i class="glyphicon glyphicon-remove-circle"></i>', \yii\helpers\Url::to(['status', 'id' => $model->id, 'status' => $model::STATUS_UNPUBLISHED]), ['class' => 'btn btn-xs' . ($model::STATUS_UNPUBLISHED == $model->status ? ' btn-default active' : ' btn-default'), 'data-pjax' => 0, 'data-method' => 'post']) . Html::endTag('div');
}, 'filter' => \gromver\platform\common\models\MenuItem::statusLabels(), 'width' => '90px', 'format' => 'raw'], ['attribute' => 'ordering', 'value' => function ($model) {
    /** @var $model \gromver\platform\common\models\MenuItem */
    return Html::input('text', 'order', $model->ordering, ['class' => 'form-control']);
}, 'format' => 'raw', 'width' => '50px'], ['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', 'menu_type_id' => $searchModel->menu_type_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]]);
?>

</div>

<script>
    function processOrdering(el) {
        var $el = $(el),
            $grid = $('#table-grid'),
            selection = $grid.yiiGridView('getSelectedRows'),
            data = {}
        if(!selection.length) {
            alert(<?php 
コード例 #14
0
ファイル: MenuMap.php プロジェクト: gromver/yii2-platform
 /**
  * @param $link
  * @return MenuItem
  */
 public function getMenuByLink($link)
 {
     $menuId = array_search($link, $this->_links);
     return $menuId ? MenuItem::findOne($menuId) : null;
 }