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
|
|
|
class SolicitudeValueSimpleSearch extends SolicitudeValue implements |
17
|
|
|
\roaresearch\yii2\roa\ResourceSearch |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @inhertidoc |
21
|
|
|
*/ |
22
|
|
|
protected function slugBehaviorConfig(): array |
23
|
1 |
|
{ |
24
|
|
|
return [ |
25
|
|
|
'idAttribute' => [], |
26
|
1 |
|
'parentSlugRelation' => null, |
27
|
|
|
'resourceName' => 'solicitude-value', |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @inhertidoc |
33
|
|
|
*/ |
34
|
|
|
public function attributes() |
35
|
1 |
|
{ |
36
|
|
|
return array_merge(parent::attributes(), ['form_id']); |
37
|
1 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inhertidoc |
41
|
|
|
*/ |
42
|
|
|
public function rules() |
43
|
1 |
|
{ |
44
|
|
|
return [ |
45
|
|
|
[['form_id', 'solicitude_id', 'section_id', 'field_id'], 'integer'], |
46
|
1 |
|
[['value'], 'safe'], |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inhertidoc |
52
|
|
|
*/ |
53
|
|
|
public function search( |
54
|
1 |
|
array $params, |
55
|
|
|
?string $formName = '' |
56
|
|
|
): ?ActiveDataProvider { |
57
|
|
|
$this->load($params, $formName); |
58
|
1 |
|
if (!$this->validate()) { |
59
|
1 |
|
return null; |
60
|
1 |
|
} |
61
|
|
|
$this->checkAccess($params); |
|
|
|
|
62
|
1 |
|
$class = get_parent_class(); |
63
|
1 |
|
|
64
|
|
|
return new ActiveDataProvider([ |
65
|
1 |
|
'query' => $class::find()->innerJoinWith(['solicitude']) |
66
|
1 |
|
->andFilterWhere([ |
67
|
1 |
|
'form_id' => $this->form_id, |
|
|
|
|
68
|
1 |
|
'solicitude_id' => $this->solicitude_id, |
69
|
1 |
|
'section_id' => $this->section_id, |
70
|
1 |
|
'field_id' => $this->field_id, |
71
|
1 |
|
])->andFilterWhere(['like', 'value', $this->value]) |
72
|
1 |
|
]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inhertidoc |
77
|
|
|
*/ |
78
|
|
|
public function afterValidate() |
79
|
1 |
|
{ |
80
|
|
|
Model::afterValidate(); |
81
|
1 |
|
} |
82
|
|
|
} |
83
|
|
|
|