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
|
/**
* This is the model class for table "blog_category".
*
|
c846c007
Alexey Boroda
-Blog ready
|
15
16
17
18
19
20
21
22
23
|
* @property integer $id
* @property integer $sort
* @property string $image
* @property integer $parent_id
* @property boolean $status
* @property BlogArticle[] $blogArticles
* @property BlogCategoryLang[] $blogCategoryLangs
* @property Language[] $languages
* @property BlogCategory $parent
|
52190232
Alexey Boroda
-Blog almost done
|
24
|
* * From language behavior *
|
c846c007
Alexey Boroda
-Blog ready
|
25
26
27
28
29
30
31
|
* @property BlogCategoryLang $lang
* @property BlogCategoryLang[] $langs
* @property BlogCategoryLang $objectLang
* @property string $ownerKey
* @property string $langKey
* @property BlogCategoryLang[] $modelLangs
* @property bool $transactionStatus
|
52190232
Alexey Boroda
-Blog almost done
|
32
33
34
35
36
37
38
39
40
41
42
43
44
|
* @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 *
|
c846c007
Alexey Boroda
-Blog ready
|
45
46
|
* @property string|null $imageFile
* @property string|null $imageUrl
|
52190232
Alexey Boroda
-Blog almost done
|
47
48
49
|
* @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(),
],
|
c846c007
Alexey Boroda
-Blog ready
|
79
|
'Slug' => [
|
52190232
Alexey Boroda
-Blog almost done
|
80
81
|
'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
|
[
|
c846c007
Alexey Boroda
-Blog ready
|
108
|
[ 'parent_id' ],
|
52190232
Alexey Boroda
-Blog almost done
|
109
110
111
|
'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
|
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'sort' => 'Sort',
'image' => 'Image',
'parent_id' => 'Parent ID',
'status' => 'Status',
];
}
/**
* @return \yii\db\ActiveQuery
*/
|
c5a6465c
Alexey Boroda
-Blog half-way done
|
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
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' ]);
}
|
c846c007
Alexey Boroda
-Blog ready
|
154
155
156
157
158
|
public function getParent()
{
return $this->hasOne(BlogCategory::className(), [ 'id' => 'parent_id' ]);
}
|
c5a6465c
Alexey Boroda
-Blog half-way done
|
159
|
}
|