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
|
* @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
{
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
37
38
|
public $imageUpload;
|
85261b14
Karnovsky A
not fixed commite
|
39
40
41
42
43
44
45
46
|
public function behaviors()
{
return [
'artboxtree' => [
'class' => ArtboxTreeBehavior::className(),
'keyNameGroup' => null,
'keyNamePath' => 'path',
],
|
85261b14
Karnovsky A
not fixed commite
|
47
48
49
50
51
52
53
|
'artboxsynonym' => [
'class' => ArtboxSynonymBehavior::className(),
'keyNameValue' => 'category_name_id',
'valueModel' => CategoryName::className(),
'valueOptionId' => 'category_id',
'valueFields' => [ // postKey => DBFieldName
'name' => 'value'
|
0b8441f2
Karnovsky A
Karnovsky-02052016
|
54
55
56
57
58
|
],
'slug' => [
'valueKeyName' => 'value',
'slugKeyName' => 'alias',
'translit' => true
|
85261b14
Karnovsky A
not fixed commite
|
59
|
]
|
b519af22
Karnovsky A
Base-product func...
|
60
61
62
63
|
],
[
'class' => relationBehavior::className(),
'relations' => [
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
64
65
|
'product_categories' => 'entity2', // Products of category
'tax_group_to_category' => 'entity2',
|
b519af22
Karnovsky A
Base-product func...
|
66
|
]
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
67
|
],
|
85261b14
Karnovsky A
not fixed commite
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
];
}
/**
* @inheritdoc
*/
public static function tableName()
{
return 'category';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
|
f57bf6b7
Karnovsky A
Some fixes
|
85
|
[['name'], 'string'],
|
85261b14
Karnovsky A
not fixed commite
|
86
87
|
[['parent_id', 'depth', 'category_name_id', 'product_unit_id'], 'integer'],
[['path', 'meta_desc', 'seo_text'], 'string'],
|
2583aa9d
Karnovsky A
Tmp disabled ajax...
|
88
|
[['meta_title'], 'string', 'max' => 255],
|
85261b14
Karnovsky A
not fixed commite
|
89
90
|
[['meta_robots'], 'string', 'max' => 50],
[['alias', 'name'], 'string', 'max' => 250],
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
91
|
[['populary'], 'boolean'],
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
92
|
[['group_to_category', 'remote_category'], 'safe'],
|
14eadb86
Karnovsky A
Eager loading for...
|
93
|
[['category_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryName::className(), 'targetAttribute' => ['category_name_id' => 'category_name_id']],
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
94
95
|
[['imageUpload'], 'safe'],
[['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'],
|
85261b14
Karnovsky A
not fixed commite
|
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// [['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'),
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
111
|
'imageUrl' => Yii::t('product', 'Image'),
|
85261b14
Karnovsky A
not fixed commite
|
112
113
114
115
116
117
118
|
'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
|
119
|
'name' => Yii::t('product', 'Name'),
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
120
|
'remote_id' => Yii::t('product', 'Remote ID'),
|
85261b14
Karnovsky A
not fixed commite
|
121
122
123
|
];
}
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
124
125
|
public static function find()
{
|
85261b14
Karnovsky A
not fixed commite
|
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
|
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']);
}
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
153
154
|
public function getTaxGroups()
{
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
155
156
157
|
return $this->getRelations('tax_group_to_category');
}
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
158
159
|
public function getRemote_category()
{
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
160
161
|
return ArtboxTreeHelper::getArrayField($this->remote_id);
}
|
85261b14
Karnovsky A
not fixed commite
|
162
|
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
163
164
|
public function setRemote_category($value)
{
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
165
166
|
if (!empty($value) && is_array($value)) {
$this->remote_id = ArtboxTreeHelper::setArrayField($value, false);
|
85261b14
Karnovsky A
not fixed commite
|
167
|
}
|
85261b14
Karnovsky A
not fixed commite
|
168
169
|
}
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
170
171
|
public function getCategoryName()
{
|
85261b14
Karnovsky A
not fixed commite
|
172
173
174
|
return $this->hasOne(CategoryName::className(), ['category_name_id' => 'category_name_id']);
}
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
175
176
|
public function getName()
{
|
9db1f47f
Karnovsky A
Add category.name...
|
177
178
|
return empty($this->categoryName) ? null : $this->categoryName->value;
}
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
179
|
|
1f90c5f4
Karnovsky A
ArtboxImage resizer
|
180
181
182
183
|
public function getImageFile() {
return empty($this->image) ? null : Yii::getAlias('@storage/category/'. $this->image);
}
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
184
185
|
public function getImageUrl()
{
|
1f90c5f4
Karnovsky A
ArtboxImage resizer
|
186
|
return empty($this->image) ? null : '/storage/category/' . $this->image;
|
550f051a
Karnovsky A
Karnovsky-0505201...
|
187
188
|
}
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
189
190
191
192
193
194
195
196
197
198
199
|
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
|
200
|
}
|