1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\modules\feedback\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\db\ActiveRecord; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* This is the model class for table "feedback". |
10
|
|
|
* |
11
|
|
|
* @property integer $id |
12
|
|
|
* @property string $name |
13
|
|
|
* @property string $email |
14
|
|
|
* @property string $message |
15
|
|
|
* @property string $status |
16
|
|
|
* @property string $created_at |
17
|
|
|
* @property string $updated_at |
18
|
|
|
*/ |
19
|
|
|
class Feedback extends ActiveRecord |
20
|
|
|
{ |
21
|
|
|
const STATUS_NEW = 'new'; |
22
|
|
|
const STATUS_ANSWERED = 'answered'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @inheritdoc |
26
|
|
|
*/ |
27
|
6 |
|
public static function tableName() |
28
|
|
|
{ |
29
|
6 |
|
return 'feedback'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
3 |
|
public function rules() |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
3 |
|
[['email'], 'required'], |
39
|
|
|
[['message', 'status'], 'string'], |
40
|
|
|
[['created_at', 'updated_at'], 'safe'], |
41
|
|
|
[['name', 'email'], 'string', 'max' => 255], |
42
|
|
|
[ |
43
|
3 |
|
['status'], 'in', 'range' => [self::STATUS_ANSWERED, self::STATUS_NEW], |
44
|
3 |
|
'message' => Yii::t('feedback', 'Status is invalid.'), |
45
|
|
|
], |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritdoc |
51
|
|
|
*/ |
52
|
3 |
View Code Duplication |
public function attributeLabels() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
3 |
|
'id' => Yii::t('feedback', 'ID'), |
56
|
3 |
|
'name' => Yii::t('feedback', 'Name'), |
57
|
3 |
|
'email' => Yii::t('feedback', 'Email'), |
58
|
3 |
|
'message' => Yii::t('feedback', 'Message'), |
59
|
3 |
|
'status' => Yii::t('feedback', 'Status'), |
60
|
3 |
|
'created_at' => Yii::t('feedback', 'Created At'), |
61
|
3 |
|
'updated_at' => Yii::t('feedback', 'Updated At'), |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.