1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace roaresearch\yii2\formgenerator\models; |
4
|
|
|
|
5
|
|
|
use yii\db\ActiveQuery; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Model class for table `{{%formgenerator_solicitude_value}}` |
9
|
|
|
* |
10
|
|
|
* @property integer $section_id |
11
|
|
|
* @property integer $field_id |
12
|
|
|
* @property integer $solicitude_id |
13
|
|
|
* @property string $value |
14
|
|
|
* |
15
|
|
|
* @property SectionField $sectionField |
16
|
|
|
* @property Section $section |
17
|
|
|
* @property Field $field |
18
|
|
|
* @property Solicitude $solicitude |
19
|
|
|
*/ |
20
|
|
|
class SolicitudeValue extends \roaresearch\yii2\rmdb\models\Entity |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string full class name of the model used in the relation |
24
|
|
|
* `getSectionField()`. |
25
|
|
|
*/ |
26
|
|
|
protected $sectionFieldClass = SectionField::class; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string full class name of the model used in the relation |
30
|
|
|
* `getSection()`. |
31
|
|
|
*/ |
32
|
|
|
protected $sectionClass = Section::class; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string full class name of the model used in the relation |
36
|
|
|
* `getField()`. |
37
|
|
|
*/ |
38
|
|
|
protected $fieldClass = Field::class; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string full class name of the model used in the relation |
42
|
|
|
* `getSolicitude()`. |
43
|
|
|
*/ |
44
|
|
|
protected $solicitudeClass = Solicitude::class; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritdoc |
48
|
|
|
*/ |
49
|
10 |
|
public static function tableName() |
50
|
|
|
{ |
51
|
10 |
|
return '{{%formgenerator_solicitude_value}}'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritdoc |
56
|
|
|
*/ |
57
|
6 |
|
protected function attributeTypecast(): array |
58
|
|
|
{ |
59
|
6 |
|
return parent::attributeTypecast() + [ |
60
|
6 |
|
'section_id' => 'integer', |
61
|
|
|
'field_id' => 'integer', |
62
|
|
|
'solicitude_id' => 'integer', |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @inheritdoc |
68
|
|
|
*/ |
69
|
2 |
|
public function rules() |
70
|
|
|
{ |
71
|
|
|
return [ |
72
|
2 |
|
[['section_id', 'field_id', 'solicitude_id'], 'required'], |
73
|
|
|
[['section_id', 'field_id', 'solicitude_id'], 'integer'], |
74
|
|
|
[ |
75
|
|
|
['solicitude_id'], |
76
|
|
|
'exist', |
77
|
|
|
'skipOnError' => true, |
78
|
|
|
'targetClass' => Solicitude::class, |
79
|
|
|
'targetAttribute' => ['solicitude_id' => 'id'], |
80
|
|
|
], |
81
|
|
|
[ |
82
|
|
|
['section_id'], |
83
|
2 |
|
'exist', |
84
|
|
|
'skipOnError' => true, |
85
|
|
|
'targetClass' => Section::class, |
86
|
|
|
'targetAttribute' => ['section_id' => 'id'], |
87
|
2 |
|
'when' => function () { |
88
|
2 |
|
return !$this->hasErrors('solicitude_id'); |
89
|
2 |
|
}, |
90
|
2 |
|
'filter' => function ($query) { |
91
|
2 |
|
$query->andWhere(['form_id' => $this->solicitude->form_id]); |
92
|
2 |
|
}, |
93
|
2 |
|
'message' => 'Section is not associated to the form.', |
94
|
|
|
], |
95
|
|
|
[ |
96
|
|
|
['field_id'], |
97
|
2 |
|
'exist', |
98
|
|
|
'skipOnError' => true, |
99
|
|
|
'targetClass' => SectionField::class, |
100
|
|
|
'targetAttribute' => [ |
101
|
|
|
'section_id' => 'section_id', |
102
|
|
|
'field_id' => 'field_id', |
103
|
|
|
], |
104
|
2 |
|
'when' => function () { |
105
|
2 |
|
return !$this->hasErrors('section_id'); |
106
|
2 |
|
}, |
107
|
2 |
|
'message' => 'Field not associated to the Section.', |
108
|
|
|
], |
109
|
|
|
[ |
110
|
|
|
['field_id'], |
111
|
2 |
|
'unique', |
112
|
|
|
'targetAttribute' => [ |
113
|
|
|
'section_id', |
114
|
|
|
'field_id', |
115
|
|
|
'solicitude_id', |
116
|
|
|
], |
117
|
2 |
|
'when' => function () { |
118
|
2 |
|
return !$this->hasErrors('section_id') |
119
|
2 |
|
&& !$this->hasErrors('solicitude_id'); |
120
|
2 |
|
}, |
121
|
2 |
|
'message' => 'Field already filled.', |
122
|
|
|
], |
123
|
|
|
[['value'], 'trim'], |
124
|
|
|
]; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @inheritdoc |
129
|
|
|
*/ |
130
|
2 |
|
public function afterValidate() |
131
|
|
|
{ |
132
|
2 |
|
if (!$this->hasErrors()) { |
133
|
2 |
|
$field = $this->getField() |
134
|
2 |
|
->with([ |
135
|
2 |
|
'dataType', |
136
|
2 |
|
'rules' => function ($query) { |
137
|
2 |
|
$query->modelClass = FieldRule::class; |
138
|
2 |
|
}, |
139
|
2 |
|
'rules.properties', |
140
|
|
|
]) |
141
|
2 |
|
->one(); |
142
|
2 |
|
$this->populateRelation('field', $field); |
143
|
2 |
|
foreach ( |
144
|
|
|
$field->buildValidators($this, 'value') as $validator |
145
|
|
|
) { |
146
|
2 |
|
$validator->validateAttributes($this, ['value']); |
147
|
|
|
} |
148
|
2 |
|
$field->dataType->castValue($this, 'value'); |
|
|
|
|
149
|
|
|
} |
150
|
2 |
|
parent::afterValidate(); |
151
|
2 |
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @inheritdoc |
155
|
|
|
*/ |
156
|
5 |
|
public function attributeLabels() |
157
|
|
|
{ |
158
|
5 |
|
return array_merge([ |
159
|
5 |
|
'section_id' => 'Section ID', |
160
|
|
|
'field_id' => 'Field ID', |
161
|
|
|
'label' => 'label', |
162
|
5 |
|
], parent::attributeLabels()); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return ActiveQuery |
167
|
|
|
*/ |
168
|
|
|
public function getSectionField(): ActiveQuery |
169
|
|
|
{ |
170
|
|
|
return $this->hasOne( |
171
|
|
|
$this->sectionFieldClass, |
172
|
|
|
['section_id' => 'section_id', 'field_id' => 'field_id'] |
173
|
|
|
); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return ActiveQuery |
178
|
|
|
*/ |
179
|
5 |
|
public function getSection(): ActiveQuery |
180
|
|
|
{ |
181
|
5 |
|
return $this->hasOne($this->sectionClass, ['id' => 'section_id']); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return ActiveQuery |
186
|
|
|
*/ |
187
|
5 |
|
public function getField(): ActiveQuery |
188
|
|
|
{ |
189
|
5 |
|
return $this->hasOne($this->fieldClass, ['id' => 'field_id']); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return ActiveQuery |
194
|
|
|
*/ |
195
|
6 |
|
public function getSolicitude(): ActiveQuery |
196
|
|
|
{ |
197
|
6 |
|
return $this->hasOne($this->solicitudeClass, ['id' => 'solicitude_id']); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.