Commit 44ff20b4daf10b1cf16aa35e6601a5f4f5a25cf3
1 parent
ae45093c
-Page categories ready
Showing
2 changed files
with
57 additions
and
44 deletions
Show diff stats
backend/views/layouts/menu_items.php
| @@ -35,9 +35,14 @@ | @@ -35,9 +35,14 @@ | ||
| 35 | 'icon' => 'file-text', | 35 | 'icon' => 'file-text', |
| 36 | 'items' => [ | 36 | 'items' => [ |
| 37 | [ | 37 | [ |
| 38 | - 'label' => \Yii::t('core', 'Static pages'), | 38 | + 'label' => \Yii::t('core', 'Pages'), |
| 39 | 'url' => [ '/page/index' ], | 39 | 'url' => [ '/page/index' ], |
| 40 | 'icon' => 'file-text', | 40 | 'icon' => 'file-text', |
| 41 | + ], | ||
| 42 | + [ | ||
| 43 | + 'label' => \Yii::t('core', 'Categories'), | ||
| 44 | + 'url' => [ '/page-category/index' ], | ||
| 45 | + 'icon' => 'archive', | ||
| 41 | ] | 46 | ] |
| 42 | ], | 47 | ], |
| 43 | ], | 48 | ], |
frontend/views/layouts/main.php
| 1 | <?php | 1 | <?php |
| 2 | + | ||
| 2 | /** | 3 | /** |
| 3 | - * @var View $this | ||
| 4 | - * @var string $content | ||
| 5 | - * @var SeoComponent $seo | ||
| 6 | - * @var User $user | 4 | + * @var View $this |
| 5 | + * @var string $content | ||
| 6 | + * @var SeoComponent $seo | ||
| 7 | + * @var User $user | ||
| 8 | + * @var PageCategory[] $pageCategories | ||
| 7 | */ | 9 | */ |
| 10 | + | ||
| 8 | use artbox\core\components\SeoComponent; | 11 | use artbox\core\components\SeoComponent; |
| 9 | use artbox\core\helpers\ImageHelper; | 12 | use artbox\core\helpers\ImageHelper; |
| 10 | use artbox\core\models\Feedback; | 13 | use artbox\core\models\Feedback; |
| 11 | - use artbox\core\models\Page; | 14 | + use artbox\core\models\PageCategory; |
| 12 | use artbox\core\models\User; | 15 | use artbox\core\models\User; |
| 13 | use common\models\Settings; | 16 | use common\models\Settings; |
| 14 | use frontend\assets\AppAsset; | 17 | use frontend\assets\AppAsset; |
| @@ -16,7 +19,7 @@ | @@ -16,7 +19,7 @@ | ||
| 16 | use yii\bootstrap\ActiveForm; | 19 | use yii\bootstrap\ActiveForm; |
| 17 | use yii\bootstrap\Nav; | 20 | use yii\bootstrap\Nav; |
| 18 | use yii\bootstrap\Html; | 21 | use yii\bootstrap\Html; |
| 19 | - use yii\helpers\Json; | 22 | + use yii\db\ActiveQuery; |
| 20 | use yii\helpers\Url; | 23 | use yii\helpers\Url; |
| 21 | use yii\web\View; | 24 | use yii\web\View; |
| 22 | use yii\widgets\Breadcrumbs; | 25 | use yii\widgets\Breadcrumbs; |
| @@ -29,13 +32,21 @@ | @@ -29,13 +32,21 @@ | ||
| 29 | $controller = Yii::$app->controller; | 32 | $controller = Yii::$app->controller; |
| 30 | $default_controller = Yii::$app->defaultRoute; | 33 | $default_controller = Yii::$app->defaultRoute; |
| 31 | $isHome = ( ( $controller->id === $default_controller ) && ( $controller->action->id === $controller->defaultAction ) ) ? true : false; | 34 | $isHome = ( ( $controller->id === $default_controller ) && ( $controller->action->id === $controller->defaultAction ) ) ? true : false; |
| 32 | - /** | ||
| 33 | - * @var Page[] $pages | ||
| 34 | - */ | ||
| 35 | - $pages = Page::find() | ||
| 36 | - ->where([ 'in_menu' => true ]) | ||
| 37 | - ->with('lang.alias') | ||
| 38 | - ->all(); | 35 | + |
| 36 | + $pageCategories = PageCategory::find() | ||
| 37 | + ->with( | ||
| 38 | + [ | ||
| 39 | + 'lang', | ||
| 40 | + 'pages' => function (ActiveQuery $query) { | ||
| 41 | + $query->with('lang.alias') | ||
| 42 | + ->where(['in_menu' => true]) | ||
| 43 | + ->orderBy([ 'sort' => SORT_ASC ]); | ||
| 44 | + }, | ||
| 45 | + ] | ||
| 46 | + ) | ||
| 47 | + ->where([ 'status' => true ]) | ||
| 48 | + ->orderBy([ 'sort' => SORT_ASC ]) | ||
| 49 | + ->all(); | ||
| 39 | $logo = null; | 50 | $logo = null; |
| 40 | if ($settings->logo) { | 51 | if ($settings->logo) { |
| 41 | $logo_img = ImageManager::findOne($settings->logo); | 52 | $logo_img = ImageManager::findOne($settings->logo); |
| @@ -80,7 +91,7 @@ | @@ -80,7 +91,7 @@ | ||
| 80 | 91 | ||
| 81 | ga('create', '<?=$settings->ga_code?>', 'auto'); | 92 | ga('create', '<?=$settings->ga_code?>', 'auto'); |
| 82 | ga('send', 'pageview'); | 93 | ga('send', 'pageview'); |
| 83 | - | 94 | + |
| 84 | </script> | 95 | </script> |
| 85 | <div id="all"> | 96 | <div id="all"> |
| 86 | <header> | 97 | <header> |
| @@ -260,41 +271,38 @@ _________________________________________________________ --> | @@ -260,41 +271,38 @@ _________________________________________________________ --> | ||
| 260 | 271 | ||
| 261 | <div class="navbar-collapse collapse" id="navigation"> | 272 | <div class="navbar-collapse collapse" id="navigation"> |
| 262 | <?php | 273 | <?php |
| 263 | - $pagesLinks = []; | ||
| 264 | - foreach ($pages as $page) { | ||
| 265 | - $route = [ | ||
| 266 | - 'page/view', | ||
| 267 | - 'id' => $page->id, | ||
| 268 | - ]; | ||
| 269 | - if (!empty($page->lang->alias) && !empty($page->lang->alias->route)) { | ||
| 270 | - $route = Json::decode($page->lang->alias->route); | 274 | + $items = []; |
| 275 | + $items[] = [ | ||
| 276 | + 'label' => \Yii::t('app', 'Home'), | ||
| 277 | + 'url' => [ 'site/index' ], | ||
| 278 | + ]; | ||
| 279 | + foreach ($pageCategories as $category) { | ||
| 280 | + if (empty($category->pages)) { | ||
| 281 | + continue; | ||
| 271 | } | 282 | } |
| 272 | - $pagesLinks[] = [ | 283 | + $pages = []; |
| 284 | + foreach ($category->pages as $page) { | ||
| 285 | + $pages[] = [ | ||
| 273 | 'label' => $page->lang->title, | 286 | 'label' => $page->lang->title, |
| 274 | - 'url' => $route, | 287 | + 'url' => Url::to(['page/view','alias' => $page->lang->alias]), |
| 288 | + ]; | ||
| 289 | + } | ||
| 290 | + $items[] = [ | ||
| 291 | + 'label' => $category->lang->title, | ||
| 292 | + 'items' => $pages, | ||
| 275 | ]; | 293 | ]; |
| 276 | } | 294 | } |
| 295 | + $items[] = [ | ||
| 296 | + 'label' => \Yii::t('app', 'Contatcs'), | ||
| 297 | + 'url' => [ 'site/contact' ], | ||
| 298 | + ]; | ||
| 299 | + $items[] = [ | ||
| 300 | + 'label' => \Yii::t('app', 'About'), | ||
| 301 | + 'url' => [ 'site/about' ], | ||
| 302 | + ]; | ||
| 277 | echo Nav::widget( | 303 | echo Nav::widget( |
| 278 | [ | 304 | [ |
| 279 | - 'items' => [ | ||
| 280 | - [ | ||
| 281 | - 'label' => \Yii::t('app', 'Home'), | ||
| 282 | - 'url' => [ 'site/index' ], | ||
| 283 | - ], | ||
| 284 | - [ | ||
| 285 | - 'label' => \Yii::t('app', 'Pages'), | ||
| 286 | - 'items' => $pagesLinks, | ||
| 287 | - 'visible' => count($pagesLinks), | ||
| 288 | - ], | ||
| 289 | - [ | ||
| 290 | - 'label' => \Yii::t('app', 'Contatcs'), | ||
| 291 | - 'url' => [ 'site/contact' ], | ||
| 292 | - ], | ||
| 293 | - [ | ||
| 294 | - 'label' => \Yii::t('app', 'About'), | ||
| 295 | - 'url' => [ 'site/about' ], | ||
| 296 | - ], | ||
| 297 | - ], | 305 | + 'items' => $items, |
| 298 | 'options' => [ | 306 | 'options' => [ |
| 299 | 'class' => 'nav navbar-nav navbar-right', | 307 | 'class' => 'nav navbar-nav navbar-right', |
| 300 | ], | 308 | ], |