From 982be2a82034d4c64335f8065a05a546f61747c5 Mon Sep 17 00:00:00 2001 From: dozer111 Date: Thu, 26 Jul 2018 17:24:34 +0300 Subject: [PATCH] Генерация мета тегов для отзывов, а так же изменен --- common/components/MailerComponent.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ common/models/Feedback.php | 7 +++---- common/models/Visit.php | 33 +++++++++++++++++++++++++++++++++ frontend/components/UrlManager.php | 4 ++-- frontend/config/main.php | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------ frontend/controllers/SiteController.php | 15 ++++++++++----- frontend/views/layouts/main.php | 2 +- 7 files changed, 170 insertions(+), 60 deletions(-) create mode 100644 common/components/MailerComponent.php diff --git a/common/components/MailerComponent.php b/common/components/MailerComponent.php new file mode 100644 index 0000000..e4baadd --- /dev/null +++ b/common/components/MailerComponent.php @@ -0,0 +1,47 @@ + используется для site/callback + * 4 ==> site/contact + */ + public static function sendListToAdminAfterSubmit(int $mode) + { + $mail = Mail::findOne(1); + if ($mail != null) { + $time = Visit::getTimeTitles($mode); + # если у них всё же почтовые настройки есть, НО письмо не может отправится, + # прокидываю сообщение об этом нам обратно + try { + \Yii::$app->mailer + ->compose() + ->setTo($mail->user) + ->setSubject('Запись на прием: обратная связь') + ->setTextBody('Пациент с тел: :' . $model->phone . "
просил перезвонить ему на протяжении " . $time) + ->send(); + } catch (\Exception $e) { + \Yii::error($mail->user . " - неполучается отправить письмо за указанным адресом", 'mail_error'); + } + + } + } + + +} \ No newline at end of file diff --git a/common/models/Feedback.php b/common/models/Feedback.php index fc8cd46..fe1977d 100644 --- a/common/models/Feedback.php +++ b/common/models/Feedback.php @@ -25,10 +25,9 @@ const SCENARIO_FEEDBACK = 'feedback'; const SCENARIO_CALLBACK = 'callback'; - - - - public $returnUrl; + + + public $returnUrl; diff --git a/common/models/Visit.php b/common/models/Visit.php index 00b3ad6..e9bffcc 100644 --- a/common/models/Visit.php +++ b/common/models/Visit.php @@ -43,6 +43,39 @@ { return 'visit'; } + + + /** + * Метод, который нужен для универсальных тайтлов для временных меток + * + * @param int $inputMode + * @return string + */ + public static function getTimeTitles(int $inputMode): string + { + $resultTimeMessage = ''; + switch ($inputMode) { + case 1: + $resultTimeMessage = "В течение 30 минут"; + break; + case 2: + $resultTimeMessage = 'с 9:00 до 12:00'; + break; + case 3: + $resultTimeMessage = ' с 12:00 до 18:00'; + break; + default: + $resultTimeMessage = ' Время не указано'; + + } + return $resultTimeMessage; + } + + + + + + /** * {@inheritdoc} diff --git a/frontend/components/UrlManager.php b/frontend/components/UrlManager.php index d8ed517..e38e87f 100644 --- a/frontend/components/UrlManager.php +++ b/frontend/components/UrlManager.php @@ -103,8 +103,8 @@ ] ) ->one(); - - if ($alias !== null) { + + if ($alias !== null) { $params = Json::decode($alias->route); $route = array_shift($params); diff --git a/frontend/config/main.php b/frontend/config/main.php index 19d9016..b70b98d 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -2,6 +2,7 @@ use common\models\SlashRedirect; use frontend\components\UrlManager; use yii\helpers\Url; + $params = array_merge( require( __DIR__ . '/../../common/config/params.php' ), @@ -117,7 +118,7 @@ use yii\helpers\Url; 'buttonTemplate' => '
{button}
', 'buttonOptions' => [], 'buttonContent' => 'Send', - 'sendEmail' => false, + 'sendEmail' => true, 'ajax' => true, 'formId' => 'contact-form', 'scenario' => 'callback', @@ -370,6 +371,31 @@ use yii\helpers\Url; 'warning', ], ], + [ + 'class' => 'yii\log\EmailTarget', + 'categories' => ['mail_error'], + 'mailer' => [ + 'class' => 'yii\swiftmailer\Mailer', + 'viewPath' => '@frontend/mail', + 'useFileTransport' => false, + 'transport' => [ + 'class' => 'Swift_SmtpTransport', + 'host' => 'smtp.gmail.com', + # пока что стоят мои данные, потому что я пробивал свою почту + # для возможности отправки писем + 'username' => 'alkhonko@gmail.com', + 'password' => 'jakirothebest123', + 'port' => '587', + 'encryption' => 'tls', + ], + ], + 'logVars' => [], + 'message' => [ + 'from' => ['admin@site.com' => 'ABClinic'], + 'to' => [\Yii::$app->params['adminEmail']], + 'subject' => 'Ошибка в почтовом адресе. Письма не доставляются после обработки одной из форм', + ], + ], ], ], 'errorHandler' => [ @@ -388,53 +414,53 @@ use yii\helpers\Url; SlashRedirect::className(), ], ], - 'assetsAutoCompress' => [ - 'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent', - 'enabled' => false, - - 'readFileTimeout' => 3, - //Time in seconds for reading each asset file - - 'jsCompress' => true, - //Enable minification js in html code - 'jsCompressFlaggedComments' => true, - //Cut comments during processing js - - 'cssCompress' => true, - //Enable minification css in html code - - 'cssFileCompile' => true, - //Turning association css files - 'cssFileRemouteCompile' => false, - //Trying to get css files to which the specified path as the remote file, skchat him to her. - 'cssFileCompress' => true, - //Enable compression and processing before being stored in the css file - 'cssFileBottom' => false, - //Moving down the page css files - 'cssFileBottomLoadOnJs' => false, - //Transfer css file down the page and uploading them using js - - 'jsFileCompile' => true, - //Turning association js files - 'jsFileRemouteCompile' => false, - //Trying to get a js files to which the specified path as the remote file, skchat him to her. - 'jsFileCompress' => true, - //Enable compression and processing js before saving a file - 'jsFileCompressFlaggedComments' => true, - //Cut comments during processing js - - 'htmlCompress' => true, - //Enable compression html - 'noIncludeJsFilesOnPjax' => true, - //Do not connect the js files when all pjax requests - 'htmlCompressOptions' => //options for compressing output result - [ - 'extra' => false, - //use more compact algorithm - 'no-comments' => true - //cut all the html comments - ], - ], + 'assetsAutoCompress' => [ + 'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent', + 'enabled' => false, + + 'readFileTimeout' => 3, + //Time in seconds for reading each asset file + + 'jsCompress' => true, + //Enable minification js in html code + 'jsCompressFlaggedComments' => true, + //Cut comments during processing js + + 'cssCompress' => true, + //Enable minification css in html code + + 'cssFileCompile' => true, + //Turning association css files + 'cssFileRemouteCompile' => false, + //Trying to get css files to which the specified path as the remote file, skchat him to her. + 'cssFileCompress' => true, + //Enable compression and processing before being stored in the css file + 'cssFileBottom' => false, + //Moving down the page css files + 'cssFileBottomLoadOnJs' => false, + //Transfer css file down the page and uploading them using js + + 'jsFileCompile' => true, + //Turning association js files + 'jsFileRemouteCompile' => false, + //Trying to get a js files to which the specified path as the remote file, skchat him to her. + 'jsFileCompress' => true, + //Enable compression and processing js before saving a file + 'jsFileCompressFlaggedComments' => true, + //Cut comments during processing js + + 'htmlCompress' => true, + //Enable compression html + 'noIncludeJsFilesOnPjax' => true, + //Do not connect the js files when all pjax requests + 'htmlCompressOptions' => //options for compressing output result + [ + 'extra' => false, + //use more compact algorithm + 'no-comments' => true + //cut all the html comments + ], + ], ], 'params' => $params, diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index ea5f95f..259f541 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -22,6 +22,7 @@ use yii\web\BadRequestHttpException; use yii\web\Controller; use yii\web\Response; + use common\components\MailerComponent; /** * Site controller @@ -176,12 +177,16 @@ $response->headers->set('Content-Type', 'text/plain'); return $this->renderFile($meta[ 'uri' ]); } - + public function actionCallback(){ - \Yii::$app->response->format = Response::FORMAT_JSON; + + \Yii::$app->response->format = Response::FORMAT_JSON; $model = new Visit(); if ($model->load(\Yii::$app->request->post()) && $model->save()){ - return ['success' => true]; + $mode = $model->time; + MailerComponent::sendListToAdminAfterSubmit($mode); + + return ['success' => true]; }else{ return ['success' => false, 'errors' => $model->errors]; } @@ -196,8 +201,8 @@ */ $mailer = \Yii::$app->get('smtpmailer'); $settings = Settings::getInstance(); - - if (empty(Yii::$app->request->post())) { + + if (empty(Yii::$app->request->post())) { throw new BadRequestHttpException(); } else { $model = new Feedback(); diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 4baba84..cb6d8e2 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -652,7 +652,7 @@
Записаться на прием
1, 'time' => 1]); - $form = ActiveForm::begin([ 'action' => 'site/callback', 'id' => 'callback-form' ]); ?> + $form = ActiveForm::begin(['action' => '/site/callback', 'id' => 'callback-form']); ?>
field($model, 'phone') ->textInput([ 'placeholder' => '+38(0__)___-__-__' ]) -- libgit2 0.21.4