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;
|
b519af22
Karnovsky A
Base-product func...
|
7
|
use common\modules\relation\relationBehavior;
|
85261b14
Karnovsky A
not fixed commite
|
8
9
10
11
12
13
14
15
16
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
|
use common\modules\rubrication\behaviors\ArtboxSynonymBehavior;
use Yii;
/**
* This is the model class for table "category".
*
* @property integer $category_id
* @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
|
44
|
'class' => RuSlug::className(),
|
85261b14
Karnovsky A
not fixed commite
|
45
46
47
48
49
50
51
52
53
54
55
56
|
'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...
|
57
58
59
60
|
],
[
'class' => relationBehavior::className(),
'relations' => [
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
61
62
|
'product_categories' => 'entity2', // Products of category
'tax_group_to_category' => 'entity2',
|
b519af22
Karnovsky A
Base-product func...
|
63
|
]
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
64
|
],
|
85261b14
Karnovsky A
not fixed commite
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
];
}
/**
* @inheritdoc
*/
public static function tableName()
{
return 'category';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
|
f57bf6b7
Karnovsky A
Some fixes
|
82
|
[['name'], 'string'],
|
85261b14
Karnovsky A
not fixed commite
|
83
84
|
[['parent_id', 'depth', 'category_name_id', 'product_unit_id'], 'integer'],
[['path', 'meta_desc', 'seo_text'], 'string'],
|
2583aa9d
Karnovsky A
Tmp disabled ajax...
|
85
|
[['meta_title'], 'string', 'max' => 255],
|
85261b14
Karnovsky A
not fixed commite
|
86
87
|
[['meta_robots'], 'string', 'max' => 50],
[['alias', 'name'], 'string', 'max' => 250],
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
88
89
|
[['populary'], 'boolean'],
[['group_to_category'], 'safe'],
|
14eadb86
Karnovsky A
Eager loading for...
|
90
|
[['category_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryName::className(), 'targetAttribute' => ['category_name_id' => 'category_name_id']],
|
2583aa9d
Karnovsky A
Tmp disabled ajax...
|
91
|
// [['image'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif'],
|
85261b14
Karnovsky A
not fixed commite
|
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
|
// [['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'),
];
}
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...
|
145
146
147
148
|
public function getTaxGroups() {
return $this->getRelations('tax_group_to_category');
}
|
85261b14
Karnovsky A
not fixed commite
|
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if (empty($this->parent_id))
$this->parent_id = 0;
return true;
}
return false;
}
public function getCategoryName() {
return $this->hasOne(CategoryName::className(), ['category_name_id' => 'category_name_id']);
}
|
9db1f47f
Karnovsky A
Add category.name...
|
164
165
166
|
public function getName() {
return empty($this->categoryName) ? null : $this->categoryName->value;
}
|
85261b14
Karnovsky A
not fixed commite
|
167
|
}
|