Blame view

frontend/controllers/PageController.php 2.45 KB
f3b6b9b1   Alexey Boroda   -Seo component in...
1
2
  <?php
      namespace frontend\controllers;
63296d61   Alexey Boroda   -Added gallery
3
      
8596ef4b   Alexey Boroda   -Seo component ready
4
      use artbox\core\components\SeoComponent;
f3b6b9b1   Alexey Boroda   -Seo component in...
5
      use artbox\core\models\Page;
f3b6b9b1   Alexey Boroda   -Seo component in...
6
7
      use yii\web\Controller;
      use yii\web\NotFoundHttpException;
8596ef4b   Alexey Boroda   -Seo component ready
8
      use Yii;
63296d61   Alexey Boroda   -Added gallery
9
      
f3b6b9b1   Alexey Boroda   -Seo component in...
10
11
12
13
14
15
16
17
18
19
      /**
       * Class PageController
       *
       * @package frontend\controllers
       */
      class PageController extends Controller
      {
          public function actionView($id)
          {
              $model = $this->findModel($id);
63296d61   Alexey Boroda   -Added gallery
20
              
8596ef4b   Alexey Boroda   -Seo component ready
21
22
23
24
25
              /**
               * @var SeoComponent $seo
               */
              $seo = Yii::$app->get('seo');
              $seo->setModel($model->lang);
63296d61   Alexey Boroda   -Added gallery
26
27
28
29
30
31
32
33
34
35
              
              if (strpos($model->lang->body, '[[gallery]]')) {
                  $splited = explode('[[gallery]]', $model->lang->body);
                  $body = array_shift($splited);
                  $lefts = implode('', $splited);
              } else {
                  $body = $model->lang->body;
                  $lefts = null;
              }
              
4acbd19d   Alexey Boroda   -Bar tabs
36
37
              $pages = Page::find()
                           ->with('lang')
6e516b40   Yarik   Layout complete
38
39
40
41
42
43
44
                           ->where(
                               [
                                   'not',
                                   [ 'id' => $id ],
                               ]
                           )
                           ->limit(5)
4acbd19d   Alexey Boroda   -Bar tabs
45
46
                           ->all();
              
f3b6b9b1   Alexey Boroda   -Seo component in...
47
48
49
              return $this->render(
                  'view',
                  [
63296d61   Alexey Boroda   -Added gallery
50
51
52
53
                      'model'  => $model,
                      'pages'  => $pages,
                      'body'   => $body,
                      'lefts'  => $lefts,
eacd7080   Alexey Boroda   -Gallery ready
54
                      'images' => $model->getImages(),
f3b6b9b1   Alexey Boroda   -Seo component in...
55
56
57
                  ]
              );
          }
63296d61   Alexey Boroda   -Added gallery
58
          
f3b6b9b1   Alexey Boroda   -Seo component in...
59
60
          protected function findModel($id)
          {
8596ef4b   Alexey Boroda   -Seo component ready
61
              /**
63296d61   Alexey Boroda   -Added gallery
62
63
               * @var Page         $model
               * @var SeoComponent $seo
8596ef4b   Alexey Boroda   -Seo component ready
64
               */
63296d61   Alexey Boroda   -Added gallery
65
              $seo = \Yii::$app->get('seo');
8596ef4b   Alexey Boroda   -Seo component ready
66
67
68
69
70
71
72
73
              $model = Page::find()
                           ->where(
                               [
                                   'id' => $id,
                               ]
                           )
                           ->with('lang')
                           ->one();
63296d61   Alexey Boroda   -Added gallery
74
75
76
              
              if (!empty($model)) {
                  if ($model->lang->alias_id !== $seo->aliasId) {
8596ef4b   Alexey Boroda   -Seo component ready
77
78
                      throw new NotFoundHttpException('Wrong language');
                  }
f3b6b9b1   Alexey Boroda   -Seo component in...
79
80
81
82
83
84
                  return $model;
              } else {
                  throw new NotFoundHttpException('Model not found');
              }
          }
      }