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