Article.php
4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace common\modules\blog\models;
use common\models\ActiveRecordRule;
use common\models\Media;
use common\models\User;
use common\modules\blog\behaviors\Autocomplete;
use Yii;
use yii\db\Query;
/**
* This is the model class for table "article".
*
* @property integer $article_id
* @property integer $sort
* @property string $date_add
* @property string $date_update
* @property string $code
* @property integer $user_id
* @property string $tag
* @property integer $article_pid
* @property integer $status
* @property integer $comment
* @property integer $vote
*
* @property Article $parent
* @property Article[] $articles
* @property User $user
* @property ArticleLang[] $articleLangs
* @property ArticleMedia[] $articleMedia
* @property ArticleToCategory[] $articleToCategories
* @property Media[] $media
*/
class Article extends ActiveRecordRule
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'article';
}
public function behaviors()
{
return [
[
'class' => Autocomplete::className(),
'attributes' => [
'translit' => ['code'],
]
]
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['sort', 'article_pid', 'status', 'comment', 'vote'], 'integer'],
[['date_add', 'date_update'], 'safe'],
[['code'], 'required'],
[['code', 'tag'], 'string']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'article_id' => Yii::t('app', 'ID'),
'sort' => Yii::t('app', 'Sort'),
'date_add' => Yii::t('app', 'Create At'),
'date_update' => Yii::t('app', 'Update At'),
'code' => Yii::t('app', 'Code'),
'user_id' => Yii::t('app', 'Author'),
'tag' => Yii::t('app', 'Tags'),
'article_pid' => Yii::t('app', 'Parent ID'),
'status' => Yii::t('app', 'Active'),
'comment' => Yii::t('app', 'Comments'),
'vote' => Yii::t('app', 'Voting'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getParent()
{
return $this->hasOne(Article::className(), ['article_id' => 'article_pid']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticles()
{
return $this->hasMany(Article::className(), ['article_pid' => 'article_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticleLangs()
{
return $this->hasMany(ArticleLang::className(), ['article_id' => 'article_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticleMedia()
{
return $this->hasMany(ArticleMedia::className(), ['article_id' => 'article_id']);
}
public function getMedia()
{
return $this->hasMany(Media::className(), ['article_id' => 'media_id'])->via('articleMedia');
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticleToCategories()
{
return $this->hasMany(ArticleToCategory::className(), ['article_id' => 'article_id']);
}
public function getArticleCategories()
{
return $this->hasMany(ArticleCategory::className(), ['article_category_id' => 'article_category_id'])->viaTable('article_to_category', ['article_id' => 'article_category_id']);
}
public static function findArticleDropdown($id)
{
$query = new Query();
return $query->select(['l.name', 'a.article_id'])
->from(['article a'])
->leftJoin(['article_lang l'], 'a.article_id = l.article_id')
->where(['l.language_id' => 0, 'a.status' => 1])
->andWhere(['not', ['a.article_id' => $id]])
->indexBy('article_id')
->column();
}
public function getArticleCategoriesArray()
{
return $this->getArticleToCategories()->select('article_category_id')->column();
}
}