Commit 47df160f8f9e09982e8f766732de0dc64cb300e8

Authored by Alexey Boroda
2 parents 771cb13e f972afc1

Merge branch 'master' of gitlab.artweb.com.ua:steska/clinica

common/components/MailerComponent.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\components;
  4 +
  5 +use yii\base\Component;
  6 +use common\models\Visit;
  7 +use backend\models\Mail;
  8 +use common\models\Settings;
  9 +
  10 +
  11 +
  12 +
  13 +/**
  14 + * =====================================================================================================================
  15 + * Компонент, созданный для того, чтобы обьявлять аналогичные по логике письма с 1 места
  16 + * =====================================================================================================================
  17 + */
  18 +class MailerComponent extends Component
  19 +{
  20 +
  21 + /**
  22 + * Отправляет письмо админу по backend\models\Mail если такая запись есть
  23 + * ***Если запись есть, но творится вакханалия с почтовым адресом, сервер начнёт валить Exception,
  24 + * а мы пишем нашему админу, что у них там почтовые настройки есть, но некорректы
  25 + *
  26 + * @param $mode 1|2|3|4
  27 + * 1|2|3 ==> используется для site/callback
  28 + * 4 ==> site/contact
  29 + */
  30 + public static function sendListToAdminAfterSubmit(int $mode, array $params = [])
  31 + {
  32 + $mail = Mail::findOne(1);
  33 + if ($mail != null) {
  34 + $time = Visit::getTimeTitles($mode);
  35 + $settings = Settings::getInstance();
  36 + # если у них всё же почтовые настройки есть, НО письмо не может отправится,
  37 + # прокидываю сообщение об этом нам обратно
  38 + try {
  39 + if (!empty($mail->user) && !empty($settings->email)) {
  40 + $mail1 = \Yii::$app->mailer
  41 + ->compose()
  42 + ->setFrom($mail->user)
  43 + ->setTo($settings->email)
  44 + ->setSubject('Запись на прием: обратная связь')
  45 + ->setTextBody('Контакт пациента: :' . $params['user_data'] . " просил перезвонить ему " . $time);
  46 + if ($mail1->send() == false) {
  47 + \Yii::info(\Yii::$app->params['artwebAdminEmail'] . " - неполучается отправить письмо за указанным адресом", 'mail_error');
  48 + }
  49 + }
  50 +
  51 +
  52 +
  53 +
  54 + } catch (\Exception $e) {
  55 + \Yii::error(\Yii::$app->params['artwebAdminEmail'] . " - неполучается отправить письмо за указанным адресом", 'mail_error');
  56 + }
  57 +
  58 + }
  59 + }
  60 +
  61 +
  62 +}
0 63 \ No newline at end of file
... ...
common/config/params.php
... ... @@ -3,4 +3,5 @@ return [
3 3 'adminEmail' => 'admin@example.com',
4 4 'supportEmail' => 'support@example.com',
5 5 'user.passwordResetTokenExpire' => 3600,
  6 + 'artwebAdminEmail' => 'alkhonko@gmail.com',
6 7 ];
... ...
common/models/Feedback.php
... ... @@ -25,10 +25,9 @@
25 25  
26 26 const SCENARIO_FEEDBACK = 'feedback';
27 27 const SCENARIO_CALLBACK = 'callback';
28   -
29   -
30   -
31   - public $returnUrl;
  28 +
  29 +
  30 + public $returnUrl;
32 31  
33 32  
34 33  
... ...
common/models/Settings.php
... ... @@ -186,7 +186,8 @@
186 186 public static function getInstance()
187 187 {
188 188 if (empty( self::$instance )) {
189   - self::$instance = self::find()->with('languages')->where([ 'id' => 1 ])->one();
  189 +
  190 + self::$instance = self::find()->with('languages')->where([ 'id' => 1 ])->one();
190 191 return self::$instance;
191 192 }
192 193  
... ...
common/models/Visit.php
... ... @@ -43,6 +43,39 @@
43 43 {
44 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 81 * {@inheritdoc}
... ...
frontend/components/UrlManager.php
... ... @@ -103,8 +103,8 @@
103 103 ]
104 104 )
105 105 ->one();
106   -
107   - if ($alias !== null) {
  106 +
  107 + if ($alias !== null) {
108 108 $params = Json::decode($alias->route);
109 109  
110 110 $route = array_shift($params);
... ...
frontend/config/main.php
1 1 <?php
2 2 use common\models\SlashRedirect;
3 3 use frontend\components\UrlManager;
4   -use yii\helpers\Url;
  4 +use common\models\Settings;
  5 +
  6 +
5 7  
6 8 $params = array_merge(
7 9 require( __DIR__ . '/../../common/config/params.php' ),
... ... @@ -9,7 +11,7 @@ use yii\helpers\Url;
9 11 require( __DIR__ . '/params.php' ),
10 12 require( __DIR__ . '/params-local.php' )
11 13 );
12   -
  14 +
13 15 return [
14 16 'id' => 'app-frontend',
15 17 'homeUrl' => '/',
... ... @@ -79,8 +81,9 @@ use yii\helpers\Url;
79 81  
80 82 ],
81 83 'contact' => [
82   - 'class' => 'artbox\core\forms\Module',
  84 + 'class' => 'frontend\modules\forms\Module',
83 85 'activeRecord' => "artbox\core\models\Feedback",
  86 + 'alternateMailLogic' => true,
84 87 'attributes' => [
85 88 'name',
86 89 'phone',
... ... @@ -117,7 +120,7 @@ use yii\helpers\Url;
117 120 'buttonTemplate' => '<div class="button-wr submit-close-wr-c-a">{button}</div>',
118 121 'buttonOptions' => [],
119 122 'buttonContent' => 'Send',
120   - 'sendEmail' => false,
  123 + 'sendEmail' => true,
121 124 'ajax' => true,
122 125 'formId' => 'contact-form',
123 126 'scenario' => 'callback',
... ... @@ -348,6 +351,22 @@ use yii\helpers\Url;
348 351 'csrfParam' => '_csrf-frontend',
349 352 'baseUrl' => '',
350 353 ],
  354 +// 'mailer' => [
  355 +// 'class' => 'yii\swiftmailer\Mailer',
  356 +// 'viewPath' => '@frontend/mail',
  357 +// 'useFileTransport' => false,
  358 +//
  359 +// 'transport' => [
  360 +// 'class' => 'Swift_SmtpTransport',
  361 +// 'host' => 'smtp.gmail.com',
  362 +// # пока что стоят мои данные, потому что я пробивал свою почту
  363 +// # для возможности отправки писем
  364 +// 'username' => 'alkhonko@gmail.com',
  365 +// 'password' => 'jakirothebest123',
  366 +// 'port' => '587',
  367 +// 'encryption' => 'tls',
  368 +// ],
  369 +// ],
351 370 'user' => [
352 371 'identityClass' => 'common\models\User',
353 372 'enableAutoLogin' => true,
... ... @@ -370,6 +389,35 @@ use yii\helpers\Url;
370 389 'warning',
371 390 ],
372 391 ],
  392 + [
  393 + 'class' => 'yii\log\EmailTarget',
  394 + 'categories' => ['mail_error'],
  395 + 'levels' => [
  396 + 'error',
  397 + 'warning',
  398 + 'info'
  399 + ],
  400 + 'mailer' => [
  401 + 'class' => 'yii\swiftmailer\Mailer',
  402 + 'viewPath' => '@frontend/mail',
  403 + 'useFileTransport' => false,
  404 +
  405 + 'transport' => [
  406 + 'class' => 'Swift_SmtpTransport',
  407 + 'host' => 'smtp.gmail.com',
  408 + 'username' => 'artboxcore@gmail.com',
  409 + 'password' => 'upfly2000',
  410 + 'port' => '587',
  411 + 'encryption' => 'tls',
  412 + ],
  413 + ],
  414 + 'logVars' => [],
  415 + 'message' => [
  416 + 'from' => ['artboxcore@gmail.com' => 'ABClinic'],
  417 + 'to' => [\Yii::$app->params['artboxAdminEmail']],
  418 + 'subject' => 'Ошибка в почтовом адресе ABClinic. Письма не доставляются после обработки одной из форм',
  419 + ],
  420 + ],
373 421 ],
374 422 ],
375 423 'errorHandler' => [
... ... @@ -388,53 +436,53 @@ use yii\helpers\Url;
388 436 SlashRedirect::className(),
389 437 ],
390 438 ],
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   - ],
  439 + 'assetsAutoCompress' => [
  440 + 'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
  441 + 'enabled' => false,
  442 +
  443 + 'readFileTimeout' => 3,
  444 + //Time in seconds for reading each asset file
  445 +
  446 + 'jsCompress' => true,
  447 + //Enable minification js in html code
  448 + 'jsCompressFlaggedComments' => true,
  449 + //Cut comments during processing js
  450 +
  451 + 'cssCompress' => true,
  452 + //Enable minification css in html code
  453 +
  454 + 'cssFileCompile' => true,
  455 + //Turning association css files
  456 + 'cssFileRemouteCompile' => false,
  457 + //Trying to get css files to which the specified path as the remote file, skchat him to her.
  458 + 'cssFileCompress' => true,
  459 + //Enable compression and processing before being stored in the css file
  460 + 'cssFileBottom' => false,
  461 + //Moving down the page css files
  462 + 'cssFileBottomLoadOnJs' => false,
  463 + //Transfer css file down the page and uploading them using js
  464 +
  465 + 'jsFileCompile' => true,
  466 + //Turning association js files
  467 + 'jsFileRemouteCompile' => false,
  468 + //Trying to get a js files to which the specified path as the remote file, skchat him to her.
  469 + 'jsFileCompress' => true,
  470 + //Enable compression and processing js before saving a file
  471 + 'jsFileCompressFlaggedComments' => true,
  472 + //Cut comments during processing js
  473 +
  474 + 'htmlCompress' => true,
  475 + //Enable compression html
  476 + 'noIncludeJsFilesOnPjax' => true,
  477 + //Do not connect the js files when all pjax requests
  478 + 'htmlCompressOptions' => //options for compressing output result
  479 + [
  480 + 'extra' => false,
  481 + //use more compact algorithm
  482 + 'no-comments' => true
  483 + //cut all the html comments
  484 + ],
  485 + ],
438 486 ],
439 487  
440 488 'params' => $params,
... ...
frontend/controllers/SiteController.php
... ... @@ -22,6 +22,7 @@
22 22 use yii\web\BadRequestHttpException;
23 23 use yii\web\Controller;
24 24 use yii\web\Response;
  25 + use common\components\MailerComponent;
25 26  
26 27 /**
27 28 * Site controller
... ... @@ -62,7 +63,7 @@
62 63 */
63 64 public function actionIndex()
64 65 {
65   - $slides = Slide::find()
  66 + $slides = Slide::find()
66 67 ->with('language')
67 68 ->where([ 'status' => true ])
68 69 ->orderBy('sort')
... ... @@ -176,12 +177,15 @@
176 177 $response->headers->set('Content-Type', 'text/plain');
177 178 return $this->renderFile($meta[ 'uri' ]);
178 179 }
179   -
  180 +
180 181 public function actionCallback(){
181   - \Yii::$app->response->format = Response::FORMAT_JSON;
  182 +
  183 + \Yii::$app->response->format = Response::FORMAT_JSON;
182 184 $model = new Visit();
183 185 if ($model->load(\Yii::$app->request->post()) && $model->save()){
184   - return ['success' => true];
  186 + $mode = $model->time;
  187 + MailerComponent::sendListToAdminAfterSubmit($mode, ['user_data' => $model->phone]);
  188 + return ['success' => true];
185 189 }else{
186 190 return ['success' => false, 'errors' => $model->errors];
187 191 }
... ... @@ -196,8 +200,8 @@
196 200 */
197 201 $mailer = \Yii::$app->get('smtpmailer');
198 202 $settings = Settings::getInstance();
199   -
200   - if (empty(Yii::$app->request->post())) {
  203 +
  204 + if (empty(Yii::$app->request->post())) {
201 205 throw new BadRequestHttpException();
202 206 } else {
203 207 $model = new Feedback();
... ...
frontend/modules/forms/DynamicModel.php 0 → 100755
  1 +<?php
  2 +
  3 +
  4 +namespace frontend\modules\forms;
  5 +/**
  6 + * Class DynamicModel
  7 + *
  8 + * @package artbox\core\forms
  9 + */
  10 +class DynamicModel extends \yii\base\DynamicModel
  11 +{
  12 + /**
  13 + * @var mixed
  14 + */
  15 + protected $_labels;
  16 +
  17 + /**
  18 + * @param $labels
  19 + */
  20 + public function setAttributeLabels($labels)
  21 + {
  22 + $this->_labels = $labels;
  23 + }
  24 +
  25 + /**
  26 + * @param string $name
  27 + *
  28 + * @return string
  29 + */
  30 + public function getAttributeLabel($name)
  31 + {
  32 + return $this->_labels[$name] ?? $name;
  33 + }
  34 +}
0 35 \ No newline at end of file
... ...
frontend/modules/forms/Module.php 0 → 100755
  1 +<?php
  2 +
  3 +namespace frontend\modules\forms;
  4 +
  5 +use yii\base\InvalidConfigException;
  6 +use yii\helpers\Html;
  7 +use yii\web\View;
  8 +use yii\widgets\ActiveForm;
  9 +
  10 +/**
  11 + * Module for generation forms adn saving data from frontend
  12 + *
  13 + * @package artbox\core\forms
  14 + */
  15 +class Module extends \yii\base\Module
  16 +{
  17 + /**
  18 + * ActiveRecord for insert to db
  19 + *
  20 + * @var null
  21 + */
  22 + public $templateForm = '{form}';
  23 +
  24 + public $activeRecord = null;
  25 +
  26 + /**
  27 + * attributes which render in form
  28 + *
  29 + * @var array
  30 + */
  31 + public $attributes = [];
  32 +
  33 + /**
  34 + * validation rules for DynamicModel
  35 + *
  36 + * @var array
  37 + */
  38 + public $rules = [];
  39 +
  40 + /**
  41 + * scenario for ActiveRecord
  42 + *
  43 + * @var string
  44 + */
  45 + public $scenario = 'default';
  46 +
  47 + /**
  48 + * Input types for attributes. textinput default
  49 + *
  50 + * @var array
  51 + */
  52 + public $inputOptions = [];
  53 +
  54 + /**
  55 + * Labels by form (if ActiveRecord is null)
  56 + *
  57 + * @var array
  58 + */
  59 + public $labels = [];
  60 +
  61 + /**
  62 + * Send or not email
  63 + *
  64 + * @var bool
  65 + */
  66 + public $sendEmail = true;
  67 +
  68 + /**
  69 + * Email address
  70 + *
  71 + * @var string
  72 + */
  73 + public $email = 'admin@example.com';
  74 +
  75 + /**
  76 + * Email template
  77 + *
  78 + * @var string
  79 + */
  80 + public $emailFile = 'mail.php';
  81 +
  82 + /**
  83 + * Email subject
  84 + *
  85 + * @var string
  86 + */
  87 + public $subject = '';
  88 +
  89 + /**
  90 + * mailer which send email
  91 + *
  92 + * @var null
  93 + */
  94 + public $mailer = null;
  95 +
  96 + /**
  97 + * @var \yii\db\ActiveRecord $model ;
  98 + */
  99 + public $model = null;
  100 +
  101 + /**
  102 + * send form with ajax
  103 + *
  104 + * @var bool
  105 + */
  106 + public $ajax = false;
  107 +
  108 + /**
  109 + * callback function for ajax script of send form
  110 + *
  111 + * @var string
  112 + */
  113 + public $successCallback = 'function (data) {
  114 + alert("ok");
  115 + }';
  116 +
  117 + /**
  118 + * error function for ajax script of send form
  119 + *
  120 + * @var string
  121 + */
  122 + public $errorCallback = 'function (data) {
  123 + alert("error");
  124 + }';
  125 +
  126 + /**
  127 + * id form
  128 + *
  129 + * @var string
  130 + */
  131 + public $formId = 'dynamic-form';
  132 +
  133 + /**
  134 + * options for submit button
  135 + *
  136 + * @var array
  137 + */
  138 + public $buttonOptions = ['class' => 'btn'];
  139 +
  140 + /**
  141 + * content for submit button
  142 + *
  143 + * @var string
  144 + */
  145 + public $buttonContent = 'Save';
  146 +
  147 + /**
  148 + * @var string
  149 + */
  150 + public $classForm = 'form';
  151 +
  152 + public $id = 'forms';
  153 +
  154 + public $buttonTemplate = '{button}';
  155 +
  156 + public $locale = 'app';
  157 +
  158 + /**
  159 + * Свойство, которое заменяет логику для отправки письма, если установлено $this->sendMail=true
  160 + * @var null
  161 + */
  162 + public $alternateMailLogic = false;
  163 +
  164 +
  165 + /**
  166 + * @inheritdoc
  167 + * @throws \yii\base\InvalidConfigException
  168 + */
  169 + public function init()
  170 + {
  171 + parent::init();
  172 +
  173 + if ($this->activeRecord !== null) {
  174 + $this->model = \Yii::createObject($this->activeRecord);
  175 + $this->model->scenario = $this->scenario;
  176 + } else {
  177 + $this->model = new DynamicModel($this->attributes);
  178 + $this->model->attributeLabels = $this->labels;
  179 + foreach ($this->rules as $rule) {
  180 + if (is_array($rule) && isset($rule[0], $rule[1])) {
  181 + $attributes = $rule[0];
  182 + $validator = $rule[1];
  183 + unset($rule[0], $rule[1]);
  184 + $this->model->addRule($attributes, $validator, $rule);
  185 + } else {
  186 + throw new InvalidConfigException(
  187 + 'Invalid validation rule: a rule must specify both attribute names and validator type.'
  188 + );
  189 + }
  190 + }
  191 + }
  192 + }
  193 +
  194 + /**
  195 + * render html form with model
  196 + *
  197 + * @param \yii\web\View $view
  198 + */
  199 + public function renderForm(View $view)
  200 + {
  201 + if ($this->ajax) {
  202 + $js = <<<JS
  203 +$(document).on('submit', '#{$this->formId}', function(e) {
  204 + e.preventDefault();
  205 + e.stopImmediatePropagation();
  206 + $.post(
  207 + $(this).attr("action"), $(this).serialize(), {$this->successCallback}).fail({$this->errorCallback});
  208 +});
  209 +JS;
  210 +
  211 + $view->registerJs($js, View::POS_READY);
  212 + }
  213 + /**
  214 + * @var ActiveForm $form
  215 + */
  216 +
  217 + $form = ActiveForm::begin(
  218 + [
  219 + 'id' => $this->formId,
  220 + 'action' => ($this->ajax) ? '/' . $this->id . '/save/ajax' : '/' . $this->id . '/save/no-ajax',
  221 + 'class' => $this->classForm,
  222 + ]
  223 + );
  224 + $content = '';
  225 + # var_dump($this->labels);
  226 + # die(var_dump($this->attributes));
  227 + foreach ($this->attributes as $field) {
  228 + if (isset($this->inputOptions[$field]['type'])) {
  229 + $function = $this->inputOptions[$field]['type'];
  230 + $formStr = $form->field($this->model, $field)
  231 + ->$function(
  232 + isset($this->inputOptions[$field]['options']) ? $this->inputOptions[$field]['options'] : []
  233 + );
  234 + } else {
  235 + $formStr = $form->field($this->model, $field);
  236 + }
  237 + if (isset($this->labels[$field])) {
  238 + $formStr->label(\Yii::t($this->locale, $this->labels[$field]));
  239 + }
  240 + if (isset($this->inputOptions[$field]['template'])) {
  241 + $formStr = str_replace('{input}', $formStr, $this->inputOptions[$field]['template']);
  242 + }
  243 + $content .= $formStr;
  244 + }
  245 +
  246 + $content .= str_replace('{button}', Html::submitButton(\Yii::t($this->locale, $this->buttonContent), $this->buttonOptions), $this->buttonTemplate);
  247 +
  248 + $content = str_replace('{form}', $content, $this->templateForm);
  249 + # die(var_dump(htmlspecialchars($content)));
  250 + echo $content;
  251 + ActiveForm::end();
  252 + }
  253 +}
0 254 \ No newline at end of file
... ...
frontend/modules/forms/controllers/SaveController.php 0 → 100755
  1 +<?php
  2 +
  3 +
  4 +namespace frontend\modules\forms\controllers;
  5 +
  6 +
  7 +use artbox\core\forms\DynamicModel;
  8 +use yii\web\Controller;
  9 +use yii\web\Response;
  10 +use common\components\MailerComponent;
  11 +
  12 +/**
  13 + * Class SaveController
  14 + *
  15 + * @property \artbox\core\forms\Module $module
  16 + * @package artbox\core\forms\controllers
  17 + */
  18 +class SaveController extends Controller
  19 +{
  20 + /**
  21 + * Custom data saving via POST
  22 + *
  23 + * @return bool|\yii\web\Response
  24 + * @throws \yii\base\InvalidConfigException
  25 + */
  26 + public function actionNoAjax()
  27 + {
  28 + $returnUrl = \Yii::$app->request->referrer;
  29 + $model = $this->module->model;
  30 + if (\Yii::$app->request->isPost and $model->load(\Yii::$app->request->post())) {
  31 + if ($model instanceof DynamicModel) {
  32 + $this->sendEmail($model);
  33 + } else {
  34 + if ($model->save()) {
  35 + if ($this->module->sendEmail) {
  36 + $this->sendEmail($model);
  37 + return $this->redirect($returnUrl);
  38 + }
  39 + } else {
  40 + return false;
  41 + }
  42 + }
  43 + return $this->redirect($returnUrl);
  44 +
  45 + }
  46 + return $this->redirect($returnUrl);
  47 + }
  48 +
  49 + /**
  50 + * Action that saves data submited via AJAX
  51 + *
  52 + * @return array
  53 + * @throws \yii\base\InvalidConfigException
  54 + */
  55 + public function actionAjax()
  56 + {
  57 + \Yii::$app->response->format = Response::FORMAT_JSON;
  58 + $model = $this->module->model;
  59 + #die(var_dump(\Yii::$app->request->post()));
  60 + if (\Yii::$app->request->isPost and $model->load(\Yii::$app->request->post())) {
  61 + if ($model instanceof DynamicModel) {
  62 + $this->sendEmail($model);
  63 + return ['status' => 'success'];
  64 + } else {
  65 + if ($model->save()) {
  66 + if ($this->module->sendEmail) {
  67 + if ($this->module->alternateMailLogic) {
  68 + MailerComponent::sendListToAdminAfterSubmit(4, ['user_data' => $model->phone]);
  69 + } else {
  70 + $this->sendEmail($model);
  71 + }
  72 +
  73 + return ['status' => 'success'];
  74 + }
  75 + return ['status' => 'success'];
  76 + } else {
  77 + return ['status' => 'error'];
  78 + }
  79 + }
  80 +
  81 + }
  82 + return ['status' => 'error'];
  83 + }
  84 +
  85 + /**
  86 + * @param $model
  87 + *
  88 + * @return bool
  89 + * @throws \yii\base\InvalidConfigException
  90 + */
  91 + public function sendEmail($model)
  92 + {
  93 +
  94 + if ($this->module->mailer == null) {
  95 + $mailer = \Yii::$app->mailer;
  96 + } else {
  97 + $mailer = \Yii::$app->get($this->module->mailer);
  98 + }
  99 + return $mailer->compose(
  100 + [
  101 + 'html' => $this->module->emailFile,
  102 + 'text' => $this->module->emailFile,
  103 + ],
  104 + [$model]
  105 + )
  106 + ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
  107 + ->setTo($this->module->email)
  108 + ->setSubject($this->module->subject)
  109 + ->send();
  110 + }
  111 +
  112 +}
0 113 \ No newline at end of file
... ...
frontend/modules/forms/views/form/form.php 0 → 100755
  1 +<?php
  2 +/**
  3 + * @var \yii\db\ActiveRecord $model
  4 + * @var array $types
  5 + */
  6 +
  7 +use yii\helpers\Html;
  8 +use yii\widgets\ActiveForm;
  9 +
  10 +$form = ActiveForm::begin(['id' => 'dynamic-form']);
  11 +foreach ($this->context->module->attributes as $field) {
  12 +
  13 + if (isset($types[$field])) {
  14 + $function = $types[$field]['type'];
  15 + echo $form->field($model, $field)
  16 + ->$function(
  17 + $types[$field]['options']
  18 + );
  19 + } else {
  20 + echo $form->field($model, $field);
  21 + }
  22 +
  23 +}
  24 +
  25 +echo Html::submitButton();
  26 +
  27 +$form = ActiveForm::end();
... ...
frontend/views/layouts/main.php
... ... @@ -652,7 +652,7 @@
652 652 <div class="style title-callback">Записаться на прием</div>
653 653 <?php
654 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 656 <div class="input-wr phones_mask required">
657 657 <?= $form->field($model, 'phone')
658 658 ->textInput([ 'placeholder' => '+38(0__)___-__-__' ])
... ...