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