[ 'class' => 'yii\web\ErrorAction', ], ]; } /** * @inheritdoc */ public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'feedback' => [ 'post' ], ], ], ]; } /** * Displays homepage. * * @return mixed */ public function actionIndex() { $slider = Slider::find() ->with("slides.lang.image") ->where([ 'on_home_page' => true ]) ->one(); $objects = Objectkb::find() ->with('lang.alias') ->where( [ 'id' => [ 7, 37, 38, 43, ], ] ) ->orderBy('id') ->all(); return $this->render( 'index', [ 'slider' => $slider, 'objects' => $objects, ] ); } /** * Displays contact page. * * @return mixed */ public function actionContact() { $contact = new Feedback(); return $this->render( 'contact', [ 'contact' => $contact, ] ); } /** * Displays about page. * * @return mixed */ public function actionAbout() { $page = Page::find()->with('lang') ->where(['id' => 3])->one(); if ($page) { return $this->render('about', [ 'page' => $page, ]); } else { throw new NotFoundHttpException(); } } public function actionIndividual() { $idsArray = [ 25, 37, 12, 42, ]; $objects = Objectkb::find() ->with('lang.alias') ->where( [ 'id' => $idsArray, ] ) ->indexBy('id') ->all(); return $this->render( 'individual', [ 'objects' => $objects, 'idsArray' => $idsArray, ] ); } // частное лицо public function actionLegal() { return $this->render('legal'); } // юридическое public function actionMediaAbout() { return $this->render('media-about'); } // СМИ о нас /** * Action to view robots.txt file dinamycli * * @return string */ public function actionRobots() { $response = \Yii::$app->response; /** * @var Settings $settings */ $settings = Settings::find() ->one(); $temp = tmpfile(); fwrite($temp, $settings->robots); $meta = stream_get_meta_data($temp); $response->format = $response::FORMAT_RAW; $response->headers->set('Content-Type', 'text/plain'); return $this->renderFile($meta[ 'uri' ]); } public function actionFeedback() { Yii::$app->response->format = Response::FORMAT_JSON; /** * @var Mailer $mailer */ $mailer = \Yii::$app->get('smtpmailer'); $settings = Settings::getInstance(); if (empty(Yii::$app->request->post())) { throw new BadRequestHttpException(); } else { $post = Yii::$app->request->post('Feedback'); switch ($post[ 'topic' ]) { case Feedback::SCENARIO_FEEDBACK : $model = new Feedback([ 'scenario' => Feedback::SCENARIO_FEEDBACK ]); $view = 'feedback'; $isLoaded = $model->load(Yii::$app->request->post()); break; case Feedback::SCENARIO_CALLBACK : $model = new Feedback([ 'scenario' => Feedback::SCENARIO_CALLBACK ]); $view = 'feedback'; $isLoaded = $model->load(Yii::$app->request->post()); break; case Feedback::SCENARIO_CALCULATOR: $model = new Feedback([ 'scenario' => Feedback::SCENARIO_CALCULATOR ]); $view = 'calculator'; $isLoaded = $model->load(Yii::$app->request->post()); $model->setCalcJsonInfo(); break; default: $model = new Feedback(); $view = 'feedback'; $isLoaded = $model->load(Yii::$app->request->post()); } if ($isLoaded && $model->save()) { $mailer->compose( $view, [ 'model' => $model, ] ) ->setFrom('artbox@domain.com')// ->setTo($settings->email) ->setTo( [ 'tamerlan8.05.92@gmail.com', $settings->email, ] ) ->setSubject(\Yii::t('app', 'Feedback')) ->send(); return [ 'success' => true, 'message' => 'Success message', 'view' => $view, 'model' => $model->attributeValues, 'alert' => $this->renderPartial('success_alert'), ]; } else { Yii::$app->response->setStatusCode(500); return [ 'success' => false, 'error' => $model->errors, ]; } } } }