d8c1a2e0
Yarik
Big commit artbox
|
1
|
<?php
|
af036678
Yarik
Image behaviors
|
2
3
4
5
6
|
namespace common\modules\product\models;
use common\behaviors\ImageBehavior;
use Yii;
|
5c2eb7c8
Yarik
Big commit almost...
|
7
|
use yii\db\ActiveRecord;
|
af036678
Yarik
Image behaviors
|
8
|
|
d8c1a2e0
Yarik
Big commit artbox
|
9
|
/**
|
af036678
Yarik
Image behaviors
|
10
|
* This is the model class for table "product_image".
|
4428da8c
Yarik
Almost all databa...
|
11
|
*
|
772a3ca4
Yarik
Big commit
|
12
|
* @property integer $id
|
af036678
Yarik
Image behaviors
|
13
14
15
16
17
18
19
|
* @property integer $product_id
* @property integer $product_variant_id
* @property string $image
* @property string $alt
* @property string $title
* @property Product $product
* @property ProductVariant $productVariant
|
d8c1a2e0
Yarik
Big commit artbox
|
20
|
*/
|
5c2eb7c8
Yarik
Big commit almost...
|
21
|
class ProductImage extends ActiveRecord
|
d8c1a2e0
Yarik
Big commit artbox
|
22
|
{
|
af036678
Yarik
Image behaviors
|
23
24
25
26
27
28
29
|
/**
* @inheritdoc
*/
public static function tableName()
{
return 'product_image';
|
d8c1a2e0
Yarik
Big commit artbox
|
30
|
}
|
af036678
Yarik
Image behaviors
|
31
32
33
34
35
36
37
38
39
40
|
public function behaviors()
{
return [
[
'class' => ImageBehavior::className(),
'link' => 'image',
'directory' => 'products',
],
];
|
d8c1a2e0
Yarik
Big commit artbox
|
41
|
}
|
af036678
Yarik
Image behaviors
|
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[ 'product_id' ],
'required',
],
[
[
|
772a3ca4
Yarik
Big commit
|
55
|
'id',
|
af036678
Yarik
Image behaviors
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
'product_id',
'product_variant_id',
],
'integer',
],
[
[
'alt',
'title',
'image',
],
'string',
'max' => 255,
],
[
[ 'product_id' ],
'exist',
'skipOnError' => true,
'targetClass' => Product::className(),
|
8af13427
Yarik
For leha commit.
|
75
|
'targetAttribute' => [ 'product_id' => 'id' ],
|
af036678
Yarik
Image behaviors
|
76
77
78
79
80
81
|
],
[
[ 'product_variant_id' ],
'exist',
'skipOnError' => true,
'targetClass' => ProductVariant::className(),
|
4428da8c
Yarik
Almost all databa...
|
82
|
'targetAttribute' => [ 'product_variant_id' => 'id' ],
|
af036678
Yarik
Image behaviors
|
83
84
85
86
87
88
89
90
91
92
|
],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
|
772a3ca4
Yarik
Big commit
|
93
|
'id' => Yii::t('product', 'Product Image ID'),
|
af036678
Yarik
Image behaviors
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
'product_id' => Yii::t('product', 'Product ID'),
'product_variant_id' => Yii::t('product', 'Product Variant ID'),
'product' => Yii::t('product', 'Product'),
'product_variant' => Yii::t('product', 'Product Variant'),
'image' => Yii::t('product', 'Image'),
'alt' => Yii::t('product', 'Alt'),
'title' => Yii::t('product', 'Title'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProduct()
{
|
8af13427
Yarik
For leha commit.
|
109
|
$return = $this->hasOne(Product::className(), [ 'id' => 'product_id' ]);
|
af036678
Yarik
Image behaviors
|
110
|
return $return;
|
d8c1a2e0
Yarik
Big commit artbox
|
111
|
}
|
af036678
Yarik
Image behaviors
|
112
113
114
115
116
117
|
/**
* @return \yii\db\ActiveQuery
*/
public function getProductVariant()
{
|
4428da8c
Yarik
Almost all databa...
|
118
|
return $this->hasOne(ProductVariant::className(), [ 'id' => 'product_variant_id' ]);
|
d8c1a2e0
Yarik
Big commit artbox
|
119
|
}
|
d8c1a2e0
Yarik
Big commit artbox
|
120
|
}
|