Commit 4ec01e3b5a3715458cf189028162ce4612b0783d
1 parent
5d99555b
-New feedback model
Showing
2 changed files
with
124 additions
and
1 deletions
Show diff stats
frontend/controllers/FeedbackController.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace frontend\controllers; | 3 | namespace frontend\controllers; |
4 | 4 | ||
5 | - use artbox\core\models\Feedback; | 5 | + use frontend\models\Feedback; |
6 | use yii\filters\Cors; | 6 | use yii\filters\Cors; |
7 | use yii\web\Controller; | 7 | use yii\web\Controller; |
8 | use yii\web\Response; | 8 | use yii\web\Response; |
1 | +<?php | ||
2 | + | ||
3 | + namespace frontend\models; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + use yii\behaviors\AttributeBehavior; | ||
7 | + use yii\behaviors\TimestampBehavior; | ||
8 | + use yii\db\ActiveRecord; | ||
9 | + | ||
10 | + /** | ||
11 | + * This is the model class for table "feedback". | ||
12 | + * | ||
13 | + * @property integer $id | ||
14 | + * @property string $name | ||
15 | + * @property string $email | ||
16 | + * @property string $phone | ||
17 | + * @property string $message | ||
18 | + * @property integer $created_at | ||
19 | + * @property string $ip | ||
20 | + * @property string $url | ||
21 | + * @property bool $status | ||
22 | + */ | ||
23 | + class Feedback extends ActiveRecord | ||
24 | + { | ||
25 | + public $returnUrl; | ||
26 | + | ||
27 | + /** | ||
28 | + * @inheritdoc | ||
29 | + */ | ||
30 | + public static function tableName() | ||
31 | + { | ||
32 | + return 'feedback'; | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * @inheritdoc | ||
37 | + */ | ||
38 | + public function behaviors() | ||
39 | + { | ||
40 | + return [ | ||
41 | + [ | ||
42 | + 'class' => TimestampBehavior::className(), | ||
43 | + 'updatedAtAttribute' => false, | ||
44 | + ], | ||
45 | + [ | ||
46 | + 'class' => AttributeBehavior::className(), | ||
47 | + 'attributes' => [ | ||
48 | + ActiveRecord::EVENT_BEFORE_INSERT => 'ip', | ||
49 | + ], | ||
50 | + 'value' => function () { | ||
51 | + return \Yii::$app->request->userIP; | ||
52 | + }, | ||
53 | + ], | ||
54 | + [ | ||
55 | + 'class' => AttributeBehavior::className(), | ||
56 | + 'attributes' => [ | ||
57 | + ActiveRecord::EVENT_BEFORE_INSERT => 'url', | ||
58 | + ], | ||
59 | + 'value' => function () { | ||
60 | + return \Yii::$app->request->referrer; | ||
61 | + }, | ||
62 | + ], | ||
63 | + ]; | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * @inheritdoc | ||
68 | + */ | ||
69 | + public function rules() | ||
70 | + { | ||
71 | + return [ | ||
72 | + [ | ||
73 | + [ | ||
74 | + 'email', | ||
75 | + ], | ||
76 | + 'required', | ||
77 | + ], | ||
78 | + [ | ||
79 | + [ 'email' ], | ||
80 | + 'email', | ||
81 | + ], | ||
82 | + [ | ||
83 | + [ | ||
84 | + 'name', | ||
85 | + 'phone', | ||
86 | + 'email', | ||
87 | + ], | ||
88 | + 'string', | ||
89 | + 'max' => 255, | ||
90 | + ], | ||
91 | + [ | ||
92 | + [ | ||
93 | + 'message', | ||
94 | + ], | ||
95 | + 'string', | ||
96 | + ], | ||
97 | + [ | ||
98 | + [ | ||
99 | + 'status', | ||
100 | + ], | ||
101 | + 'boolean', | ||
102 | + ], | ||
103 | + ]; | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * @inheritdoc | ||
108 | + */ | ||
109 | + public function attributeLabels() | ||
110 | + { | ||
111 | + return [ | ||
112 | + 'id' => Yii::t('core', 'id'), | ||
113 | + 'name' => Yii::t('core', 'name'), | ||
114 | + 'phone' => Yii::t('core', 'phone'), | ||
115 | + 'created_at' => Yii::t('core', 'created_at'), | ||
116 | + 'ip' => Yii::t('core', 'ip'), | ||
117 | + 'url' => Yii::t('core', 'url'), | ||
118 | + 'status' => Yii::t('core', 'status'), | ||
119 | + 'message' => Yii::t('core', 'message'), | ||
120 | + 'email' => Yii::t('core', 'email'), | ||
121 | + ]; | ||
122 | + } | ||
123 | + } |