|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\backend\models; |
|
4
|
|
|
|
|
5
|
|
|
use app\modules\user\models\User; |
|
6
|
|
|
use Yii; |
|
7
|
|
|
use yii\db\ActiveRecord; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* This is the model class for table "order_chat". |
|
11
|
|
|
* |
|
12
|
|
|
* @property string $id |
|
13
|
|
|
* @property string $order_id |
|
14
|
|
|
* @property string $user_id |
|
15
|
|
|
* @property string $date |
|
16
|
|
|
* @property string $message |
|
17
|
|
|
* Relations: |
|
18
|
|
|
* @property User $user |
|
19
|
|
|
*/ |
|
20
|
|
|
class OrderChat extends ActiveRecord |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @inheritdoc |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function tableName() |
|
26
|
|
|
{ |
|
27
|
|
|
return '{{%order_chat}}'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @inheritdoc |
|
32
|
|
|
*/ |
|
33
|
|
|
public function rules() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
|
|
[['order_id', 'user_id', 'message'], 'required'], |
|
37
|
|
|
[['order_id', 'user_id'], 'integer'], |
|
38
|
|
|
[['date'], 'safe'], |
|
39
|
|
|
[['message'], 'string'], |
|
40
|
|
|
[['user_id'], 'default', 'value' => \Yii::$app->user->id], |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @inheritdoc |
|
46
|
|
|
*/ |
|
47
|
|
|
public function attributeLabels() |
|
48
|
|
|
{ |
|
49
|
|
|
return [ |
|
50
|
|
|
'id' => Yii::t('app', 'ID'), |
|
51
|
|
|
'order_id' => Yii::t('app', 'Order ID'), |
|
52
|
|
|
'user_id' => Yii::t('app', 'User ID'), |
|
53
|
|
|
'date' => Yii::t('app', 'Date'), |
|
54
|
|
|
'message' => Yii::t('app', 'Message'), |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return User |
|
|
|
|
|
|
60
|
|
|
*/ |
|
61
|
|
|
public function getUser() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->hasOne(User::className(), ['id' => 'user_id']); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function beforeSave($insert) |
|
67
|
|
|
{ |
|
68
|
|
|
if (false === parent::beforeSave($insert)) { |
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
if (empty($this->message)) { |
|
|
|
|
|
|
73
|
|
|
return false; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
?> |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.