Commit 982be2a82034d4c64335f8065a05a546f61747c5
1 parent
01039920
Генерация мета тегов для отзывов, а так же изменен
Showing
7 changed files
with
170 additions
and
60 deletions
Show diff stats
1 | +<?php | ||
2 | + | ||
3 | +namespace common\components; | ||
4 | + | ||
5 | +use yii\base\Component; | ||
6 | + | ||
7 | + | ||
8 | +/** | ||
9 | + * ===================================================================================================================== | ||
10 | + * Компонент, созданный для того, чтобы обьявлять аналогичные по логике запросы с 1 места | ||
11 | + * ===================================================================================================================== | ||
12 | + */ | ||
13 | +class MailerComponent extends Component | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * Отправляет письмо админу по backend\models\Mail если такая запись есть | ||
18 | + * ***Если запись есть, но творится вакханалия с почтовым адресом, сервер начнёт валить Exception, | ||
19 | + * а мы пишем нашему админу, что у них там почтовые настройки есть, но некорректы | ||
20 | + * | ||
21 | + * @param $mode 1|2|3|4 | ||
22 | + * 1|2|3 ==> используется для site/callback | ||
23 | + * 4 ==> site/contact | ||
24 | + */ | ||
25 | + public static function sendListToAdminAfterSubmit(int $mode) | ||
26 | + { | ||
27 | + $mail = Mail::findOne(1); | ||
28 | + if ($mail != null) { | ||
29 | + $time = Visit::getTimeTitles($mode); | ||
30 | + # если у них всё же почтовые настройки есть, НО письмо не может отправится, | ||
31 | + # прокидываю сообщение об этом нам обратно | ||
32 | + try { | ||
33 | + \Yii::$app->mailer | ||
34 | + ->compose() | ||
35 | + ->setTo($mail->user) | ||
36 | + ->setSubject('Запись на прием: обратная связь') | ||
37 | + ->setTextBody('Пациент с тел: :' . $model->phone . " <br> просил перезвонить ему на протяжении " . $time) | ||
38 | + ->send(); | ||
39 | + } catch (\Exception $e) { | ||
40 | + \Yii::error($mail->user . " - неполучается отправить письмо за указанным адресом", 'mail_error'); | ||
41 | + } | ||
42 | + | ||
43 | + } | ||
44 | + } | ||
45 | + | ||
46 | + | ||
47 | +} | ||
0 | \ No newline at end of file | 48 | \ No newline at end of file |
common/models/Feedback.php
common/models/Visit.php
@@ -43,6 +43,39 @@ | @@ -43,6 +43,39 @@ | ||
43 | { | 43 | { |
44 | return 'visit'; | 44 | return 'visit'; |
45 | } | 45 | } |
46 | + | ||
47 | + | ||
48 | + /** | ||
49 | + * Метод, который нужен для универсальных тайтлов для временных меток | ||
50 | + * | ||
51 | + * @param int $inputMode | ||
52 | + * @return string | ||
53 | + */ | ||
54 | + public static function getTimeTitles(int $inputMode): string | ||
55 | + { | ||
56 | + $resultTimeMessage = ''; | ||
57 | + switch ($inputMode) { | ||
58 | + case 1: | ||
59 | + $resultTimeMessage = "В течение 30 минут"; | ||
60 | + break; | ||
61 | + case 2: | ||
62 | + $resultTimeMessage = 'с 9:00 до 12:00'; | ||
63 | + break; | ||
64 | + case 3: | ||
65 | + $resultTimeMessage = ' с 12:00 до 18:00'; | ||
66 | + break; | ||
67 | + default: | ||
68 | + $resultTimeMessage = ' Время не указано'; | ||
69 | + | ||
70 | + } | ||
71 | + return $resultTimeMessage; | ||
72 | + } | ||
73 | + | ||
74 | + | ||
75 | + | ||
76 | + | ||
77 | + | ||
78 | + | ||
46 | 79 | ||
47 | /** | 80 | /** |
48 | * {@inheritdoc} | 81 | * {@inheritdoc} |
frontend/components/UrlManager.php
@@ -103,8 +103,8 @@ | @@ -103,8 +103,8 @@ | ||
103 | ] | 103 | ] |
104 | ) | 104 | ) |
105 | ->one(); | 105 | ->one(); |
106 | - | ||
107 | - if ($alias !== null) { | 106 | + |
107 | + if ($alias !== null) { | ||
108 | $params = Json::decode($alias->route); | 108 | $params = Json::decode($alias->route); |
109 | 109 | ||
110 | $route = array_shift($params); | 110 | $route = array_shift($params); |
frontend/config/main.php
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | use common\models\SlashRedirect; | 2 | use common\models\SlashRedirect; |
3 | use frontend\components\UrlManager; | 3 | use frontend\components\UrlManager; |
4 | use yii\helpers\Url; | 4 | use yii\helpers\Url; |
5 | + | ||
5 | 6 | ||
6 | $params = array_merge( | 7 | $params = array_merge( |
7 | require( __DIR__ . '/../../common/config/params.php' ), | 8 | require( __DIR__ . '/../../common/config/params.php' ), |
@@ -117,7 +118,7 @@ use yii\helpers\Url; | @@ -117,7 +118,7 @@ use yii\helpers\Url; | ||
117 | 'buttonTemplate' => '<div class="button-wr submit-close-wr-c-a">{button}</div>', | 118 | 'buttonTemplate' => '<div class="button-wr submit-close-wr-c-a">{button}</div>', |
118 | 'buttonOptions' => [], | 119 | 'buttonOptions' => [], |
119 | 'buttonContent' => 'Send', | 120 | 'buttonContent' => 'Send', |
120 | - 'sendEmail' => false, | 121 | + 'sendEmail' => true, |
121 | 'ajax' => true, | 122 | 'ajax' => true, |
122 | 'formId' => 'contact-form', | 123 | 'formId' => 'contact-form', |
123 | 'scenario' => 'callback', | 124 | 'scenario' => 'callback', |
@@ -370,6 +371,31 @@ use yii\helpers\Url; | @@ -370,6 +371,31 @@ use yii\helpers\Url; | ||
370 | 'warning', | 371 | 'warning', |
371 | ], | 372 | ], |
372 | ], | 373 | ], |
374 | + [ | ||
375 | + 'class' => 'yii\log\EmailTarget', | ||
376 | + 'categories' => ['mail_error'], | ||
377 | + 'mailer' => [ | ||
378 | + 'class' => 'yii\swiftmailer\Mailer', | ||
379 | + 'viewPath' => '@frontend/mail', | ||
380 | + 'useFileTransport' => false, | ||
381 | + 'transport' => [ | ||
382 | + 'class' => 'Swift_SmtpTransport', | ||
383 | + 'host' => 'smtp.gmail.com', | ||
384 | + # пока что стоят мои данные, потому что я пробивал свою почту | ||
385 | + # для возможности отправки писем | ||
386 | + 'username' => 'alkhonko@gmail.com', | ||
387 | + 'password' => 'jakirothebest123', | ||
388 | + 'port' => '587', | ||
389 | + 'encryption' => 'tls', | ||
390 | + ], | ||
391 | + ], | ||
392 | + 'logVars' => [], | ||
393 | + 'message' => [ | ||
394 | + 'from' => ['admin@site.com' => 'ABClinic'], | ||
395 | + 'to' => [\Yii::$app->params['adminEmail']], | ||
396 | + 'subject' => 'Ошибка в почтовом адресе. Письма не доставляются после обработки одной из форм', | ||
397 | + ], | ||
398 | + ], | ||
373 | ], | 399 | ], |
374 | ], | 400 | ], |
375 | 'errorHandler' => [ | 401 | 'errorHandler' => [ |
@@ -388,53 +414,53 @@ use yii\helpers\Url; | @@ -388,53 +414,53 @@ use yii\helpers\Url; | ||
388 | SlashRedirect::className(), | 414 | SlashRedirect::className(), |
389 | ], | 415 | ], |
390 | ], | 416 | ], |
391 | - 'assetsAutoCompress' => [ | ||
392 | - 'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent', | ||
393 | - 'enabled' => false, | ||
394 | - | ||
395 | - 'readFileTimeout' => 3, | ||
396 | - //Time in seconds for reading each asset file | ||
397 | - | ||
398 | - 'jsCompress' => true, | ||
399 | - //Enable minification js in html code | ||
400 | - 'jsCompressFlaggedComments' => true, | ||
401 | - //Cut comments during processing js | ||
402 | - | ||
403 | - 'cssCompress' => true, | ||
404 | - //Enable minification css in html code | ||
405 | - | ||
406 | - 'cssFileCompile' => true, | ||
407 | - //Turning association css files | ||
408 | - 'cssFileRemouteCompile' => false, | ||
409 | - //Trying to get css files to which the specified path as the remote file, skchat him to her. | ||
410 | - 'cssFileCompress' => true, | ||
411 | - //Enable compression and processing before being stored in the css file | ||
412 | - 'cssFileBottom' => false, | ||
413 | - //Moving down the page css files | ||
414 | - 'cssFileBottomLoadOnJs' => false, | ||
415 | - //Transfer css file down the page and uploading them using js | ||
416 | - | ||
417 | - 'jsFileCompile' => true, | ||
418 | - //Turning association js files | ||
419 | - 'jsFileRemouteCompile' => false, | ||
420 | - //Trying to get a js files to which the specified path as the remote file, skchat him to her. | ||
421 | - 'jsFileCompress' => true, | ||
422 | - //Enable compression and processing js before saving a file | ||
423 | - 'jsFileCompressFlaggedComments' => true, | ||
424 | - //Cut comments during processing js | ||
425 | - | ||
426 | - 'htmlCompress' => true, | ||
427 | - //Enable compression html | ||
428 | - 'noIncludeJsFilesOnPjax' => true, | ||
429 | - //Do not connect the js files when all pjax requests | ||
430 | - 'htmlCompressOptions' => //options for compressing output result | ||
431 | - [ | ||
432 | - 'extra' => false, | ||
433 | - //use more compact algorithm | ||
434 | - 'no-comments' => true | ||
435 | - //cut all the html comments | ||
436 | - ], | ||
437 | - ], | 417 | + 'assetsAutoCompress' => [ |
418 | + 'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent', | ||
419 | + 'enabled' => false, | ||
420 | + | ||
421 | + 'readFileTimeout' => 3, | ||
422 | + //Time in seconds for reading each asset file | ||
423 | + | ||
424 | + 'jsCompress' => true, | ||
425 | + //Enable minification js in html code | ||
426 | + 'jsCompressFlaggedComments' => true, | ||
427 | + //Cut comments during processing js | ||
428 | + | ||
429 | + 'cssCompress' => true, | ||
430 | + //Enable minification css in html code | ||
431 | + | ||
432 | + 'cssFileCompile' => true, | ||
433 | + //Turning association css files | ||
434 | + 'cssFileRemouteCompile' => false, | ||
435 | + //Trying to get css files to which the specified path as the remote file, skchat him to her. | ||
436 | + 'cssFileCompress' => true, | ||
437 | + //Enable compression and processing before being stored in the css file | ||
438 | + 'cssFileBottom' => false, | ||
439 | + //Moving down the page css files | ||
440 | + 'cssFileBottomLoadOnJs' => false, | ||
441 | + //Transfer css file down the page and uploading them using js | ||
442 | + | ||
443 | + 'jsFileCompile' => true, | ||
444 | + //Turning association js files | ||
445 | + 'jsFileRemouteCompile' => false, | ||
446 | + //Trying to get a js files to which the specified path as the remote file, skchat him to her. | ||
447 | + 'jsFileCompress' => true, | ||
448 | + //Enable compression and processing js before saving a file | ||
449 | + 'jsFileCompressFlaggedComments' => true, | ||
450 | + //Cut comments during processing js | ||
451 | + | ||
452 | + 'htmlCompress' => true, | ||
453 | + //Enable compression html | ||
454 | + 'noIncludeJsFilesOnPjax' => true, | ||
455 | + //Do not connect the js files when all pjax requests | ||
456 | + 'htmlCompressOptions' => //options for compressing output result | ||
457 | + [ | ||
458 | + 'extra' => false, | ||
459 | + //use more compact algorithm | ||
460 | + 'no-comments' => true | ||
461 | + //cut all the html comments | ||
462 | + ], | ||
463 | + ], | ||
438 | ], | 464 | ], |
439 | 465 | ||
440 | 'params' => $params, | 466 | 'params' => $params, |
frontend/controllers/SiteController.php
@@ -22,6 +22,7 @@ | @@ -22,6 +22,7 @@ | ||
22 | use yii\web\BadRequestHttpException; | 22 | use yii\web\BadRequestHttpException; |
23 | use yii\web\Controller; | 23 | use yii\web\Controller; |
24 | use yii\web\Response; | 24 | use yii\web\Response; |
25 | + use common\components\MailerComponent; | ||
25 | 26 | ||
26 | /** | 27 | /** |
27 | * Site controller | 28 | * Site controller |
@@ -176,12 +177,16 @@ | @@ -176,12 +177,16 @@ | ||
176 | $response->headers->set('Content-Type', 'text/plain'); | 177 | $response->headers->set('Content-Type', 'text/plain'); |
177 | return $this->renderFile($meta[ 'uri' ]); | 178 | return $this->renderFile($meta[ 'uri' ]); |
178 | } | 179 | } |
179 | - | 180 | + |
180 | public function actionCallback(){ | 181 | public function actionCallback(){ |
181 | - \Yii::$app->response->format = Response::FORMAT_JSON; | 182 | + |
183 | + \Yii::$app->response->format = Response::FORMAT_JSON; | ||
182 | $model = new Visit(); | 184 | $model = new Visit(); |
183 | if ($model->load(\Yii::$app->request->post()) && $model->save()){ | 185 | if ($model->load(\Yii::$app->request->post()) && $model->save()){ |
184 | - return ['success' => true]; | 186 | + $mode = $model->time; |
187 | + MailerComponent::sendListToAdminAfterSubmit($mode); | ||
188 | + | ||
189 | + return ['success' => true]; | ||
185 | }else{ | 190 | }else{ |
186 | return ['success' => false, 'errors' => $model->errors]; | 191 | return ['success' => false, 'errors' => $model->errors]; |
187 | } | 192 | } |
@@ -196,8 +201,8 @@ | @@ -196,8 +201,8 @@ | ||
196 | */ | 201 | */ |
197 | $mailer = \Yii::$app->get('smtpmailer'); | 202 | $mailer = \Yii::$app->get('smtpmailer'); |
198 | $settings = Settings::getInstance(); | 203 | $settings = Settings::getInstance(); |
199 | - | ||
200 | - if (empty(Yii::$app->request->post())) { | 204 | + |
205 | + if (empty(Yii::$app->request->post())) { | ||
201 | throw new BadRequestHttpException(); | 206 | throw new BadRequestHttpException(); |
202 | } else { | 207 | } else { |
203 | $model = new Feedback(); | 208 | $model = new Feedback(); |
frontend/views/layouts/main.php
@@ -652,7 +652,7 @@ | @@ -652,7 +652,7 @@ | ||
652 | <div class="style title-callback">Записаться на прием</div> | 652 | <div class="style title-callback">Записаться на прием</div> |
653 | <?php | 653 | <?php |
654 | $model = new Visit(['agree' => 1, 'time' => 1]); | 654 | $model = new Visit(['agree' => 1, 'time' => 1]); |
655 | - $form = ActiveForm::begin([ 'action' => 'site/callback', 'id' => 'callback-form' ]); ?> | 655 | + $form = ActiveForm::begin(['action' => '/site/callback', 'id' => 'callback-form']); ?> |
656 | <div class="input-wr phones_mask required"> | 656 | <div class="input-wr phones_mask required"> |
657 | <?= $form->field($model, 'phone') | 657 | <?= $form->field($model, 'phone') |
658 | ->textInput([ 'placeholder' => '+38(0__)___-__-__' ]) | 658 | ->textInput([ 'placeholder' => '+38(0__)___-__-__' ]) |