/** * @param \gromver\platform\basic\components\MenuRequestInfo $requestInfo * @return mixed|null|string */ public function createTagItems($requestInfo) { if ($path = $requestInfo->menuMap->getMenuPathByRoute('grom/tag/frontend/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); } }
*/ $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', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '60px'], ['attribute' => 'category_id', 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '80px', 'value' => function ($model) { return @$model->category->title; }, 'filter' => \yii\helpers\ArrayHelper::map(\gromver\platform\basic\modules\news\models\Category::find()->excludeRoots()->orderBy('lft')->all(), 'id', function ($model) { return str_repeat(" • ", max($model->level - 2, 0)) . $model->title; })], ['attribute' => 'language', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '60px', 'filter' => Yii::$app->getAcceptedLanguagesList()], ['attribute' => 'title', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) { /** @var $model \gromver\platform\basic\modules\news\models\Post */ return $model->title . '<br/>' . Html::tag('small', $model->alias, ['class' => 'text-muted']); }, 'format' => 'html'], ['attribute' => 'status', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) { /** @var $model \gromver\platform\basic\modules\news\models\Post */ return $model->getStatusLabel(); }, 'width' => '100px', 'filter' => \gromver\platform\basic\modules\news\models\Post::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\basic\modules\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\basic\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(['/grom/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\basic\modules\news\models\Post */ 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', 'Post: {title}', ['title' => $model->title]), 'route' => \gromver\platform\basic\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>
/** * 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(); $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; }
/** * Находит путь к пункту меню ссылающемуся на категорию $categoryId, либо ее предка * Если путь ведет к предку, то достраиваем путь категории $categoryId * @param $categoryId * @param $menuMap \gromver\platform\basic\components\MenuMap * @return null|string */ private function findCategoryMenuPath($categoryId, $menuMap) { /** @var Category $category */ if (!isset($this->_categoryPaths[$menuMap->language][$categoryId])) { if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute('grom/news/frontend/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]; }
/** * @param $requestInfo MenuRequestInfo; * @return mixed|null|string */ public function createSearch($requestInfo) { if ($path = $requestInfo->menuMap->getMenuPathByRoute('grom/search/sql/frontend/default/index')) { return MenuItem::toRoute($path, $requestInfo->requestParams); } }
/** * 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]); }
/** * Находит путь к пункту меню ссылающемуся на категорию $categoryId, либо ее предка * Если путь ведет к предку, то достраиваем путь категории $categoryId * @param $pageId * @param $menuMap \gromver\platform\basic\components\MenuMap * @return null|string */ private function findPageMenuPath($pageId, $menuMap) { /** @var Page $page */ if (!isset($this->_pagePaths[$menuMap->language][$pageId])) { if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute('grom/page/frontend/default/guide', ['id' => $pageId]))) { $this->_pagePaths[$menuMap->language][$pageId] = $path; } elseif (($page = Page::findOne($pageId)) && !$page->isRoot() && ($path = $this->findPageMenuPath($page->parent_id, $menuMap))) { $this->_pagePaths[$menuMap->language][$pageId] = $path . '/' . $page->alias; } else { $this->_pagePaths[$menuMap->language][$pageId] = false; } } return $this->_pagePaths[$menuMap->language][$pageId]; }