85261b14
Karnovsky A
not fixed commite
|
1
2
3
4
|
<?php
namespace common\modules\product\models;
|
ba008812
Administrator
31.03.16 finish 1
|
5
|
use common\behaviors\RuSlug;
|
85261b14
Karnovsky A
not fixed commite
|
6
|
use common\components\artboxtree\ArtboxTreeBehavior;
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
7
|
use common\components\artboxtree\ArtboxTreeHelper;
|
b519af22
Karnovsky A
Base-product func...
|
8
|
use common\modules\relation\relationBehavior;
|
85261b14
Karnovsky A
not fixed commite
|
9
10
11
12
13
14
15
|
use common\modules\rubrication\behaviors\ArtboxSynonymBehavior;
use Yii;
/**
* This is the model class for table "category".
*
* @property integer $category_id
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
16
|
* @property string $remote_id
|
85261b14
Karnovsky A
not fixed commite
|
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
|
* @property integer $parent_id
* @property string $path
* @property integer $depth
* @property string $image
* @property string $meta_title
* @property string $meta_desc
* @property string $meta_robots
* @property string $seo_text
* @property integer $category_name_id
* @property integer $product_unit_id
* @property string $alias
* @property boolean $populary
*
* @property CategoryName $categoryName
* @property ProductUnit $productUnit
* @property CategoryName[] $categoryNames
* @property ProductCategory[] $productCategories
*/
class Category extends \yii\db\ActiveRecord
{
public function behaviors()
{
return [
'artboxtree' => [
'class' => ArtboxTreeBehavior::className(),
'keyNameGroup' => null,
'keyNamePath' => 'path',
],
'slug' => [
|
ba008812
Administrator
31.03.16 finish 1
|
46
|
'class' => RuSlug::className(),
|
85261b14
Karnovsky A
not fixed commite
|
47
48
49
50
51
52
53
54
55
56
57
58
|
'in_attribute' => 'name',
'out_attribute' => 'alias',
'translit' => true
],
'artboxsynonym' => [
'class' => ArtboxSynonymBehavior::className(),
'keyNameValue' => 'category_name_id',
'valueModel' => CategoryName::className(),
'valueOptionId' => 'category_id',
'valueFields' => [ // postKey => DBFieldName
'name' => 'value'
]
|
b519af22
Karnovsky A
Base-product func...
|
59
60
61
62
|
],
[
'class' => relationBehavior::className(),
'relations' => [
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
63
64
|
'product_categories' => 'entity2', // Products of category
'tax_group_to_category' => 'entity2',
|
b519af22
Karnovsky A
Base-product func...
|
65
|
]
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
66
|
],
|
85261b14
Karnovsky A
not fixed commite
|
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
];
}
/**
* @inheritdoc
*/
public static function tableName()
{
return 'category';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
|
f57bf6b7
Karnovsky A
Some fixes
|
84
|
[['name'], 'string'],
|
85261b14
Karnovsky A
not fixed commite
|
85
86
|
[['parent_id', 'depth', 'category_name_id', 'product_unit_id'], 'integer'],
[['path', 'meta_desc', 'seo_text'], 'string'],
|
2583aa9d
Karnovsky A
Tmp disabled ajax...
|
87
|
[['meta_title'], 'string', 'max' => 255],
|
85261b14
Karnovsky A
not fixed commite
|
88
89
|
[['meta_robots'], 'string', 'max' => 50],
[['alias', 'name'], 'string', 'max' => 250],
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
90
|
[['populary'], 'boolean'],
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
91
|
[['group_to_category', 'remote_category'], 'safe'],
|
14eadb86
Karnovsky A
Eager loading for...
|
92
|
[['category_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryName::className(), 'targetAttribute' => ['category_name_id' => 'category_name_id']],
|
2583aa9d
Karnovsky A
Tmp disabled ajax...
|
93
|
// [['image'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif'],
|
85261b14
Karnovsky A
not fixed commite
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
// [['product_unit_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductUnit::className(), 'targetAttribute' => ['product_unit_id' => 'product_unit_id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'category_id' => Yii::t('product', 'Category ID'),
'parent_id' => Yii::t('product', 'Parent ID'),
'path' => Yii::t('product', 'Path'),
'depth' => Yii::t('product', 'Depth'),
'image' => Yii::t('product', 'Image'),
'meta_title' => Yii::t('product', 'Meta Title'),
'meta_desc' => Yii::t('product', 'Meta Desc'),
'meta_robots' => Yii::t('product', 'Meta Robots'),
'seo_text' => Yii::t('product', 'Seo Text'),
'product_unit_id' => Yii::t('product', 'Product Unit ID'),
'alias' => Yii::t('product', 'Alias'),
'populary' => Yii::t('product', 'Populary'),
|
bce22e8a
Karnovsky A
Some refixes
|
116
|
'name' => Yii::t('product', 'Name'),
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
117
|
'remote_id' => Yii::t('product', 'Remote ID'),
|
85261b14
Karnovsky A
not fixed commite
|
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
|
];
}
public static function find() {
return new CategoryQuery(get_called_class());
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductUnit()
{
return $this->hasOne(ProductUnit::className(), ['product_unit_id' => 'product_unit_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCategoryNames()
{
return $this->hasMany(CategoryName::className(), ['category_id' => 'category_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductCategories()
{
return $this->hasMany(ProductCategory::className(), ['category_id' => 'category_id']);
}
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
149
150
151
152
|
public function getTaxGroups() {
return $this->getRelations('tax_group_to_category');
}
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
153
154
155
|
public function getRemote_category() {
return ArtboxTreeHelper::getArrayField($this->remote_id);
}
|
85261b14
Karnovsky A
not fixed commite
|
156
|
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
157
158
159
|
public function setRemote_category($value) {
if (!empty($value) && is_array($value)) {
$this->remote_id = ArtboxTreeHelper::setArrayField($value, false);
|
85261b14
Karnovsky A
not fixed commite
|
160
|
}
|
85261b14
Karnovsky A
not fixed commite
|
161
162
163
164
165
166
|
}
public function getCategoryName() {
return $this->hasOne(CategoryName::className(), ['category_name_id' => 'category_name_id']);
}
|
9db1f47f
Karnovsky A
Add category.name...
|
167
168
169
|
public function getName() {
return empty($this->categoryName) ? null : $this->categoryName->value;
}
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
170
171
172
173
174
175
176
177
178
179
180
181
|
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if (empty($this->parent_id))
$this->parent_id = 0;
return true;
}
return false;
}
|
85261b14
Karnovsky A
not fixed commite
|
182
|
}
|