diff --git a/common/config/main.php b/common/config/main.php index fe97efe..d80ab1f 100644 --- a/common/config/main.php +++ b/common/config/main.php @@ -27,7 +27,7 @@ ], 'components' => [ 'cache' => [ - 'class' => 'yii\caching\DummyCache', + 'class' => 'yii\caching\FileCache', ], 'i18n' => [ 'translations' => [ diff --git a/frontend/controllers/ServiceController.php b/frontend/controllers/ServiceController.php index d1bcee5..b62f805 100644 --- a/frontend/controllers/ServiceController.php +++ b/frontend/controllers/ServiceController.php @@ -19,14 +19,14 @@ public function actionView($id){ $model = $this->findModel($id); if ($model->parent_id == null){ - $others = Service::find()->where(['parent_id' => $model->id])->with('services.language.alias')->all(); + $others = Service::find()->where(['parent_id' => $model->id])->with(['services.language.alias', 'language.alias'])->all(); if (empty($others)){ - $others = Service::find()->where(['parent_id' => null, 'status' => true])->all(); + $others = Service::find()->where(['parent_id' => null, 'status' => true])->with(['services.language.alias', 'language.alias'])->all(); } }elseif ($model->level == 1){ - $others = Service::find()->where(['parent_id' => $model->parent_id])->with('services.language.alias')->all(); + $others = Service::find()->where(['parent_id' => $model->parent_id])->with(['services.language.alias', 'language.alias'])->all(); }else{ - $others = Service::find()->where(['parent_id' => (new Query())->select('parent_id')->from('service')->where(['id' => $model->parent_id])])->with('services.language.alias')->all(); + $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(); } $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body); @@ -40,13 +40,13 @@ $model = Service::find() ->where(['id' => $id, 'status' => true]) ->with(['language.alias', 'prices' => function (ActiveQuery $query){ - $query->where(['status' => true])->orderBy('sort'); + $query->where(['status' => true])->with('language')->orderBy('sort'); }, 'comments' => function (ActiveQuery $query){ $query->where(['status' => true]); }, 'questions' => function (ActiveQuery $query){ $query->where(['status' => true])->with('doctor'); },'packages' => function (ActiveQuery $query){ - $query->with(['image', 'language'])->where(['status' => true]); + $query->with(['image', 'language.alias'])->where(['status' => true]); }])->one(); if (empty($model)){ throw new NotFoundHttpException('Model not found'); diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 5c706f5..028044e 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -1,4 +1,5 @@ with('language')->where(['status' => true])->orderBy('sort')->with('language.image')->all(); - $services = Service::find()->where(['is not' ,'image_id', NULL])->andWhere( + $slides = Slide::find() + ->with('language') + ->where([ 'status' => true ]) + ->orderBy('sort') + ->with('language.image') + ->all(); + $services = Service::find() + ->where( + [ + 'is not', + 'image_id', + null, + ] + ) + ->andWhere( + [ + 'status' => true, + 'level' => 0, + ] + ) + ->with( + [ + 'image', + 'language.alias', + 'services' => function (ActiveQuery $query) { + $query->where([ 'status' => true ]) + ->with([ 'language.alias' ]); + }, + ] + ) + ->orderBy([ new Expression('sort ASC NULLS LAST') ]) + ->all(); + $comments = Comment::find() + ->where( + [ + 'status' => true, + 'on_main' => true, + ] + ) + ->limit(6) + ->all(); + + $package = Package::find() + ->with( + [ + 'language.alias', + 'image', + ] + ) + ->where([ 'status' => true ]) + ->orderBy('sort') + ->limit(3) + ->all(); + $settings = Settings::getInstance(); + return $this->render( + 'index', [ - 'status' => true, - 'level' => 0, + 'slides' => $slides, + 'services' => $services, + 'comments' => $comments, + 'settings' => $settings, + 'package' => $package, ] - ) - ->with( - [ - 'image', - 'language.alias', - 'services' => function (ActiveQuery $query) { - $query->where(['status' => true])->with(['language.alias']); - }, - ] - )->orderBy([ new Expression('sort ASC NULLS LAST') ]) - ->all(); - $comments = Comment::find()->where(['status' => true, 'on_main' => true])->limit(6)->all(); - - $package = Package::find()->with(['language.alias'])->where(['status' => true])->orderBy('sort')->limit(3)->all(); - $settings = Settings::getInstance(); - return $this->render('index', [ - 'slides' => $slides, - 'services' => $services, - 'comments' => $comments, - 'settings' => $settings, - 'package' => $package - ]); + ); } /** @@ -104,8 +141,8 @@ return $this->render( 'contact', [ - 'contact' => $contact, - 'settings' => $settings + 'contact' => $contact, + 'settings' => $settings, ] ); } @@ -186,133 +223,187 @@ } } } - public function actionPrices(){ - $services = Service::find()->innerJoinWith(['prices' => function (ActiveQuery $query){ - $query->where(['price.status' => true]); - }])->all(); + public function actionPrices() + { + $services = Service::find() + ->innerJoinWith( + [ + 'prices' => function (ActiveQuery $query) { + $query->where([ 'price.status' => true ]) + ->with('language'); + }, + ] + ) + ->with('language.alias') + ->all(); - return $this->render('prices', [ - 'services' => $services, - ]); + return $this->render( + 'prices', + [ + 'services' => $services, + ] + ); } - - public function actionPage1(){ + public function actionPage1() + { return $this->render('page1'); } - - public function actionPage2(){ + + public function actionPage2() + { return $this->render('page2'); } - - public function actionPage22(){ + + public function actionPage22() + { return $this->render('page2-2'); } - - public function actionPage23(){ + + public function actionPage23() + { return $this->render('page2-3'); } - - public function actionPage3(){ + + public function actionPage3() + { return $this->render('page3'); } - - public function actionPage4(){ + + public function actionPage4() + { return $this->render('page4'); } - - public function actionPage5(){ + + public function actionPage5() + { return $this->render('page5'); } - - public function actionPage6(){ + + public function actionPage6() + { return $this->render('page6'); } - - # Вопрос/ответ - public function actionQuestions($service_id = null){ + public function actionQuestions($service_id = null) + { Language::getCurrent(); - if (\Yii::$app->request->isAjax){ + if (\Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; $model = new Question(); $model->scenario = Question::SCENARIO_QUESTION; - if ($model->load(\Yii::$app->request->post()) and $model->save()){ + if ($model->load(\Yii::$app->request->post()) and $model->save()) { return [ - 'status' => true, - 'message' => 'Спасибо за Ваш вопрос' + 'status' => true, + 'message' => 'Спасибо за Ваш вопрос', ]; - }else{ + } else { return [ - 'status' => false, - 'message' => 'Ошибка' + 'status' => false, + 'message' => 'Ошибка', ]; } } - $dataProvider = new ActiveDataProvider([ - 'query' => Question::find()->where(['status' => true])->andFilterWhere(['service_id' => $service_id])->with(['doctor.language']), - 'pagination' => [ - 'pageSize' => 10, - ], - ]); - $services = Service::find()->where(['status' => true])->andWhere(['parent_id' => null])->all(); + $dataProvider = new ActiveDataProvider( + [ + 'query' => Question::find() + ->where([ 'status' => true ]) + ->andFilterWhere([ 'service_id' => $service_id ]) + ->with([ 'doctor.language' ]), + 'pagination' => [ + 'pageSize' => 10, + ], + ] + ); + $services = Service::find() + ->where([ 'status' => true ]) + ->andWhere([ 'parent_id' => null ]) + ->with('language') + ->all(); $route = []; - foreach ($services as $service){ - $route[] = Json::encode(['site/questions', 'service_id' => $service->id]); + foreach ($services as $service) { + $route[] = Json::encode( + [ + 'site/questions', + 'service_id' => $service->id, + ] + ); } $route [] = '{"0":"site/questions"}'; - $alias = Alias::find()->where(['route' => $route])->andWhere(['language_id' => Language::getCurrent()->id])->indexBy('route')->asArray()->all(); - return $this->render('questions', [ - 'dataProvider' => $dataProvider, - 'services' => $services, - 'service_id' => $service_id, - 'alias' => $alias - ]); + $alias = Alias::find() + ->where([ 'route' => $route ]) + ->andWhere([ 'language_id' => Language::getCurrent()->id ]) + ->indexBy('route') + ->asArray() + ->all(); + return $this->render( + 'questions', + [ + 'dataProvider' => $dataProvider, + 'services' => $services, + 'service_id' => $service_id, + 'alias' => $alias, + ] + ); } - - public function actionComments($service_id = null){ - - if (\Yii::$app->request->isAjax){ + + public function actionComments($service_id = null) + { + + if (\Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; $model = new Comment(); #if ($model->load(\Yii::$app->request->post()) and $model->save()){ - if ($model->load(\Yii::$app->request->post())){ - if(!$model->entity_id)$model->entity_id=0; - $model->entity=Service::className(); + if ($model->load(\Yii::$app->request->post())) { + if (!$model->entity_id) { + $model->entity_id = 0; + } + $model->entity = Service::className(); $model->save(); return [ - 'status' => true, - 'message' => 'Спасибо за Ваш отзыв. После проверки модератором он появиться на сайте' + 'status' => true, + 'message' => 'Спасибо за Ваш отзыв. После проверки модератором он появиться на сайте', ]; - }else{ + } else { return [ - 'status' => false, - 'message' => 'Ошибка' + 'status' => false, + 'message' => 'Ошибка', ]; } } - - + # подкоректировал логику для сохранрения в БД/выдачи вопросов с категории "Общие вопросы" # закрепил за ними entity_id=0 - if($service_id==null)$service_id=0; - $dataProvider = new ActiveDataProvider([ - 'query' => Comment::find() - ->where(['status' => true]) - ->andWhere(['entity' => Service::className()]) - ->andFilterWhere(['entity_id' => $service_id]),//'SELECT * FROM \"comment\" WHERE (\"status\"=TRUE) AND (\"entity\"=\'common\\models\\Service\')' - 'pagination' => [ - 'pageSize' => 10, - ], - ]); - $services = Service::find()->where(['status' => true])->andWhere(['parent_id' => null])->all(); - - return $this->render('comments', [ - 'dataProvider' => $dataProvider, - 'services' => $services, - 'service_id' => $service_id - ]); + if ($service_id == null) { + $service_id = 0; + } + $dataProvider = new ActiveDataProvider( + [ + 'query' => Comment::find() + ->where([ 'status' => true ]) + ->andWhere([ 'entity' => Service::className() ]) + ->andFilterWhere([ 'entity_id' => $service_id ]), + //'SELECT * FROM \"comment\" WHERE (\"status\"=TRUE) AND (\"entity\"=\'common\\models\\Service\')' + 'pagination' => [ + 'pageSize' => 10, + ], + ] + ); + $services = Service::find() + ->where([ 'status' => true ]) + ->andWhere([ 'parent_id' => null ]) + ->with('language') + ->all(); + + return $this->render( + 'comments', + [ + 'dataProvider' => $dataProvider, + 'services' => $services, + 'service_id' => $service_id, + ] + ); } } diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 12fa839..7a8f10a 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -50,7 +50,14 @@ [ 'language.alias', 'services' => function (ActiveQuery $query) { - $query->where(['status' => true])->with(['language.alias']); + $query->where(['status' => true])->with( + [ + 'language.alias', + 'services' => function (ActiveQuery $query) { + $query->where(['status' => true])->with(['language.alias']); + }, + ] + ); }, ] )->orderBy('sort') diff --git a/frontend/views/site/index.php b/frontend/views/site/index.php index 6c1b834..4686bf2 100755 --- a/frontend/views/site/index.php +++ b/frontend/views/site/index.php @@ -161,7 +161,7 @@ JS;
- +
image) ? $item->image->getPath() : null) ->cropResize(388, 240) ->quality(84) -- libgit2 0.21.4