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