Blame view

frontend/controllers/ServiceController.php 2.02 KB
aedc35b5   Anastasia   - load scg to logo
1
2
3
4
5
6
7
8
9
10
11
  <?php
      /**
       * Created by PhpStorm.
       * User: stes
       * Date: 29.05.18
       * Time: 9:51
       */
      
      namespace frontend\controllers;
      
      use common\models\Service;
43a24059   Anastasia   - servives
12
      use yii\db\ActiveQuery;
2032cb18   Anastasia   - services menu
13
      use yii\db\Query;
aedc35b5   Anastasia   - load scg to logo
14
15
16
17
18
      use yii\web\Controller;
      use yii\web\NotFoundHttpException;
  
      class ServiceController extends Controller
      {
aedc35b5   Anastasia   - load scg to logo
19
20
21
          public function actionView($id){
              $model = $this->findModel($id);
              if ($model->parent_id == null){
2032cb18   Anastasia   - services menu
22
23
24
                 $others = Service::find()->where(['parent_id' => $model->id])->with('services')->all();
              }elseif ($model->level == 1){
                  $others = Service::find()->where(['parent_id' => $model->parent_id])->with('services')->all();
aedc35b5   Anastasia   - load scg to logo
25
              }else{
2032cb18   Anastasia   - services menu
26
                  $others = Service::find()->where(['parent_id' => (new Query())->select('parent_id')->from('service')->where(['id' => $model->parent_id])])->with('services')->all();
aedc35b5   Anastasia   - load scg to logo
27
28
              }
              
43a24059   Anastasia   - servives
29
              $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);
aedc35b5   Anastasia   - load scg to logo
30
31
32
33
34
35
36
37
38
              return $this->render('view', [
                  'model' => $model,
                  'others'=> $others
              ]);
          }
          
          public function findModel($id){
              $model = Service::find()
                              ->where(['id' => $id, 'status' => true])
43a24059   Anastasia   - servives
39
40
41
42
                              ->with(['language.alias', 'image',  'prices' => function (ActiveQuery $query){
                                  $query->where(['status' => true])->orderBy('sort');
                              }, 'comments' => function (ActiveQuery $query){
                                  $query->where(['status' => true]);
b8459872   Anastasia   - forms1
43
44
                              }, 'questions' => function (ActiveQuery $query){
                                  $query->where(['status' => true]);
43a24059   Anastasia   - servives
45
                              }])->one();
aedc35b5   Anastasia   - load scg to logo
46
47
48
49
50
51
              if (empty($model)){
                  throw new NotFoundHttpException('Model not found');
              }
              return $model;
          }
      }