ArticleCategory.php
3.67 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
<?php
namespace common\modules\blog\models;
use common\modules\blog\behaviors\Autocomplete;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\db\Query;
/**
* This is the model class for table "article_category".
*
* @property integer $article_category_id
* @property integer $status
* @property integer $sort
* @property string $code
* @property string $date_add
* @property string $date_update
* @property string $tag
* @property integer $artucle_category_pid
*
* @property Article[] $articles
* @property ArticleCategory $parent
* @property ArticleCategory[] $articleCategories
* @property ArticleCategoryLang[] $articleCategoryLangs
* @property ArticleCategoryMedia[] $articleCategoryMedia
*/
class ArticleCategory extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'article_category';
}
public function behaviors()
{
return [
[
'class' => Autocomplete::className(),
'attributes' => [
'translit' => ['code'],
]
]
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['status', 'sort', 'article_category_pid'], 'integer'],
[['code'], 'required'],
[['code', 'tag'], 'string'],
[['date_add', 'date_update'], 'safe'],
[['status'], 'boolean'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'article_category_id' => Yii::t('app', 'ID'),
'status' => Yii::t('app', 'Active'),
'sort' => Yii::t('app', 'Sort'),
'code' => Yii::t('app', 'Code'),
'date_add' => Yii::t('app', 'Created At'),
'date_update' => Yii::t('app', 'Updated At'),
'tag' => Yii::t('app', 'Tags'),
'article_category_pid' => Yii::t('app', 'Parent ID'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticles()
{
return $this->hasMany(Article::className(), ['article_id' => 'article_id'])->viaTable('article_to_category', ['article_category_id' => 'article_category_id']) ;
}
/**
* @return \yii\db\ActiveQuery
*/
public function getParent()
{
return $this->hasOne(ArticleCategory::className(), ['article_category_id' => 'article_category_pid']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticleCategories()
{
return $this->hasMany(ArticleCategory::className(), ['article_category_pid' => 'article_category_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticleCategoryLangs()
{
return $this->hasMany(ArticleCategoryLang::className(), ['article_category_id' => 'article_category_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticleCategoryMedia()
{
return $this->hasMany(ArticleCategoryMedia::className(), ['article_category_id' => 'article_category_id']);
}
public static function findArticleCategoryDropdown($id)
{
$query = new Query();
return $query->select(['l.name', 'c.article_category_id'])
->from(['article_category c'])
->leftJoin(['article_category_lang l'], 'c.article_category_id = l.article_category_id')
->where(['l.language_id' => 0, 'c.status' => 1])
->andWhere(['not', ['c.article_category_id' => $id]])
->indexBy('article_category_id')
->column();
}
}