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