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