|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Model; |
|
4
|
|
|
|
|
5
|
|
|
use App\Behavior\CreatorBehavior; |
|
6
|
|
|
use App\Behavior\TimestampBehavior; |
|
7
|
|
|
use Yii; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* This is the model class for table "{{%article_comment}}". |
|
11
|
|
|
* |
|
12
|
|
|
* @property int $id |
|
13
|
|
|
* @property int $reply_to Reply To |
|
14
|
|
|
* @property int $article_id Article ID |
|
15
|
|
|
* @property int $user_id User ID |
|
16
|
|
|
* @property string $content Content |
|
17
|
|
|
* @property int $is_deleted Is Deleted |
|
18
|
|
|
* @property int $create_time Create Time |
|
19
|
|
|
* @property int $update_time Update Time |
|
20
|
|
|
* |
|
21
|
|
|
* @property Article $article |
|
22
|
|
|
* @property User $user |
|
23
|
|
|
* @property string $username |
|
24
|
|
|
*/ |
|
25
|
|
|
class ArticleComment extends \App\Model\ActiveRecord |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function tableName() |
|
31
|
|
|
{ |
|
32
|
|
|
return '{{%article_comment}}'; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function behaviors() |
|
36
|
|
|
{ |
|
37
|
|
|
return [ |
|
38
|
|
|
TimestampBehavior::class, |
|
39
|
|
|
[ |
|
40
|
|
|
'class' => CreatorBehavior::class, |
|
41
|
|
|
'creatorAttribute' => 'user_id', |
|
42
|
|
|
] |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function rules() |
|
50
|
|
|
{ |
|
51
|
|
|
return [ |
|
52
|
|
|
[['reply_to', 'article_id', 'user_id', 'is_deleted', 'create_time', 'update_time'], 'integer'], |
|
53
|
|
|
[['article_id', 'user_id', 'content'], 'required'], |
|
54
|
|
|
[['content'], 'string'], |
|
55
|
|
|
['article_id', 'exist', 'targetClass' => Article::class, 'targetAttribute' => 'id'], |
|
56
|
|
|
['user_id', 'exist', 'targetClass' => User::class, 'targetAttribute' => 'id'], |
|
57
|
|
|
]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function attributeLabels() |
|
64
|
|
|
{ |
|
65
|
|
|
return [ |
|
66
|
|
|
'id' => Yii::t('app', 'ID'), |
|
67
|
|
|
'reply_to' => Yii::t('app', 'Reply To'), |
|
68
|
|
|
'article_id' => Yii::t('app', 'Article ID'), |
|
69
|
|
|
'user_id' => Yii::t('app', 'User ID'), |
|
70
|
|
|
'content' => Yii::t('app', 'Content'), |
|
71
|
|
|
'is_deleted' => Yii::t('app', 'Is Deleted'), |
|
72
|
|
|
'create_time' => Yii::t('app', 'Create Time'), |
|
73
|
|
|
'update_time' => Yii::t('app', 'Update Time'), |
|
74
|
|
|
]; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getArticle() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->hasOne(Article::class, ['id' => 'article_id']); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getUser() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->hasOne(User::class, ['id' => 'user_id']); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getUsername() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->user ? $this->user->name : ''; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|