1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace roaresearch\yii2\formgenerator\roa\models; |
4
|
|
|
|
5
|
|
|
use yii\{base\Model, data\ActiveDataProvider}; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Contract to filter and sort collections of `SolicitudeValue` records. |
9
|
|
|
* |
10
|
|
|
* Unlike `SolicitudeValueSearch` this class doesnt invoke the parent |
11
|
|
|
* `Solicitude` record so it can search `SolicitudeValue` records across |
12
|
|
|
* different `Solicitude` records. |
13
|
|
|
* |
14
|
|
|
* @author Angel (Faryshta) Guevara <[email protected]> |
15
|
|
|
* |
16
|
|
|
* @property int $form_id |
17
|
|
|
*/ |
18
|
|
|
class SolicitudeValueSimpleSearch extends SolicitudeValue implements |
19
|
|
|
\roaresearch\yii2\roa\ResourceSearch |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @inhertidoc |
23
|
|
|
*/ |
24
|
1 |
|
protected function slugBehaviorConfig(): array |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
1 |
|
'idAttribute' => [], |
28
|
|
|
'parentSlugRelation' => null, |
29
|
|
|
'resourceName' => 'solicitude-value', |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inhertidoc |
35
|
|
|
*/ |
36
|
1 |
|
public function attributes() |
37
|
|
|
{ |
38
|
1 |
|
return array_merge(parent::attributes(), ['form_id']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inhertidoc |
43
|
|
|
*/ |
44
|
1 |
|
public function rules() |
45
|
|
|
{ |
46
|
|
|
return [ |
47
|
1 |
|
[['form_id', 'solicitude_id', 'section_id', 'field_id'], 'integer'], |
48
|
|
|
[['value'], 'safe'], |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inhertidoc |
54
|
|
|
*/ |
55
|
1 |
|
public function search( |
56
|
|
|
array $params, |
57
|
|
|
?string $formName = '' |
58
|
|
|
): ?ActiveDataProvider { |
59
|
1 |
|
$this->load($params, $formName); |
60
|
1 |
|
if (!$this->validate()) { |
61
|
1 |
|
return null; |
62
|
|
|
} |
63
|
1 |
|
$this->checkAccess($params); |
|
|
|
|
64
|
1 |
|
$class = get_parent_class(); |
65
|
|
|
|
66
|
1 |
|
return new ActiveDataProvider([ |
67
|
1 |
|
'query' => $class::find()->innerJoinWith(['solicitude']) |
68
|
1 |
|
->andFilterWhere([ |
69
|
1 |
|
'form_id' => $this->form_id, |
70
|
1 |
|
'solicitude_id' => $this->solicitude_id, |
71
|
1 |
|
'section_id' => $this->section_id, |
72
|
1 |
|
'field_id' => $this->field_id, |
73
|
1 |
|
])->andFilterWhere(['like', 'value', $this->value]) |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inhertidoc |
79
|
|
|
*/ |
80
|
1 |
|
public function afterValidate() |
81
|
|
|
{ |
82
|
1 |
|
Model::afterValidate(); |
83
|
1 |
|
} |
84
|
|
|
} |
85
|
|
|
|