1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use Itstructure\AdminModule\models\{Language, ActiveRecord}; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* This is the model class for table "products_language". |
10
|
|
|
* |
11
|
|
|
* @property int $products_id |
12
|
|
|
* @property int $language_id |
13
|
|
|
* @property string $title |
14
|
|
|
* @property string $description |
15
|
|
|
* @property string $content |
16
|
|
|
* @property string $metaKeys |
17
|
|
|
* @property string $metaDescription |
18
|
|
|
* @property string $created_at |
19
|
|
|
* @property string $updated_at |
20
|
|
|
* |
21
|
|
|
* @property Language $language |
22
|
|
|
* @property Product $product |
23
|
|
|
* |
24
|
|
|
* @package app\models |
25
|
|
|
*/ |
26
|
|
View Code Duplication |
class ProductLanguage extends ActiveRecord |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public static function tableName() |
32
|
|
|
{ |
33
|
|
|
return 'products_language'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function rules() |
40
|
|
|
{ |
41
|
|
|
return [ |
42
|
|
|
[ |
43
|
|
|
[ |
44
|
|
|
'products_id', |
45
|
|
|
'language_id' |
46
|
|
|
], |
47
|
|
|
'required' |
48
|
|
|
], |
49
|
|
|
[ |
50
|
|
|
[ |
51
|
|
|
'products_id', |
52
|
|
|
'language_id' |
53
|
|
|
], |
54
|
|
|
'integer' |
55
|
|
|
], |
56
|
|
|
[ |
57
|
|
|
[ |
58
|
|
|
'description', |
59
|
|
|
'content' |
60
|
|
|
], |
61
|
|
|
'string' |
62
|
|
|
], |
63
|
|
|
[ |
64
|
|
|
[ |
65
|
|
|
'created_at', |
66
|
|
|
'updated_at' |
67
|
|
|
], |
68
|
|
|
'safe' |
69
|
|
|
], |
70
|
|
|
[ |
71
|
|
|
[ |
72
|
|
|
'title', |
73
|
|
|
'metaKeys', |
74
|
|
|
'metaDescription' |
75
|
|
|
], |
76
|
|
|
'string', |
77
|
|
|
'max' => 255 |
78
|
|
|
], |
79
|
|
|
[ |
80
|
|
|
[ |
81
|
|
|
'products_id', |
82
|
|
|
'language_id' |
83
|
|
|
], |
84
|
|
|
'unique', |
85
|
|
|
'targetAttribute' => ['products_id', 'language_id'] |
86
|
|
|
], |
87
|
|
|
[ |
88
|
|
|
[ |
89
|
|
|
'language_id' |
90
|
|
|
], |
91
|
|
|
'exist', |
92
|
|
|
'skipOnError' => true, |
93
|
|
|
'targetClass' => Language::class, |
94
|
|
|
'targetAttribute' => ['language_id' => 'id'] |
95
|
|
|
], |
96
|
|
|
[ |
97
|
|
|
[ |
98
|
|
|
'products_id' |
99
|
|
|
], |
100
|
|
|
'exist', |
101
|
|
|
'skipOnError' => true, |
102
|
|
|
'targetClass' => Product::class, |
103
|
|
|
'targetAttribute' => ['products_id' => 'id'] |
104
|
|
|
], |
105
|
|
|
]; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
|
|
public function attributeLabels() |
112
|
|
|
{ |
113
|
|
|
return [ |
114
|
|
|
'products_id' => 'Products ID', |
115
|
|
|
'language_id' => 'Language ID', |
116
|
|
|
'title' => Yii::t('app', 'Title'), |
117
|
|
|
'description' => Yii::t('app', 'Description'), |
118
|
|
|
'content' => Yii::t('app', 'Content'), |
119
|
|
|
'metaKeys' => Yii::t('app', 'Meta keys'), |
120
|
|
|
'metaDescription' => Yii::t('app', 'Meta description'), |
121
|
|
|
'created_at' => Yii::t('app', 'Created date'), |
122
|
|
|
'updated_at' => Yii::t('app', 'Updated date'), |
123
|
|
|
]; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return \yii\db\ActiveQuery |
128
|
|
|
*/ |
129
|
|
|
public function getLanguage() |
130
|
|
|
{ |
131
|
|
|
return $this->hasOne(Language::class, [ |
132
|
|
|
'id' => 'language_id' |
133
|
|
|
]); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return \yii\db\ActiveQuery |
138
|
|
|
*/ |
139
|
|
|
public function getProduct() |
140
|
|
|
{ |
141
|
|
|
return $this->hasOne(Product::class, [ |
142
|
|
|
'id' => 'products_id' |
143
|
|
|
]); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.