Commit c61dbbfba0ecb1ac405119e1041f258dee4808b4
1 parent
2e5525d5
-Categories ready
Showing
2 changed files
with
67 additions
and
50 deletions
Show diff stats
frontend/controllers/PageController.php
| @@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
| 3 | 3 | ||
| 4 | use artbox\core\components\SeoComponent; | 4 | use artbox\core\components\SeoComponent; |
| 5 | use artbox\core\models\Page; | 5 | use artbox\core\models\Page; |
| 6 | + use artbox\core\models\PageCategory; | ||
| 7 | + use yii\db\ActiveQuery; | ||
| 6 | use yii\web\Controller; | 8 | use yii\web\Controller; |
| 7 | use yii\web\NotFoundHttpException; | 9 | use yii\web\NotFoundHttpException; |
| 8 | use Yii; | 10 | use Yii; |
| @@ -33,25 +35,33 @@ | @@ -33,25 +35,33 @@ | ||
| 33 | $lefts = null; | 35 | $lefts = null; |
| 34 | } | 36 | } |
| 35 | 37 | ||
| 36 | - $pages = Page::find() | ||
| 37 | - ->with('lang') | ||
| 38 | - ->where( | ||
| 39 | - [ | ||
| 40 | - 'not', | ||
| 41 | - [ 'id' => $id ], | ||
| 42 | - ] | ||
| 43 | - ) | ||
| 44 | - ->limit(5) | ||
| 45 | - ->all(); | 38 | + $categories = PageCategory::find() |
| 39 | + ->with('lang') | ||
| 40 | + ->with( | ||
| 41 | + [ | ||
| 42 | + 'pages' => function (ActiveQuery $query) use ($id) { | ||
| 43 | + $query->with('lang.alias'); | ||
| 44 | + $query->where( | ||
| 45 | + [ | ||
| 46 | + 'not', | ||
| 47 | + [ | ||
| 48 | + 'id' => $id, | ||
| 49 | + ], | ||
| 50 | + ] | ||
| 51 | + ); | ||
| 52 | + }, | ||
| 53 | + ] | ||
| 54 | + ) | ||
| 55 | + ->all(); | ||
| 46 | 56 | ||
| 47 | return $this->render( | 57 | return $this->render( |
| 48 | 'view', | 58 | 'view', |
| 49 | [ | 59 | [ |
| 50 | - 'model' => $model, | ||
| 51 | - 'pages' => $pages, | ||
| 52 | - 'body' => $body, | ||
| 53 | - 'lefts' => $lefts, | ||
| 54 | - 'images' => $model->getImages(), | 60 | + 'model' => $model, |
| 61 | + 'categories' => $categories, | ||
| 62 | + 'body' => $body, | ||
| 63 | + 'lefts' => $lefts, | ||
| 64 | + 'images' => $model->getImages(), | ||
| 55 | ] | 65 | ] |
| 56 | ); | 66 | ); |
| 57 | } | 67 | } |
frontend/views/page/view.php
| @@ -2,17 +2,18 @@ | @@ -2,17 +2,18 @@ | ||
| 2 | use artbox\core\components\SeoComponent; | 2 | use artbox\core\components\SeoComponent; |
| 3 | use artbox\core\models\Image; | 3 | use artbox\core\models\Image; |
| 4 | use artbox\core\models\Page; | 4 | use artbox\core\models\Page; |
| 5 | + use artbox\core\models\PageCategory; | ||
| 5 | use yii\helpers\Html; | 6 | use yii\helpers\Html; |
| 6 | use yii\web\View; | 7 | use yii\web\View; |
| 7 | 8 | ||
| 8 | /** | 9 | /** |
| 9 | - * @var View $this | ||
| 10 | - * @var Page $model | ||
| 11 | - * @var Page[] $pages | ||
| 12 | - * @var SeoComponent $seo | ||
| 13 | - * @var Image[] $images | ||
| 14 | - * @var string $lefts | ||
| 15 | - * @var string $body | 10 | + * @var View $this |
| 11 | + * @var Page $model | ||
| 12 | + * @var PageCategory[] $categories | ||
| 13 | + * @var SeoComponent $seo | ||
| 14 | + * @var Image[] $images | ||
| 15 | + * @var string $lefts | ||
| 16 | + * @var string $body | ||
| 16 | */ | 17 | */ |
| 17 | $seo = \Yii::$app->get('seo'); | 18 | $seo = \Yii::$app->get('seo'); |
| 18 | $this->params[ 'breadcrumbs' ][] = $seo->title; | 19 | $this->params[ 'breadcrumbs' ][] = $seo->title; |
| @@ -69,30 +70,36 @@ _________________________________________________________ --> | @@ -69,30 +70,36 @@ _________________________________________________________ --> | ||
| 69 | <!-- *** PAGES MENU *** | 70 | <!-- *** PAGES MENU *** |
| 70 | _________________________________________________________ --> | 71 | _________________________________________________________ --> |
| 71 | <div class="panel panel-default sidebar-menu"> | 72 | <div class="panel panel-default sidebar-menu"> |
| 72 | - | ||
| 73 | - <div class="panel-heading"> | ||
| 74 | - <h3 class="panel-title">Услуги</h3> | ||
| 75 | - </div> | ||
| 76 | - | ||
| 77 | - <div class="panel-body"> | ||
| 78 | - <ul class="nav nav-pills nav-stacked"> | ||
| 79 | - <?php | ||
| 80 | - foreach ($pages as $page) { | ||
| 81 | - echo Html::tag( | ||
| 82 | - 'li', | ||
| 83 | - Html::a( | ||
| 84 | - $page->lang->title, | ||
| 85 | - [ | ||
| 86 | - 'page/view', | ||
| 87 | - 'id' => $page->id, | ||
| 88 | - ] | ||
| 89 | - ) | ||
| 90 | - ); | ||
| 91 | - } | ||
| 92 | - ?> | ||
| 93 | - </ul> | ||
| 94 | - | ||
| 95 | - </div> | 73 | + |
| 74 | + <?php foreach ($categories as $category) { | ||
| 75 | + if (!empty($category->pages)) { | ||
| 76 | + ?> | ||
| 77 | + | ||
| 78 | + <div class="panel-heading"> | ||
| 79 | + <h3 class="panel-title">Услуги</h3> | ||
| 80 | + </div> | ||
| 81 | + | ||
| 82 | + <div class="panel-body"> | ||
| 83 | + <ul class="nav nav-pills nav-stacked"> | ||
| 84 | + <?php | ||
| 85 | + foreach ($category->pages as $page) { | ||
| 86 | + echo Html::tag( | ||
| 87 | + 'li', | ||
| 88 | + Html::a( | ||
| 89 | + $page->lang->title, | ||
| 90 | + [ | ||
| 91 | + 'page/view', | ||
| 92 | + 'id' => $page->id, | ||
| 93 | + ] | ||
| 94 | + ) | ||
| 95 | + ); | ||
| 96 | + } | ||
| 97 | + ?> | ||
| 98 | + </ul> | ||
| 99 | + | ||
| 100 | + </div> | ||
| 101 | + <?php } | ||
| 102 | + } ?> | ||
| 96 | </div> | 103 | </div> |
| 97 | 104 | ||
| 98 | <!-- *** PAGES MENU END *** --> | 105 | <!-- *** PAGES MENU END *** --> |
| @@ -121,9 +128,9 @@ _________________________________________________________ --> | @@ -121,9 +128,9 @@ _________________________________________________________ --> | ||
| 121 | 128 | ||
| 122 | 129 | ||
| 123 | <div id="get-it" class="pages"> | 130 | <div id="get-it" class="pages"> |
| 124 | - <div class="container"> | ||
| 125 | - <div class="col-md-12 col-sm-12" style="text-align: center;"> | ||
| 126 | - <a href="#" class="btn bnm btn-template-transparent-primary modal-link" data-form="appointment-modal" data-modalname="Записаться на приём">Записаться на прием</a> | ||
| 127 | - </div> | 131 | + <div class="container"> |
| 132 | + <div class="col-md-12 col-sm-12" style="text-align: center;"> | ||
| 133 | + <a href="#" class="btn bnm btn-template-transparent-primary modal-link" data-form="appointment-modal" data-modalname="Записаться на приём">Записаться на прием</a> | ||
| 128 | </div> | 134 | </div> |
| 135 | + </div> | ||
| 129 | </div> | 136 | </div> |
| 130 | \ No newline at end of file | 137 | \ No newline at end of file |