Blame view

frontend/controllers/ServiceController.php 2.52 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){
74783874   Anastasia   - debug
22
                 $others = Service::find()->where(['parent_id' => $model->id])->with(['services.language.alias', 'language.alias'])->all();
a4320bd1   Anastasia   - bug fix
23
                 if (empty($others)){
74783874   Anastasia   - debug
24
                     $others = Service::find()->where(['parent_id' => null, 'status' => true])->with(['services.language.alias', 'language.alias'])->all();
a4320bd1   Anastasia   - bug fix
25
                 }
2032cb18   Anastasia   - services menu
26
              }elseif ($model->level == 1){
74783874   Anastasia   - debug
27
                  $others = Service::find()->where(['parent_id' => $model->parent_id])->with(['services.language.alias', 'language.alias'])->all();
aedc35b5   Anastasia   - load scg to logo
28
              }else{
74783874   Anastasia   - debug
29
                  $others = Service::find()->where(['parent_id' => (new Query())->select('parent_id')->from('service')->where(['id' => $model->parent_id])])->with(['services.language.alias', 'language.alias'])->all();
aedc35b5   Anastasia   - load scg to logo
30
31
              }
              
43a24059   Anastasia   - servives
32
              $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);
aedc35b5   Anastasia   - load scg to logo
33
34
35
36
37
38
39
40
41
              return $this->render('view', [
                  'model' => $model,
                  'others'=> $others
              ]);
          }
          
          public function findModel($id){
              $model = Service::find()
                              ->where(['id' => $id, 'status' => true])
727d4d0e   Anastasia   - debug
42
                              ->with(['language.alias',  'prices' => function (ActiveQuery $query){
74783874   Anastasia   - debug
43
                                  $query->where(['status' => true])->with('language')->orderBy('sort');
43a24059   Anastasia   - servives
44
45
                              }, 'comments' => function (ActiveQuery $query){
                                  $query->where(['status' => true]);
b8459872   Anastasia   - forms1
46
                              }, 'questions' => function (ActiveQuery $query){
727d4d0e   Anastasia   - debug
47
                                  $query->where(['status' => true])->with('doctor');
a4320bd1   Anastasia   - bug fix
48
                              },'packages' => function (ActiveQuery $query){
74783874   Anastasia   - debug
49
                                  $query->with(['image', 'language.alias'])->where(['status' => true]);
43a24059   Anastasia   - servives
50
                              }])->one();
aedc35b5   Anastasia   - load scg to logo
51
52
53
54
55
56
              if (empty($model)){
                  throw new NotFoundHttpException('Model not found');
              }
              return $model;
          }
      }