c5a6465c
Alexey Boroda
-Blog half-way done
|
1
2
3
4
5
6
|
<?php
namespace common\modules\blog\models;
use yii\db\ActiveRecord;
use common\modules\language\behaviors\LanguageBehavior;
|
52190232
Alexey Boroda
-Blog almost done
|
7
8
9
10
|
use common\behaviors\SaveImgBehavior;
use common\modules\language\models\Language;
use yii\db\ActiveQuery;
use yii\web\Request;
|
c5a6465c
Alexey Boroda
-Blog half-way done
|
11
12
13
14
15
16
17
18
19
20
21
22
23
|
/**
* This is the model class for table "blog_category".
*
* @property integer $id
* @property integer $sort
* @property string $image
* @property integer $parent_id
* @property boolean $status
* @property BlogArticleToCategory[] $blogArticleToCategories
* @property BlogArticle[] $blogArticles
* @property BlogCategoryLang[] $blogCategoryLangs
* @property Language[] $languages
|
52190232
Alexey Boroda
-Blog almost done
|
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
|
* * From language behavior *
* @property BlogCategoryLang $lang
* @property BlogCategoryLang[] $langs
* @property BlogCategoryLang $objectLang
* @property string $ownerKey
* @property string $langKey
* @property BlogCategoryLang[] $modelLangs
* @property bool $transactionStatus
* @method string getOwnerKey()
* @method void setOwnerKey( string $value )
* @method string getLangKey()
* @method void setLangKey( string $value )
* @method ActiveQuery getLangs()
* @method ActiveQuery getLang( integer $language_id )
* @method BlogCategoryLang[] generateLangs()
* @method void loadLangs( Request $request )
* @method bool linkLangs()
* @method bool saveLangs()
* @method bool getTransactionStatus()
* * End language behavior *
* * From SaveImgBehavior *
* @property string|null $imageFile
* @property string|null $imageUrl
* @method string|null getImageFile( int $field )
* @method string|null getImageUrl( int $field )
* * End SaveImgBehavior
|
c5a6465c
Alexey Boroda
-Blog half-way done
|
50
51
52
53
54
55
56
57
58
59
|
*/
class BlogCategory extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'blog_category';
}
|
52190232
Alexey Boroda
-Blog almost done
|
60
|
|
c5a6465c
Alexey Boroda
-Blog half-way done
|
61
62
63
64
65
66
|
/**
* @inheritdoc
*/
public function behaviors()
{
return [
|
52190232
Alexey Boroda
-Blog almost done
|
67
68
69
70
71
72
73
74
75
|
[
'class' => SaveImgBehavior::className(),
'fields' => [
[
'name' => 'image',
'directory' => 'blog/category',
],
],
],
|
c5a6465c
Alexey Boroda
-Blog half-way done
|
76
77
78
|
'language' => [
'class' => LanguageBehavior::className(),
],
|
52190232
Alexey Boroda
-Blog almost done
|
79
80
81
|
'Slug' => [
'class' => 'common\behaviors\Slug',
],
|
c5a6465c
Alexey Boroda
-Blog half-way done
|
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
|
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
'sort',
'parent_id',
],
'integer',
],
[
[ 'status' ],
'boolean',
],
[
[ 'image' ],
'string',
'max' => 255,
],
|
52190232
Alexey Boroda
-Blog almost done
|
107
108
109
110
111
|
[
['parent_id'],
'default',
'value' => 0,
],
|
c5a6465c
Alexey Boroda
-Blog half-way done
|
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
|
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'sort' => 'Sort',
'image' => 'Image',
'parent_id' => 'Parent ID',
'status' => 'Status',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getBlogArticleToCategories()
{
return $this->hasMany(BlogArticleToCategory::className(), [ 'blog_category_id' => 'id' ]);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getBlogArticles()
{
return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ])
->viaTable('blog_article_to_category', [ 'blog_category_id' => 'id' ]);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getBlogCategoryLangs()
{
return $this->hasMany(BlogCategoryLang::className(), [ 'blog_category_id' => 'id' ]);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getLanguages()
{
return $this->hasMany(Language::className(), [ 'id' => 'language_id' ])
->viaTable('blog_category_lang', [ 'blog_category_id' => 'id' ]);
}
}
|