Commit 74783874d7cf4ea251fda15ece5a9cb5b19f50cf

Authored by Anastasia
1 parent db8fc84f

- debug

common/config/main.php
@@ -27,7 +27,7 @@ @@ -27,7 +27,7 @@
27 ], 27 ],
28 'components' => [ 28 'components' => [
29 'cache' => [ 29 'cache' => [
30 - 'class' => 'yii\caching\DummyCache', 30 + 'class' => 'yii\caching\FileCache',
31 ], 31 ],
32 'i18n' => [ 32 'i18n' => [
33 'translations' => [ 33 'translations' => [
frontend/controllers/ServiceController.php
@@ -19,14 +19,14 @@ @@ -19,14 +19,14 @@
19 public function actionView($id){ 19 public function actionView($id){
20 $model = $this->findModel($id); 20 $model = $this->findModel($id);
21 if ($model->parent_id == null){ 21 if ($model->parent_id == null){
22 - $others = Service::find()->where(['parent_id' => $model->id])->with('services.language.alias')->all(); 22 + $others = Service::find()->where(['parent_id' => $model->id])->with(['services.language.alias', 'language.alias'])->all();
23 if (empty($others)){ 23 if (empty($others)){
24 - $others = Service::find()->where(['parent_id' => null, 'status' => true])->all(); 24 + $others = Service::find()->where(['parent_id' => null, 'status' => true])->with(['services.language.alias', 'language.alias'])->all();
25 } 25 }
26 }elseif ($model->level == 1){ 26 }elseif ($model->level == 1){
27 - $others = Service::find()->where(['parent_id' => $model->parent_id])->with('services.language.alias')->all(); 27 + $others = Service::find()->where(['parent_id' => $model->parent_id])->with(['services.language.alias', 'language.alias'])->all();
28 }else{ 28 }else{
29 - $others = Service::find()->where(['parent_id' => (new Query())->select('parent_id')->from('service')->where(['id' => $model->parent_id])])->with('services.language.alias')->all(); 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();
30 } 30 }
31 31
32 $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body); 32 $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);
@@ -40,13 +40,13 @@ @@ -40,13 +40,13 @@
40 $model = Service::find() 40 $model = Service::find()
41 ->where(['id' => $id, 'status' => true]) 41 ->where(['id' => $id, 'status' => true])
42 ->with(['language.alias', 'prices' => function (ActiveQuery $query){ 42 ->with(['language.alias', 'prices' => function (ActiveQuery $query){
43 - $query->where(['status' => true])->orderBy('sort'); 43 + $query->where(['status' => true])->with('language')->orderBy('sort');
44 }, 'comments' => function (ActiveQuery $query){ 44 }, 'comments' => function (ActiveQuery $query){
45 $query->where(['status' => true]); 45 $query->where(['status' => true]);
46 }, 'questions' => function (ActiveQuery $query){ 46 }, 'questions' => function (ActiveQuery $query){
47 $query->where(['status' => true])->with('doctor'); 47 $query->where(['status' => true])->with('doctor');
48 },'packages' => function (ActiveQuery $query){ 48 },'packages' => function (ActiveQuery $query){
49 - $query->with(['image', 'language'])->where(['status' => true]); 49 + $query->with(['image', 'language.alias'])->where(['status' => true]);
50 }])->one(); 50 }])->one();
51 if (empty($model)){ 51 if (empty($model)){
52 throw new NotFoundHttpException('Model not found'); 52 throw new NotFoundHttpException('Model not found');
frontend/controllers/SiteController.php
1 <?php 1 <?php
  2 +
2 namespace frontend\controllers; 3 namespace frontend\controllers;
3 4
4 use artbox\core\models\Alias; 5 use artbox\core\models\Alias;
@@ -62,34 +63,70 @@ @@ -62,34 +63,70 @@
62 */ 63 */
63 public function actionIndex() 64 public function actionIndex()
64 { 65 {
65 - $slides = Slide::find()->with('language')->where(['status' => true])->orderBy('sort')->with('language.image')->all();  
66 - $services = Service::find()->where(['is not' ,'image_id', NULL])->andWhere( 66 + $slides = Slide::find()
  67 + ->with('language')
  68 + ->where([ 'status' => true ])
  69 + ->orderBy('sort')
  70 + ->with('language.image')
  71 + ->all();
  72 + $services = Service::find()
  73 + ->where(
  74 + [
  75 + 'is not',
  76 + 'image_id',
  77 + null,
  78 + ]
  79 + )
  80 + ->andWhere(
  81 + [
  82 + 'status' => true,
  83 + 'level' => 0,
  84 + ]
  85 + )
  86 + ->with(
  87 + [
  88 + 'image',
  89 + 'language.alias',
  90 + 'services' => function (ActiveQuery $query) {
  91 + $query->where([ 'status' => true ])
  92 + ->with([ 'language.alias' ]);
  93 + },
  94 + ]
  95 + )
  96 + ->orderBy([ new Expression('sort ASC NULLS LAST') ])
  97 + ->all();
  98 + $comments = Comment::find()
  99 + ->where(
  100 + [
  101 + 'status' => true,
  102 + 'on_main' => true,
  103 + ]
  104 + )
  105 + ->limit(6)
  106 + ->all();
  107 +
  108 + $package = Package::find()
  109 + ->with(
  110 + [
  111 + 'language.alias',
  112 + 'image',
  113 + ]
  114 + )
  115 + ->where([ 'status' => true ])
  116 + ->orderBy('sort')
  117 + ->limit(3)
  118 + ->all();
  119 + $settings = Settings::getInstance();
  120 + return $this->render(
  121 + 'index',
67 [ 122 [
68 - 'status' => true,  
69 - 'level' => 0, 123 + 'slides' => $slides,
  124 + 'services' => $services,
  125 + 'comments' => $comments,
  126 + 'settings' => $settings,
  127 + 'package' => $package,
70 ] 128 ]
71 - )  
72 - ->with(  
73 - [  
74 - 'image',  
75 - 'language.alias',  
76 - 'services' => function (ActiveQuery $query) {  
77 - $query->where(['status' => true])->with(['language.alias']);  
78 - },  
79 - ]  
80 - )->orderBy([ new Expression('sort ASC NULLS LAST') ])  
81 - ->all();  
82 - $comments = Comment::find()->where(['status' => true, 'on_main' => true])->limit(6)->all();  
83 -  
84 - $package = Package::find()->with(['language.alias'])->where(['status' => true])->orderBy('sort')->limit(3)->all();  
85 - $settings = Settings::getInstance();  
86 - return $this->render('index', [  
87 - 'slides' => $slides,  
88 - 'services' => $services,  
89 - 'comments' => $comments,  
90 - 'settings' => $settings,  
91 - 'package' => $package  
92 - ]); 129 + );
93 } 130 }
94 131
95 /** 132 /**
@@ -104,8 +141,8 @@ @@ -104,8 +141,8 @@
104 return $this->render( 141 return $this->render(
105 'contact', 142 'contact',
106 [ 143 [
107 - 'contact' => $contact,  
108 - 'settings' => $settings 144 + 'contact' => $contact,
  145 + 'settings' => $settings,
109 ] 146 ]
110 ); 147 );
111 } 148 }
@@ -186,133 +223,187 @@ @@ -186,133 +223,187 @@
186 } 223 }
187 } 224 }
188 } 225 }
189 - public function actionPrices(){  
190 - $services = Service::find()->innerJoinWith(['prices' => function (ActiveQuery $query){  
191 - $query->where(['price.status' => true]);  
192 - }])->all(); 226 + public function actionPrices()
  227 + {
  228 + $services = Service::find()
  229 + ->innerJoinWith(
  230 + [
  231 + 'prices' => function (ActiveQuery $query) {
  232 + $query->where([ 'price.status' => true ])
  233 + ->with('language');
  234 + },
  235 + ]
  236 + )
  237 + ->with('language.alias')
  238 + ->all();
193 239
194 - return $this->render('prices', [  
195 - 'services' => $services,  
196 - ]); 240 + return $this->render(
  241 + 'prices',
  242 + [
  243 + 'services' => $services,
  244 + ]
  245 + );
197 } 246 }
198 247
199 -  
200 - public function actionPage1(){ 248 + public function actionPage1()
  249 + {
201 return $this->render('page1'); 250 return $this->render('page1');
202 } 251 }
203 -  
204 - public function actionPage2(){ 252 +
  253 + public function actionPage2()
  254 + {
205 return $this->render('page2'); 255 return $this->render('page2');
206 } 256 }
207 -  
208 - public function actionPage22(){ 257 +
  258 + public function actionPage22()
  259 + {
209 return $this->render('page2-2'); 260 return $this->render('page2-2');
210 } 261 }
211 -  
212 - public function actionPage23(){ 262 +
  263 + public function actionPage23()
  264 + {
213 return $this->render('page2-3'); 265 return $this->render('page2-3');
214 } 266 }
215 -  
216 - public function actionPage3(){ 267 +
  268 + public function actionPage3()
  269 + {
217 return $this->render('page3'); 270 return $this->render('page3');
218 } 271 }
219 -  
220 - public function actionPage4(){ 272 +
  273 + public function actionPage4()
  274 + {
221 return $this->render('page4'); 275 return $this->render('page4');
222 } 276 }
223 -  
224 - public function actionPage5(){ 277 +
  278 + public function actionPage5()
  279 + {
225 return $this->render('page5'); 280 return $this->render('page5');
226 } 281 }
227 -  
228 - public function actionPage6(){ 282 +
  283 + public function actionPage6()
  284 + {
229 return $this->render('page6'); 285 return $this->render('page6');
230 } 286 }
231 -  
232 287
233 -  
234 # Вопрос/ответ 288 # Вопрос/ответ
235 - public function actionQuestions($service_id = null){ 289 + public function actionQuestions($service_id = null)
  290 + {
236 Language::getCurrent(); 291 Language::getCurrent();
237 292
238 - if (\Yii::$app->request->isAjax){ 293 + if (\Yii::$app->request->isAjax) {
239 Yii::$app->response->format = Response::FORMAT_JSON; 294 Yii::$app->response->format = Response::FORMAT_JSON;
240 $model = new Question(); 295 $model = new Question();
241 $model->scenario = Question::SCENARIO_QUESTION; 296 $model->scenario = Question::SCENARIO_QUESTION;
242 - if ($model->load(\Yii::$app->request->post()) and $model->save()){ 297 + if ($model->load(\Yii::$app->request->post()) and $model->save()) {
243 return [ 298 return [
244 - 'status' => true,  
245 - 'message' => 'Спасибо за Ваш вопрос' 299 + 'status' => true,
  300 + 'message' => 'Спасибо за Ваш вопрос',
246 ]; 301 ];
247 - }else{ 302 + } else {
248 return [ 303 return [
249 - 'status' => false,  
250 - 'message' => 'Ошибка' 304 + 'status' => false,
  305 + 'message' => 'Ошибка',
251 ]; 306 ];
252 } 307 }
253 } 308 }
254 - $dataProvider = new ActiveDataProvider([  
255 - 'query' => Question::find()->where(['status' => true])->andFilterWhere(['service_id' => $service_id])->with(['doctor.language']),  
256 - 'pagination' => [  
257 - 'pageSize' => 10,  
258 - ],  
259 - ]);  
260 - $services = Service::find()->where(['status' => true])->andWhere(['parent_id' => null])->all(); 309 + $dataProvider = new ActiveDataProvider(
  310 + [
  311 + 'query' => Question::find()
  312 + ->where([ 'status' => true ])
  313 + ->andFilterWhere([ 'service_id' => $service_id ])
  314 + ->with([ 'doctor.language' ]),
  315 + 'pagination' => [
  316 + 'pageSize' => 10,
  317 + ],
  318 + ]
  319 + );
  320 + $services = Service::find()
  321 + ->where([ 'status' => true ])
  322 + ->andWhere([ 'parent_id' => null ])
  323 + ->with('language')
  324 + ->all();
261 $route = []; 325 $route = [];
262 - foreach ($services as $service){  
263 - $route[] = Json::encode(['site/questions', 'service_id' => $service->id]); 326 + foreach ($services as $service) {
  327 + $route[] = Json::encode(
  328 + [
  329 + 'site/questions',
  330 + 'service_id' => $service->id,
  331 + ]
  332 + );
264 } 333 }
265 $route [] = '{"0":"site/questions"}'; 334 $route [] = '{"0":"site/questions"}';
266 - $alias = Alias::find()->where(['route' => $route])->andWhere(['language_id' => Language::getCurrent()->id])->indexBy('route')->asArray()->all();  
267 - return $this->render('questions', [  
268 - 'dataProvider' => $dataProvider,  
269 - 'services' => $services,  
270 - 'service_id' => $service_id,  
271 - 'alias' => $alias  
272 - ]); 335 + $alias = Alias::find()
  336 + ->where([ 'route' => $route ])
  337 + ->andWhere([ 'language_id' => Language::getCurrent()->id ])
  338 + ->indexBy('route')
  339 + ->asArray()
  340 + ->all();
  341 + return $this->render(
  342 + 'questions',
  343 + [
  344 + 'dataProvider' => $dataProvider,
  345 + 'services' => $services,
  346 + 'service_id' => $service_id,
  347 + 'alias' => $alias,
  348 + ]
  349 + );
273 } 350 }
274 -  
275 - public function actionComments($service_id = null){  
276 -  
277 - if (\Yii::$app->request->isAjax){ 351 +
  352 + public function actionComments($service_id = null)
  353 + {
  354 +
  355 + if (\Yii::$app->request->isAjax) {
278 Yii::$app->response->format = Response::FORMAT_JSON; 356 Yii::$app->response->format = Response::FORMAT_JSON;
279 $model = new Comment(); 357 $model = new Comment();
280 #if ($model->load(\Yii::$app->request->post()) and $model->save()){ 358 #if ($model->load(\Yii::$app->request->post()) and $model->save()){
281 - if ($model->load(\Yii::$app->request->post())){  
282 - if(!$model->entity_id)$model->entity_id=0;  
283 - $model->entity=Service::className(); 359 + if ($model->load(\Yii::$app->request->post())) {
  360 + if (!$model->entity_id) {
  361 + $model->entity_id = 0;
  362 + }
  363 + $model->entity = Service::className();
284 $model->save(); 364 $model->save();
285 return [ 365 return [
286 - 'status' => true,  
287 - 'message' => 'Спасибо за Ваш отзыв. После проверки модератором он появиться на сайте' 366 + 'status' => true,
  367 + 'message' => 'Спасибо за Ваш отзыв. После проверки модератором он появиться на сайте',
288 ]; 368 ];
289 - }else{ 369 + } else {
290 return [ 370 return [
291 - 'status' => false,  
292 - 'message' => 'Ошибка' 371 + 'status' => false,
  372 + 'message' => 'Ошибка',
293 ]; 373 ];
294 } 374 }
295 } 375 }
296 -  
297 - 376 +
298 # подкоректировал логику для сохранрения в БД/выдачи вопросов с категории "Общие вопросы" 377 # подкоректировал логику для сохранрения в БД/выдачи вопросов с категории "Общие вопросы"
299 # закрепил за ними entity_id=0 378 # закрепил за ними entity_id=0
300 - if($service_id==null)$service_id=0;  
301 - $dataProvider = new ActiveDataProvider([  
302 - 'query' => Comment::find()  
303 - ->where(['status' => true])  
304 - ->andWhere(['entity' => Service::className()])  
305 - ->andFilterWhere(['entity_id' => $service_id]),//'SELECT * FROM \"comment\" WHERE (\"status\"=TRUE) AND (\"entity\"=\'common\\models\\Service\')'  
306 - 'pagination' => [  
307 - 'pageSize' => 10,  
308 - ],  
309 - ]);  
310 - $services = Service::find()->where(['status' => true])->andWhere(['parent_id' => null])->all();  
311 -  
312 - return $this->render('comments', [  
313 - 'dataProvider' => $dataProvider,  
314 - 'services' => $services,  
315 - 'service_id' => $service_id  
316 - ]); 379 + if ($service_id == null) {
  380 + $service_id = 0;
  381 + }
  382 + $dataProvider = new ActiveDataProvider(
  383 + [
  384 + 'query' => Comment::find()
  385 + ->where([ 'status' => true ])
  386 + ->andWhere([ 'entity' => Service::className() ])
  387 + ->andFilterWhere([ 'entity_id' => $service_id ]),
  388 + //'SELECT * FROM \"comment\" WHERE (\"status\"=TRUE) AND (\"entity\"=\'common\\models\\Service\')'
  389 + 'pagination' => [
  390 + 'pageSize' => 10,
  391 + ],
  392 + ]
  393 + );
  394 + $services = Service::find()
  395 + ->where([ 'status' => true ])
  396 + ->andWhere([ 'parent_id' => null ])
  397 + ->with('language')
  398 + ->all();
  399 +
  400 + return $this->render(
  401 + 'comments',
  402 + [
  403 + 'dataProvider' => $dataProvider,
  404 + 'services' => $services,
  405 + 'service_id' => $service_id,
  406 + ]
  407 + );
317 } 408 }
318 } 409 }
frontend/views/layouts/main.php
@@ -50,7 +50,14 @@ @@ -50,7 +50,14 @@
50 [ 50 [
51 'language.alias', 51 'language.alias',
52 'services' => function (ActiveQuery $query) { 52 'services' => function (ActiveQuery $query) {
53 - $query->where(['status' => true])->with(['language.alias']); 53 + $query->where(['status' => true])->with(
  54 + [
  55 + 'language.alias',
  56 + 'services' => function (ActiveQuery $query) {
  57 + $query->where(['status' => true])->with(['language.alias']);
  58 + },
  59 + ]
  60 + );
54 }, 61 },
55 ] 62 ]
56 )->orderBy('sort') 63 )->orderBy('sort')
frontend/views/site/index.php
@@ -161,7 +161,7 @@ JS; @@ -161,7 +161,7 @@ JS;
161 <div class="row"> 161 <div class="row">
162 <?php foreach ($package as $item){?> 162 <?php foreach ($package as $item){?>
163 <div class="col-xs-12 col-sm-4 package-offers-wr"> 163 <div class="col-xs-12 col-sm-4 package-offers-wr">
164 - <a href="<?=Url::to(['alias' => $item->alias])?>"> 164 + <a href="<?=Url::to(['alias' => $item->language->alias])?>">
165 <div class="img"><?=ImageHelper::set(($item->image) ? $item->image->getPath() : null) 165 <div class="img"><?=ImageHelper::set(($item->image) ? $item->image->getPath() : null)
166 ->cropResize(388, 240) 166 ->cropResize(388, 240)
167 ->quality(84) 167 ->quality(84)