1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace roaresearch\yii2\formgenerator\models; |
4
|
|
|
|
5
|
|
|
use yii\db\ActiveQuery; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Model class for table `{{%formgenerator_solicitude}}` |
9
|
|
|
* |
10
|
|
|
* @property integer $id |
11
|
|
|
* @property integer $form_id |
12
|
|
|
* @property string $label |
13
|
|
|
* |
14
|
|
|
* @property Form $form |
15
|
|
|
* @property SolicitudeValue $values |
16
|
|
|
*/ |
17
|
|
|
class Solicitude extends \roaresearch\yii2\rmdb\models\Entity |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string full class name of the model used in the relation |
21
|
|
|
* `getForm()`. |
22
|
|
|
*/ |
23
|
|
|
protected $formClass = Form::class; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string full class name of the model used in the relation |
27
|
|
|
* `getSolicitudeValues()`. |
28
|
|
|
*/ |
29
|
|
|
protected $solicitudeValueClass = SolicitudeValue::class; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @inheritdoc |
33
|
|
|
*/ |
34
|
14 |
|
public static function tableName() |
35
|
|
|
{ |
36
|
14 |
|
return '{{%formgenerator_solicitude}}'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritdoc |
41
|
|
|
*/ |
42
|
11 |
|
protected function attributeTypecast(): array |
43
|
|
|
{ |
44
|
11 |
|
return parent::attributeTypecast() + [ |
45
|
11 |
|
'id' => 'integer', |
46
|
|
|
'form_id' => 'integer', |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
*/ |
53
|
2 |
|
public function rules() |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
2 |
|
[['form_id'], 'required'], |
57
|
|
|
[['form_id'], 'integer'], |
58
|
|
|
[ |
59
|
|
|
['form_id'], |
60
|
|
|
'exist', |
61
|
|
|
'skipOnError' => true, |
62
|
|
|
'targetClass' => Form::class, |
63
|
|
|
'targetAttribute' => ['form_id' => 'id'], |
64
|
|
|
], |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @inheritdoc |
70
|
|
|
*/ |
71
|
2 |
|
public function attributeLabels() |
72
|
|
|
{ |
73
|
2 |
|
return array_merge([ |
74
|
2 |
|
'id' => 'ID', |
75
|
|
|
'form_id' => 'Form ID', |
76
|
2 |
|
], parent::attributeLabels()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return ActiveQuery |
81
|
|
|
*/ |
82
|
11 |
|
public function getForm(): ActiveQuery |
83
|
|
|
{ |
84
|
11 |
|
return $this->hasOne($this->formClass, ['id' => 'form_id']); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return ActiveQuery |
89
|
|
|
*/ |
90
|
|
|
public function getValues(): ActiveQuery |
91
|
|
|
{ |
92
|
|
|
return $this->hasMany( |
93
|
|
|
$this->solicitudeValueClass, |
94
|
|
|
['solicitude_id' => 'id'] |
95
|
|
|
)->inverseOf('solicitude'); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|