Commit 27658cd5786de5b57370edcb0b1346713e51f8a3

Authored by Yarik
1 parent b6b48c70

Commit

Showing 2 changed files with 119 additions and 66 deletions   Show diff stats
common/mail/feedback_success.php 0 → 100755
  1 +<?php
  2 + use common\models\Feedback;
  3 +
  4 + /**
  5 + * @var yii\web\View $this
  6 + * @var Feedback $model
  7 + */
  8 +?>
  9 +<div>
  10 + <p style="text-align: center"><b>Proektant.net</b></p>
  11 + <p>Получен вопрос от: <?php echo $model->name?></p>
  12 + <p>Телефон: <?php echo $model->phone ?></p>
  13 + <p>Email: <?php echo $model->email ?></p>
  14 + <p>Вопрос:</p>
  15 + <p><?php echo $model->answer ?></p>
  16 +</div>
common/models/Feedback.php
1 <?php 1 <?php
2 2
3 -namespace common\models; 3 + namespace common\models;
4 4
5 -use common\modules\fileloader\behaviors\FileloaderBehavior;  
6 -use Yii;  
7 -use yii\behaviors\TimestampBehavior;  
8 -use yii\db\Expression; 5 + use common\modules\fileloader\behaviors\FileloaderBehavior;
  6 + use Yii;
  7 + use yii\behaviors\TimestampBehavior;
  8 + use yii\db\Expression;
9 9
10 -/**  
11 - * This is the model class for table "feedback".  
12 - *  
13 - * @property integer $feedback_id  
14 - * @property string $name  
15 - * @property string $phone  
16 - * @property string $email  
17 - * @property string $answer  
18 - * @property string $file  
19 - * @property string $date_add  
20 - */  
21 -class Feedback extends \yii\db\ActiveRecord  
22 -{  
23 /** 10 /**
24 - * @inheritdoc 11 + * This is the model class for table "feedback".
  12 + * @property integer $feedback_id
  13 + * @property string $name
  14 + * @property string $phone
  15 + * @property string $email
  16 + * @property string $answer
  17 + * @property string $file
  18 + * @property string $date_add
25 */ 19 */
26 - public static function tableName() 20 + class Feedback extends \yii\db\ActiveRecord
27 { 21 {
28 - return 'feedback';  
29 - }  
30 22
31 - /**  
32 - * @inheritdoc  
33 - */  
34 - public function behaviors()  
35 - {  
36 - return [  
37 - [  
38 - 'class' => TimestampBehavior::className(),  
39 - 'createdAtAttribute' => 'date_add',  
40 - 'updatedAtAttribute' => false,  
41 - 'value' => new Expression('NOW()'),  
42 - ],  
43 - 'fileloader' => [  
44 - 'class' => FileloaderBehavior::className(),  
45 - ],  
46 - ];  
47 - } 23 + /**
  24 + * @inheritdoc
  25 + */
  26 + public static function tableName()
  27 + {
  28 + return 'feedback';
  29 + }
48 30
49 - /**  
50 - * @inheritdoc  
51 - */  
52 - public function rules()  
53 - {  
54 - return [  
55 - [['name', 'answer', 'email'], 'required'],  
56 - [['email'], 'email'],  
57 - [['phone'], 'match', 'pattern' => '/^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$/'],  
58 - [['name', 'phone', 'answer'], 'string', 'max' => 255],  
59 - ];  
60 - } 31 + /**
  32 + * @inheritdoc
  33 + */
  34 + public function behaviors()
  35 + {
  36 + return [
  37 + [
  38 + 'class' => TimestampBehavior::className(),
  39 + 'createdAtAttribute' => 'date_add',
  40 + 'updatedAtAttribute' => false,
  41 + 'value' => new Expression('NOW()'),
  42 + ],
  43 + 'fileloader' => [
  44 + 'class' => FileloaderBehavior::className(),
  45 + ],
  46 + ];
  47 + }
61 48
62 - /**  
63 - * @inheritdoc  
64 - */  
65 - public function attributeLabels()  
66 - {  
67 - return [  
68 - 'feedback_id' => Yii::t('app', 'Feedback ID'),  
69 - 'name' => Yii::t('app', 'Feedback name'),  
70 - 'phone' => Yii::t('app', 'Feedback phone'),  
71 - 'email' => Yii::t('app', 'Feedback email'),  
72 - 'answer' => Yii::t('app', 'Feedback answer'),  
73 - 'file' => Yii::t('app', 'Feedback file'),  
74 - 'date_add' => Yii::t('app', 'Feedback date Add'),  
75 - ]; 49 + /**
  50 + * @inheritdoc
  51 + */
  52 + public function rules()
  53 + {
  54 + return [
  55 + [
  56 + [
  57 + 'name',
  58 + 'answer',
  59 + 'email',
  60 + ],
  61 + 'required',
  62 + ],
  63 + [
  64 + [ 'email' ],
  65 + 'email',
  66 + ],
  67 + [
  68 + [ 'phone' ],
  69 + 'match',
  70 + 'pattern' => '/^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$/',
  71 + ],
  72 + [
  73 + [
  74 + 'name',
  75 + 'phone',
  76 + 'answer',
  77 + ],
  78 + 'string',
  79 + 'max' => 255,
  80 + ],
  81 + ];
  82 + }
  83 +
  84 + /**
  85 + * @inheritdoc
  86 + */
  87 + public function attributeLabels()
  88 + {
  89 + return [
  90 + 'feedback_id' => Yii::t('app', 'Feedback ID'),
  91 + 'name' => Yii::t('app', 'Feedback name'),
  92 + 'phone' => Yii::t('app', 'Feedback phone'),
  93 + 'email' => Yii::t('app', 'Feedback email'),
  94 + 'answer' => Yii::t('app', 'Feedback answer'),
  95 + 'file' => Yii::t('app', 'Feedback file'),
  96 + 'date_add' => Yii::t('app', 'Feedback date Add'),
  97 + ];
  98 + }
  99 +
  100 + public function afterSave($insert, $changedAttributes)
  101 + {
  102 + parent::afterSave($insert, $changedAttributes);
  103 + $this->sendEmail();
  104 + }
  105 +
  106 + public function sendEmail()
  107 + {
  108 + return \Yii::$app->mailer->compose('feedback_success', [ 'model' => $this ])
  109 + ->setFrom([ \Yii::$app->params[ 'supportEmail' ] => \Yii::$app->name . ' robot' ])
  110 + ->setTo('info@proektant.net')
  111 + ->setSubject('Заявка от ' . $this->name)
  112 + ->send();
  113 + }
76 } 114 }
77 -}