d8c1a2e0
Yarik
Big commit artbox
|
1
|
<?php
|
36d1807a
Yarik
Big commit.
|
2
3
4
|
namespace common\modules\rubrication\models;
|
d55d2fe0
Yarik
Multilanguage
|
5
|
use common\modules\language\behaviors\LanguageBehavior;
|
36d1807a
Yarik
Big commit.
|
6
|
use common\modules\product\models\Category;
|
d55d2fe0
Yarik
Multilanguage
|
7
8
9
|
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\web\Request;
|
93c267f7
Yarik
Multilanguage big...
|
10
|
|
d8c1a2e0
Yarik
Big commit artbox
|
11
|
/**
|
36d1807a
Yarik
Big commit.
|
12
|
* This is the model class for table "{{%tax_group}}".
|
93c267f7
Yarik
Multilanguage big...
|
13
14
15
16
17
18
19
20
21
|
* @property integer $tax_group_id
* @property boolean $is_filter
* @property integer $level
* @property integer $sort
* @property boolean $display
* @property boolean $is_menu
* @property TaxOption[] $taxOptions
* @property Category[] $categories
* @property TaxOption[] $options
|
d55d2fe0
Yarik
Multilanguage
|
22
|
* * From language behavior *
|
93c267f7
Yarik
Multilanguage big...
|
23
24
25
|
* @property TaxGroupLang $lang
* @property TaxGroupLang[] $langs
* @property TaxGroupLang $object_lang
|
d55d2fe0
Yarik
Multilanguage
|
26
27
28
|
* @property string $ownerKey
* @property string $langKey
* @method string getOwnerKey()
|
93c267f7
Yarik
Multilanguage big...
|
29
|
* @method void setOwnerKey( string $value )
|
d55d2fe0
Yarik
Multilanguage
|
30
|
* @method string getLangKey()
|
93c267f7
Yarik
Multilanguage big...
|
31
|
* @method void setLangKey( string $value )
|
d55d2fe0
Yarik
Multilanguage
|
32
33
34
|
* @method ActiveQuery getLangs()
* @method ActiveQuery getLang( integer $language_id )
* @method TaxGroupLang[] generateLangs()
|
93c267f7
Yarik
Multilanguage big...
|
35
36
37
|
* @method void loadLangs( Request $request, ActiveRecord[] $model_langs )
* @method bool linkLangs( ActiveRecord[] $model_langs )
* @method bool saveLangs( ActiveRecord[] $model_langs )
|
d55d2fe0
Yarik
Multilanguage
|
38
|
* * End language behavior *
|
d8c1a2e0
Yarik
Big commit artbox
|
39
|
*/
|
36d1807a
Yarik
Big commit.
|
40
|
class TaxGroup extends \yii\db\ActiveRecord
|
d8c1a2e0
Yarik
Big commit artbox
|
41
|
{
|
93c267f7
Yarik
Multilanguage big...
|
42
|
|
cc658b4c
Yarik
Big commit
|
43
44
45
|
/**
* @var TaxOption[] $_options
*/
|
36d1807a
Yarik
Big commit.
|
46
47
48
49
50
51
52
53
|
public $_options = [];
/**
* @inheritdoc
*/
public function behaviors()
{
return [
|
d55d2fe0
Yarik
Multilanguage
|
54
55
56
|
'language' => [
'class' => LanguageBehavior::className(),
],
|
36d1807a
Yarik
Big commit.
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
];
}
/**
* @inheritdoc
*/
public static function tableName()
{
return 'tax_group';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
|
36d1807a
Yarik
Big commit.
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
'is_filter',
'display',
'is_menu',
],
'boolean',
],
[
[
'level',
'sort',
],
'integer',
],
[
|
36d1807a
Yarik
Big commit.
|
90
91
92
93
94
95
96
97
98
99
100
101
102
|
[ 'categories' ],
'safe',
],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'tax_group_id' => 'Tax Group ID',
|
36d1807a
Yarik
Big commit.
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
'is_filter' => 'Use in filter',
'sort' => 'Sort',
'display' => 'Display',
'is_menu' => 'Отображать в меню',
];
}
public function getCategories()
{
return $this->hasMany(Category::className(), [ 'category_id' => 'category_id' ])
->viaTable('tax_group_to_category', [ 'tax_group_id' => 'tax_group_id' ]);
}
public function setCategories($values)
{
$this->categories = $values;
}
public function afterSave($insert, $changedAttributes)
{
$this->unlinkAll('categories', true);
$categories = [];
|
cc658b4c
Yarik
Big commit
|
125
|
if(!empty( $this->categories )) {
|
36d1807a
Yarik
Big commit.
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
$categories = Category::findAll($this->categories);
}
foreach($categories as $category) {
$this->link('categories', $category);
}
}
/**
* @return \yii\db\ActiveQuery
*/
public function getOptions()
{
return $this->getTaxOptions();
}
public function getTaxOptions()
{
return $this->hasMany(TaxOption::className(), [ 'tax_group_id' => 'tax_group_id' ])
->inverseOf('taxGroup');
|
d8c1a2e0
Yarik
Big commit artbox
|
145
|
}
|
d8c1a2e0
Yarik
Big commit artbox
|
146
|
}
|