|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\models; |
|
4
|
|
|
|
|
5
|
|
|
use Itstructure\AdminModule\models\{MultilanguageTrait, Language}; |
|
6
|
|
|
use Itstructure\AdminModule\interfaces\ModelInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* This is the model class for table "qualities". |
|
10
|
|
|
* |
|
11
|
|
|
* @property int $id |
|
12
|
|
|
* @property string $icon |
|
13
|
|
|
* @property string $created_at |
|
14
|
|
|
* @property string $updated_at |
|
15
|
|
|
* |
|
16
|
|
|
* @property AboutQuality[] $aboutQualities |
|
17
|
|
|
* @property About[] $about |
|
18
|
|
|
* @property QualityLanguage[] $qualitiesLanguages |
|
19
|
|
|
* @property Language[] $languages |
|
20
|
|
|
*/ |
|
21
|
|
|
class QualityBase extends ActiveRecord |
|
22
|
|
|
{ |
|
23
|
|
|
use MultilanguageTrait; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public static function tableName() |
|
29
|
|
|
{ |
|
30
|
|
|
return 'qualities'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function rules() |
|
37
|
|
|
{ |
|
38
|
|
|
return [ |
|
39
|
|
|
[ |
|
40
|
|
|
[ |
|
41
|
|
|
'icon', |
|
42
|
|
|
'about' |
|
43
|
|
|
], |
|
44
|
|
|
'required' |
|
45
|
|
|
], |
|
46
|
|
|
[ |
|
47
|
|
|
[ |
|
48
|
|
|
'created_at', |
|
49
|
|
|
'updated_at' |
|
50
|
|
|
], |
|
51
|
|
|
'safe' |
|
52
|
|
|
], |
|
53
|
|
|
[ |
|
54
|
|
|
[ |
|
55
|
|
|
'icon' |
|
56
|
|
|
], |
|
57
|
|
|
'string', |
|
58
|
|
|
'max' => 64 |
|
59
|
|
|
] |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* List if attributes. |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public function attributes() |
|
69
|
|
|
{ |
|
70
|
|
|
return [ |
|
71
|
|
|
'id', |
|
72
|
|
|
'icon', |
|
73
|
|
|
'created_at', |
|
74
|
|
|
'updated_at', |
|
75
|
|
|
]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return array |
|
80
|
|
|
*/ |
|
81
|
|
|
public function mainModelAttributes() |
|
82
|
|
|
{ |
|
83
|
|
|
return [ |
|
84
|
|
|
'id', |
|
85
|
|
|
'icon', |
|
86
|
|
|
'about', |
|
87
|
|
|
'created_at', |
|
88
|
|
|
'updated_at', |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
|
|
public function scenarios() |
|
96
|
|
|
{ |
|
97
|
|
|
$scenarios = parent::scenarios(); |
|
98
|
|
|
|
|
99
|
|
|
$scenarios[ModelInterface::SCENARIO_CREATE][] = 'about'; |
|
100
|
|
|
$scenarios[ModelInterface::SCENARIO_UPDATE][] = 'about'; |
|
101
|
|
|
|
|
102
|
|
|
return $scenarios; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* {@inheritdoc} |
|
107
|
|
|
*/ |
|
108
|
|
|
public function attributeLabels() |
|
109
|
|
|
{ |
|
110
|
|
|
return [ |
|
111
|
|
|
'id' => 'ID', |
|
112
|
|
|
'icon' => 'Icon', |
|
113
|
|
|
'created_at' => 'Created At', |
|
114
|
|
|
'updated_at' => 'Updated At', |
|
115
|
|
|
]; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return \yii\db\ActiveQuery |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getAboutQualities() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->hasMany(AboutQuality::class, [ |
|
124
|
|
|
'qualities_id' => 'id' |
|
125
|
|
|
]); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return \yii\db\ActiveQuery |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getAbout() |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->hasMany(About::class, [ |
|
134
|
|
|
'id' => 'about_id' |
|
135
|
|
|
])->viaTable('about_qualities', [ |
|
136
|
|
|
'qualities_id' => 'id' |
|
137
|
|
|
]); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param $about |
|
142
|
|
|
* |
|
143
|
|
|
* @return void |
|
144
|
|
|
*/ |
|
145
|
|
|
public function setAbout($about): void |
|
146
|
|
|
{ |
|
147
|
|
|
$this->about = $about; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return \yii\db\ActiveQuery |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getQualitiesLanguages() |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->hasMany(QualityLanguage::class, [ |
|
156
|
|
|
'qualities_id' => 'id' |
|
157
|
|
|
]); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return \yii\db\ActiveQuery |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getLanguages() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->hasMany(Language::class, [ |
|
166
|
|
|
'id' => 'language_id' |
|
167
|
|
|
])->viaTable('qualities_language', [ |
|
168
|
|
|
'qualities_id' => 'id' |
|
169
|
|
|
]); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Link with about entity. |
|
174
|
|
|
* |
|
175
|
|
|
* @param array $aboutList |
|
176
|
|
|
*/ |
|
177
|
|
|
protected function linkWithAbout(array $aboutList): void |
|
178
|
|
|
{ |
|
179
|
|
|
AboutQuality::deleteAll([ |
|
180
|
|
|
'qualities_id' => $this->id |
|
181
|
|
|
]); |
|
182
|
|
|
|
|
183
|
|
|
foreach ($aboutList as $aboutId) { |
|
184
|
|
|
$aboutQuality = new AboutQuality(); |
|
185
|
|
|
$aboutQuality->qualities_id = $this->id; |
|
186
|
|
|
$aboutQuality->about_id = $aboutId; |
|
187
|
|
|
$aboutQuality->save(); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|