Blame view

frontend/controllers/ServiceController.php 2.07 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){
727d4d0e   Anastasia   - debug
22
                 $others = Service::find()->where(['parent_id' => $model->id])->with('services.language.alias')->all();
2032cb18   Anastasia   - services menu
23
              }elseif ($model->level == 1){
727d4d0e   Anastasia   - debug
24
                  $others = Service::find()->where(['parent_id' => $model->parent_id])->with('services.language.alias')->all();
aedc35b5   Anastasia   - load scg to logo
25
              }else{
4d688be7   Anastasia   - bug fix
26
                  $others = Service::find()->where(['parent_id' => (new Query())->select('parent_id')->from('service')->where(['id' => $model->parent_id])])->with('services.language.alias')->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])
727d4d0e   Anastasia   - debug
39
                              ->with(['language.alias',  'prices' => function (ActiveQuery $query){
43a24059   Anastasia   - servives
40
41
42
                                  $query->where(['status' => true])->orderBy('sort');
                              }, 'comments' => function (ActiveQuery $query){
                                  $query->where(['status' => true]);
b8459872   Anastasia   - forms1
43
                              }, 'questions' => function (ActiveQuery $query){
727d4d0e   Anastasia   - debug
44
                                  $query->where(['status' => true])->with('doctor');
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;
          }
      }