FieldSearch::slugBehaviorConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 `Field` records.
10
 * @author Angel (Faryshta) Guevara <[email protected]>
11
 */
12
class FieldSearch extends Field implements ResourceSearch
13
{
14
    /**
15
     * @inhertidoc
16
     */
17 1
    protected function slugBehaviorConfig(): array
18
    {
19
        return [
20 1
            'idAttribute' => [],
21
            'resourceName' => 'field',
22
        ];
23
    }
24
25
    /**
26
     * @inhertidoc
27
     */
28 1
    public function rules()
29
    {
30
        return [
31 1
            [['data_type_id', 'created_by'], 'integer'],
32
            [['name', 'label'], 'string'],
33
        ];
34
    }
35
36
    /**
37
     * @inhertidoc
38
     */
39 1
    public function search(
40
        array $params,
41
        ?string $formName = ''
42
    ): ?ActiveDataProvider {
43 1
        $this->load($params, $formName);
44 1
        if (!$this->validate()) {
45 1
            return null;
46
        }
47
48 1
        $class = get_parent_class();
49
50 1
        return new ActiveDataProvider([
51 1
            'query' => $class::find()->andFilterWhere([
52 1
                    'created_by' => $this->created_by,
53 1
                    'data_type_id' => $this->data_type_id,
54
                ])
55 1
                ->andFilterWhere(['like', 'name', $this->name])
56 1
                ->andFilterWhere(['like', 'label', $this->label]),
57
        ]);
58
    }
59
}
60