Commit 7f8928746b5c59458d9a974299dd7037621b8262

Authored by Anastasia
1 parent 41fb7b5b

- blog

frontend/controllers/ServiceController.php
@@ -14,83 +14,153 @@ @@ -14,83 +14,153 @@
14 use yii\web\Controller; 14 use yii\web\Controller;
15 use yii\web\NotFoundHttpException; 15 use yii\web\NotFoundHttpException;
16 use frontend\microdata\MicrodataFabric; 16 use frontend\microdata\MicrodataFabric;
17 - 17 +
18 class ServiceController extends Controller 18 class ServiceController extends Controller
19 { 19 {
20 - public function actionView($id){ 20 + public function actionView($id)
  21 + {
21 $model = $this->findModel($id); 22 $model = $this->findModel($id);
22 - if ($model->parent_id == null){  
23 - $others = Service::find()->where(['parent_id' => $model->id])->with(['services.language.alias', 'language.alias'])->all();  
24 - if (empty($others)){  
25 - $others = Service::find()->where(['parent_id' => null, 'status' => true])->with(['services.language.alias', 'language.alias'])->all();  
26 - }  
27 - }elseif ($model->level == 1){  
28 - $others = Service::find()->where(['parent_id' => $model->parent_id])->with(['services.language.alias', 'language.alias'])->all();  
29 - }else{  
30 - $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(); 23 + if ($model->parent_id == null) {
  24 + $others = Service::find()
  25 + ->where([ 'parent_id' => $model->id ])
  26 + ->with(
  27 + [
  28 + 'services.language.alias',
  29 + 'language.alias',
  30 + ]
  31 + )
  32 + ->all();
  33 + if (empty($others)) {
  34 + $others = Service::find()
  35 + ->where(
  36 + [
  37 + 'parent_id' => null,
  38 + 'status' => true,
  39 + ]
  40 + )
  41 + ->with(
  42 + [
  43 + 'services.language.alias',
  44 + 'language.alias',
  45 + ]
  46 + )
  47 + ->all();
  48 + }
  49 + } elseif ($model->level == 1) {
  50 + $others = Service::find()
  51 + ->where([ 'parent_id' => $model->parent_id ])
  52 + ->with(
  53 + [
  54 + 'services.language.alias',
  55 + 'language.alias',
  56 + ]
  57 + )
  58 + ->all();
  59 + } else {
  60 + $others = Service::find()
  61 + ->where(
  62 + [
  63 + 'parent_id' => ( new Query() )->select('parent_id')
  64 + ->from('service')
  65 + ->where([ 'id' => $model->parent_id ]),
  66 + ]
  67 + )
  68 + ->with(
  69 + [
  70 + 'services.language.alias',
  71 + 'language.alias',
  72 + ]
  73 + )
  74 + ->all();
31 } 75 }
32 -  
33 - 76 +
34 # ัะฟะธัะพะบ ั†ะตะฝ ะดะปั ะผะธะบั€ะพะดะฐะฝะฝั‹ั… 77 # ัะฟะธัะพะบ ั†ะตะฝ ะดะปั ะผะธะบั€ะพะดะฐะฝะฝั‹ั…
35 - $prices=[];  
36 - foreach ($model->prices as $kry=>$price)  
37 - {  
38 - foreach ($price as $key2=>$val2){  
39 - if($key2=='price')$prices[]=$price[$key2]; 78 + $prices = [];
  79 + foreach ($model->prices as $kry => $price) {
  80 + foreach ($price as $key2 => $val2) {
  81 + if ($key2 == 'price') {
  82 + $prices[] = $price[ $key2 ];
  83 + }
40 } 84 }
41 - 85 +
42 } 86 }
43 -  
44 - $layoutMicrodata=(count($model->prices)>1)? 87 +
  88 + $layoutMicrodata = ( count($model->prices) > 1 ) ? [
  89 + '@context' => 'http://schema.org/',
  90 + '@type' => 'Product',
  91 + 'name' => "'{$model->language->attributes['title']}'",
  92 + 'offers' => [
  93 + '@type' => 'AggregateOffer',
  94 + 'lowPrice' => "'" . min($prices) . "'",
  95 + 'highPrice' => "'" . max($prices) . "'",
  96 + 'priceCurrency' => 'UAH',
  97 + ],
  98 + ] : [
  99 + 'type' => 'Product',
  100 + 'name' => "'{$model->language->attributes['title']}'",
  101 + 'offers' => [
  102 + '@type' => 'Offer',
  103 + 'priceCurrency' => 'UAH',
  104 + 'Price' => "'" . max($prices) . "'",
  105 + ],
  106 + ];
  107 +
  108 + $microdata = new MicrodataFabric();
  109 + $pageMicrodata = $microdata::createJsonFromProduct($layoutMicrodata)
  110 + ->toJson();
  111 +
  112 + $model->body = str_replace(
  113 + '[[prices]]',
  114 + $this->renderPartial('_prices', [ 'prices' => $model->prices ]),
  115 + $model->body
  116 + );
  117 + return $this->render(
  118 + 'view',
45 [ 119 [
46 - '@context'=> 'http://schema.org/',  
47 - '@type'=> 'Product',  
48 - 'name'=> "'{$model->language->attributes['title']}'",  
49 - 'offers' =>  
50 - [  
51 - '@type'=> 'AggregateOffer',  
52 - 'lowPrice'=> "'".min($prices)."'",  
53 - 'highPrice'=> "'".max($prices)."'",  
54 - 'priceCurrency'=> 'UAH'  
55 - ] 120 + 'model' => $model,
  121 + 'others' => $others,
  122 + 'microdata' => $pageMicrodata,
56 ] 123 ]
57 - :[  
58 - 'type'=>'Product',  
59 - 'name'=> "'{$model->language->attributes['title']}'",  
60 - 'offers'=> [  
61 - '@type'=> 'Offer',  
62 - 'priceCurrency'=> 'UAH',  
63 - 'Price'=> "'".max($prices)."'",  
64 - ]  
65 - ];  
66 -  
67 -  
68 - $microdata=new MicrodataFabric();  
69 - $pageMicrodata=$microdata::createJsonFromProduct($layoutMicrodata)->toJson();  
70 -  
71 -  
72 -  
73 - $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);  
74 - return $this->render('view', [  
75 - 'model' => $model,  
76 - 'others'=> $others,  
77 - 'microdata'=>$pageMicrodata  
78 - ]); 124 + );
79 } 125 }
80 126
81 - public function findModel($id){ 127 + public function findModel($id)
  128 + {
82 $model = Service::find() 129 $model = Service::find()
83 - ->where(['id' => $id, 'status' => true])  
84 - ->with(['language.alias', 'prices' => function (ActiveQuery $query){  
85 - $query->where(['status' => true])->with('language')->orderBy('sort');  
86 - }, 'comments' => function (ActiveQuery $query){  
87 - $query->where(['status' => true]);  
88 - }, 'questions' => function (ActiveQuery $query){  
89 - $query->where(['status' => true])->with('doctor');  
90 - },'packages' => function (ActiveQuery $query){  
91 - $query->with(['image', 'language.alias'])->where(['status' => true]);  
92 - }])->one();  
93 - if (empty($model)){ 130 + ->where(
  131 + [
  132 + 'id' => $id,
  133 + 'status' => true,
  134 + ]
  135 + )
  136 + ->with(
  137 + [
  138 + 'language.alias',
  139 + 'prices' => function (ActiveQuery $query) {
  140 + $query->where([ 'status' => true ])
  141 + ->with('language')
  142 + ->orderBy('sort');
  143 + },
  144 + 'comments' => function (ActiveQuery $query) {
  145 + $query->where([ 'status' => true ]);
  146 + },
  147 + 'questions' => function (ActiveQuery $query) {
  148 + $query->where([ 'status' => true ])
  149 + ->with('doctor');
  150 + },
  151 + 'packages' => function (ActiveQuery $query) {
  152 + $query->with(
  153 + [
  154 + 'image',
  155 + 'language.alias',
  156 + ]
  157 + )
  158 + ->where([ 'status' => true ]);
  159 + },
  160 + ]
  161 + )
  162 + ->one();
  163 + if (empty($model)) {
94 throw new NotFoundHttpException('Model not found'); 164 throw new NotFoundHttpException('Model not found');
95 } 165 }
96 return $model; 166 return $model;
frontend/views/blog/view.php
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
63 <?=ImageHelper::set(($model->image) ? $model->image->getPath() : null) 63 <?=ImageHelper::set(($model->image) ? $model->image->getPath() : null)
64 ->cropResize(555, 370) 64 ->cropResize(555, 370)
65 ->quality(84) 65 ->quality(84)
66 - ->renderImage(['alt'=>$alt,'title'=>$title])?> 66 + ->renderImage(['alt'=>$alt,'title'=>$title, 'class' => 'blog-view-img'])?>
67 <div class="blog-view-date-all"> 67 <div class="blog-view-date-all">
68 <span class="blog-view-date"><?=date('d.m.Y', $model->created_at)?></span> 68 <span class="blog-view-date"><?=date('d.m.Y', $model->created_at)?></span>
69 <span class="blog-view-comments-ico"><?=count($model->comments)?></span> 69 <span class="blog-view-comments-ico"><?=count($model->comments)?></span>