示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MenuItem::find();
     $query->with(['menuType']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['lft' => SORT_ASC]]]);
     if (!($this->load($params) && $this->validate())) {
         if ($this->excludeRoots) {
             $query->excludeRoots();
         }
         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]);
     if ($this->excludeRoots) {
         $query->excludeRoots();
     }
     if ($this->excludeItem && ($item = MenuItem::findOne($this->excludeItem))) {
         /** @var $item MenuItem */
         $query->excludeItem($item);
     }
     return $dataProvider;
 }
示例#2
0
文件: select.php 项目: oakcms/oakcms
$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', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '60px'], ['attribute' => 'language', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '60px', 'filter' => Yii::$app->getAcceptedLanguagesList()], ['attribute' => 'menu_type_id', 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '120px', 'value' => function ($model) {
    /** @var $model \app\modules\menu\models\MenuItem */
    return $model->menuType->title;
}, 'filter' => \yii\helpers\ArrayHelper::map(\app\modules\menu\models\MenuType::find()->all(), 'id', 'title')], ['attribute' => 'title', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \app\modules\menu\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', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \app\modules\menu\models\MenuItem */
    return $model->getStatusLabel();
}, 'width' => '150px', 'filter' => \app\modules\menu\models\MenuItem::statusLabels()], ['header' => Yii::t('gromver.platform', 'Action'), 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \app\modules\menu\models\MenuItem */
    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', 'Menu Item: {title}', ['title' => $model->title]), 'route' => Yii::$app->urlManager->createUrl($model->getFrontendViewLink()), '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>
示例#3
0
 /**
  * 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 = \Yii::$app->language;
     $menuMap = $this->menuManager->getMenuMap($language);
     if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute($route, $params))) {
         return $path;
     }
     $requestInfo = new MenuRequestInfo(['menuMap' => $menuMap, 'requestRoute' => $route, 'requestParams' => $params]);
     foreach ($this->_createUrlRules as $rule) {
         if ($result = $rule->process($requestInfo, $this)) {
             return $result;
         }
     }
     return false;
 }
示例#4
0
 /**
  * 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['items'] 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::postDataJs(['route' => MenuItem::toRoute($router['route']), 'link' => Yii::$app->urlManager->createUrl($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]);
 }
示例#5
0
 public function actionDefault()
 {
     $this->data->items = MenuItem::findAllTree();
 }
示例#6
0
文件: MenuMap.php 项目: oakcms/oakcms
 /**
  * @param string $link
  * @return MenuItem
  */
 public function getMenuByLink($link)
 {
     $menuId = array_search($link, $this->_links);
     return $menuId ? MenuItem::findOne($menuId) : null;
 }
示例#7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getItems()
 {
     return $this->hasMany(MenuItem::className(), ['menu_type_id' => 'id'])->orderBy('lft');
 }
示例#8
0
文件: index.php 项目: oakcms/oakcms
    </div>

    <?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' => 'language', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '80px', 'value' => function ($model) {
    /** @var $model \app\modules\menu\models\MenuItem */
    //return \app\modules\main\widgets\TranslationsBackend::widget(['model' => $model]);
}, 'format' => 'raw'], ['attribute' => 'menu_type_id', 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '100px', 'value' => function ($model) {
    /** @var $model \app\modules\menu\models\MenuItem */
    return $model->menuType->title;
}, 'filter' => \yii\helpers\ArrayHelper::map(\app\modules\menu\models\MenuType::find()->all(), 'id', 'title')], ['attribute' => 'title', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \app\modules\menu\models\MenuItem */
    return str_repeat(" • ", max($model->level - 2, 0)) . $model->title . '<br/>' . Html::tag('small', $model->path);
}, 'format' => 'html'], ['attribute' => 'link', 'vAlign' => GridView::ALIGN_MIDDLE], ['attribute' => 'status', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \app\modules\menu\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' => \app\modules\menu\models\MenuItem::statusLabels(), 'width' => '100px', 'format' => 'raw'], ['attribute' => 'ordering', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \app\modules\menu\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', 'menuTypeId' => $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 
示例#9
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.'));
     }
 }
示例#10
0
文件: Menu.php 项目: oakcms/oakcms
 /**
  * @return array
  */
 protected function items()
 {
     $rawItems = MenuItem::find()->type($this->type)->published()->language($this->language)->orderBy('lft')->all();
     if (count($rawItems)) {
         return $this->prepareItems($rawItems, $rawItems[0]->level);
     }
     return [];
 }
示例#11
0
 public function actionMoveAfter($id, $to)
 {
     try {
         $item = MenuItem::findByPK($id);
         if (empty($item)) {
             throw new Exception('Source element does not exist');
         }
         $destination = MenuItem::findByPK($to);
         if (empty($destination)) {
             throw new Exception('Destination element does not exist');
         }
         $item->insertAfter($destination);
         $this->data->result = true;
     } catch (Exception $e) {
         $this->data->result = false;
         $this->data->error = $e->getMessage();
     }
 }
示例#12
0
文件: _form.php 项目: oakcms/oakcms
?>
</a></li>
        <li><a href="#link-options" data-toggle="tab"><?php 
echo Yii::t('gromver.platform', 'Link params');
?>
</a></li>
        <li><a href="#meta-options" data-toggle="tab"><?php 
echo Yii::t('gromver.platform', 'SEO');
?>
</a></li>
    </ul>
    <br/>
    <div class="tab-content">
        <div id="main" class="tab-pane active">
            <?php 
echo $form->field($model, 'link_type')->dropDownList(\app\modules\menu\models\MenuItem::linkTypeLabels());
?>

            <?php 
$this->registerJs("\$('#" . Html::getInputId($model, 'link_type') . "').change(function (event){\n                if(\$(this).val() === '" . \app\modules\menu\models\MenuItem::LINK_ROUTE . "') {\n                    \$('a#router').attr('href', " . \yii\helpers\Json::encode(\yii\helpers\Url::toRoute(['routers'])) . ")\n                } else {\n                    \$('a#router').attr('href', " . \yii\helpers\Json::encode(\yii\helpers\Url::toRoute(['select', 'MenuItemSearch[link_type]' => \app\modules\menu\models\MenuItem::LINK_ROUTE])) . ")\n                }\n            }).change()");
?>

            <?php 
$linkLabel = Html::activeLabel($model, 'link');
$linkInputId = Html::getInputId($model, 'link');
echo $form->field($model, 'link', ['template' => "{label}\n{beginWrapper}\n<div class=\"input-group\">{input}{controls}</div>\n{error}\n{endWrapper}\n{hint}", 'parts' => ['{controls}' => \app\widgets\ModalIFrame::widget(['options' => ['id' => 'router', 'class' => 'input-group-btn'], 'url' => ['routers'], 'label' => Html::tag('span', '<span class="glyphicon glyphicon-folder-open"></span>', ['class' => 'btn btn-default']), 'dataHandler' => "function(data){\n                                    \$('#{$linkInputId}').val(data.route)\n                                }"])]])->textInput(['maxlength' => 1024]);
?>

            <?php 
echo $form->field($model, 'access_rule')->dropDownList(\yii\helpers\ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name'), ['prompt' => 'Не выбрано']);
?>