Blame view

frontend/controllers/ServiceController.php 4.34 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
      use yii\web\Controller;
      use yii\web\NotFoundHttpException;
cfb947e6   alex   Микроданные для у...
16
      use frontend\microdata\MicrodataFabric;
aedc35b5   Anastasia   - load scg to logo
17
18
19
  
      class ServiceController extends Controller
      {
aedc35b5   Anastasia   - load scg to logo
20
21
22
          public function actionView($id){
              $model = $this->findModel($id);
              if ($model->parent_id == null){
727d4d0e   Anastasia   - debug
23
                 $others = Service::find()->where(['parent_id' => $model->id])->with('services.language.alias')->all();
a4320bd1   Anastasia   - bug fix
24
25
26
                 if (empty($others)){
                     $others = Service::find()->where(['parent_id' => null, 'status' => true])->all();
                 }
2032cb18   Anastasia   - services menu
27
              }elseif ($model->level == 1){
727d4d0e   Anastasia   - debug
28
                  $others = Service::find()->where(['parent_id' => $model->parent_id])->with('services.language.alias')->all();
aedc35b5   Anastasia   - load scg to logo
29
              }else{
4d688be7   Anastasia   - bug fix
30
                  $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
31
              }
cfb947e6   alex   Микроданные для у...
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  
  
              $prices=[];
              foreach ($model->prices as $kry=>$price)
              {
                  foreach ($price as $key2=>$val2){
                      if($key2=='price')$prices[]=$price[$key2];
                  }
  
              }
  
              $layoutMicrodata=(count($model->prices)>1)?
                  [
                      '@context'=> 'http://schema.org/',
                      '@type'=> 'Product',
                      'name'=> "'{$model->language->attributes['title']}'",
                      'offers' =>
                          [
                              '@type'=> 'AggregateOffer',
                              'lowPrice'=> "'".min($prices)."'",
                              'highPrice'=> "'".max($prices)."'",
                              'priceCurrency'=> 'UAH'
                          ]
                  ]
                  :[
                      'type'=>'Product',
                      'name'=> "'{$model->language->attributes['title']}'",
                      'image'=> [
                          'https://example.com/photos/1x1/photo.jpg',
                          'https://example.com/photos/4x3/photo.jpg',
                          'https://example.com/photos/16x9/photo.jpg'
                      ],
                      'offers'=> [
                          '@type'=> 'Offer',
                          'priceCurrency'=> 'UAH',
                          'Price'=> "'".max($prices)."'",
                          'priceValidUntil'=> '2020-11-05',
                          'itemCondition'=> 'http://schema.org/UsedCondition',
                          'availability'=> 'http://schema.org/InStock',
                          'seller'=> [
                              'type'=> 'Organization',
                              'name'=>'Executive Objects']
                      ]
                  ];
  
  
              $microdata=new MicrodataFabric();
              $pageMicrodata=$microdata::createJsonFromProduct($layoutMicrodata)->toJson();
  
  
  
43a24059   Anastasia   - servives
83
              $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);
aedc35b5   Anastasia   - load scg to logo
84
85
              return $this->render('view', [
                  'model' => $model,
cfb947e6   alex   Микроданные для у...
86
87
                  'others'=> $others,
                  'microdata'=>$pageMicrodata
aedc35b5   Anastasia   - load scg to logo
88
89
90
91
92
93
              ]);
          }
          
          public function findModel($id){
              $model = Service::find()
                              ->where(['id' => $id, 'status' => true])
727d4d0e   Anastasia   - debug
94
                              ->with(['language.alias',  'prices' => function (ActiveQuery $query){
43a24059   Anastasia   - servives
95
96
97
                                  $query->where(['status' => true])->orderBy('sort');
                              }, 'comments' => function (ActiveQuery $query){
                                  $query->where(['status' => true]);
b8459872   Anastasia   - forms1
98
                              }, 'questions' => function (ActiveQuery $query){
727d4d0e   Anastasia   - debug
99
                                  $query->where(['status' => true])->with('doctor');
a4320bd1   Anastasia   - bug fix
100
101
                              },'packages' => function (ActiveQuery $query){
                                  $query->with(['image', 'language'])->where(['status' => true]);
43a24059   Anastasia   - servives
102
                              }])->one();
aedc35b5   Anastasia   - load scg to logo
103
104
105
106
107
108
              if (empty($model)){
                  throw new NotFoundHttpException('Model not found');
              }
              return $model;
          }
      }