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){
|
74783874
Anastasia
- debug
|
23
|
$others = Service::find()->where(['parent_id' => $model->id])->with(['services.language.alias', 'language.alias'])->all();
|
a4320bd1
Anastasia
- bug fix
|
24
|
if (empty($others)){
|
74783874
Anastasia
- debug
|
25
|
$others = Service::find()->where(['parent_id' => null, 'status' => true])->with(['services.language.alias', 'language.alias'])->all();
|
a4320bd1
Anastasia
- bug fix
|
26
|
}
|
2032cb18
Anastasia
- services menu
|
27
|
}elseif ($model->level == 1){
|
74783874
Anastasia
- debug
|
28
|
$others = Service::find()->where(['parent_id' => $model->parent_id])->with(['services.language.alias', 'language.alias'])->all();
|
aedc35b5
Anastasia
- load scg to logo
|
29
|
}else{
|
74783874
Anastasia
- debug
|
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();
|
aedc35b5
Anastasia
- load scg to logo
|
31
|
}
|
cfb947e6
alex
Микроданные для у...
|
32
33
|
|
3fafe556
alex
Микроразметка для...
|
34
|
# список цен для микроданных
|
cfb947e6
alex
Микроданные для у...
|
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
|
$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']}'",
|
cfb947e6
alex
Микроданные для у...
|
60
61
62
63
|
'offers'=> [
'@type'=> 'Offer',
'priceCurrency'=> 'UAH',
'Price'=> "'".max($prices)."'",
|
cfb947e6
alex
Микроданные для у...
|
64
65
66
67
68
69
70
71
72
|
]
];
$microdata=new MicrodataFabric();
$pageMicrodata=$microdata::createJsonFromProduct($layoutMicrodata)->toJson();
|
43a24059
Anastasia
- servives
|
73
|
$model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);
|
aedc35b5
Anastasia
- load scg to logo
|
74
75
|
return $this->render('view', [
'model' => $model,
|
cfb947e6
alex
Микроданные для у...
|
76
77
|
'others'=> $others,
'microdata'=>$pageMicrodata
|
aedc35b5
Anastasia
- load scg to logo
|
78
79
80
81
82
83
|
]);
}
public function findModel($id){
$model = Service::find()
->where(['id' => $id, 'status' => true])
|
727d4d0e
Anastasia
- debug
|
84
|
->with(['language.alias', 'prices' => function (ActiveQuery $query){
|
74783874
Anastasia
- debug
|
85
|
$query->where(['status' => true])->with('language')->orderBy('sort');
|
43a24059
Anastasia
- servives
|
86
87
|
}, 'comments' => function (ActiveQuery $query){
$query->where(['status' => true]);
|
b8459872
Anastasia
- forms1
|
88
|
}, 'questions' => function (ActiveQuery $query){
|
727d4d0e
Anastasia
- debug
|
89
|
$query->where(['status' => true])->with('doctor');
|
a4320bd1
Anastasia
- bug fix
|
90
|
},'packages' => function (ActiveQuery $query){
|
74783874
Anastasia
- debug
|
91
|
$query->with(['image', 'language.alias'])->where(['status' => true]);
|
43a24059
Anastasia
- servives
|
92
|
}])->one();
|
aedc35b5
Anastasia
- load scg to logo
|
93
94
95
96
97
98
|
if (empty($model)){
throw new NotFoundHttpException('Model not found');
}
return $model;
}
}
|