Completed
Push — master ( 799d81...9805c7 )
by Angel
05:02
created

SolicitudeValueSimpleSearch   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 65
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 0 19 2
A rules() 0 5 1
A attributes() 0 3 1
A afterValidate() 0 3 1
A slugBehaviorConfig() 0 6 1
1
<?php
2
3
namespace roaresearch\yii2\formgenerator\roa\models;
4
5
use yii\{base\Model, data\ActiveDataProvider};
6
7
/**
8
 * Contract to filter and sort collections of `SolicitudeValue` records.
9
 *
10
 * Unlike `SolicitudeValueSearch` this class doesnt invoke the parent
11
 * `Solicitude` record so it can search `SolicitudeValue` records across
12
 * different `Solicitude` records.
13
 *
14
 * @author Angel (Faryshta) Guevara <[email protected]>
15
 *
16
 * @property int $form_id
17
 */
18
class SolicitudeValueSimpleSearch extends SolicitudeValue implements
19
    \roaresearch\yii2\roa\ResourceSearch
20
{
21
    /**
22
     * @inhertidoc
23
     */
24 1
    protected function slugBehaviorConfig(): array
25
    {
26
        return [
27 1
            'idAttribute' => [],
28
            'parentSlugRelation' => null,
29
            'resourceName' => 'solicitude-value',
30
        ];
31
    }
32
33
    /**
34
     * @inhertidoc
35
     */
36 1
    public function attributes()
37
    {
38 1
        return array_merge(parent::attributes(), ['form_id']);
39
    }
40
41
    /**
42
     * @inhertidoc
43
     */
44 1
    public function rules()
45
    {
46
        return [
47 1
            [['form_id', 'solicitude_id', 'section_id', 'field_id'], 'integer'],
48
            [['value'], 'safe'],
49
        ];
50
    }
51
52
    /**
53
     * @inhertidoc
54
     */
55 1
    public function search(
56
        array $params,
57
        ?string $formName = ''
58
    ): ?ActiveDataProvider {
59 1
        $this->load($params, $formName);
60 1
        if (!$this->validate()) {
61 1
            return null;
62
        }
63 1
        $this->checkAccess($params);
0 ignored issues
show
Bug introduced by
The method checkAccess() does not exist on roaresearch\yii2\formgen...citudeValueSimpleSearch. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        $this->/** @scrutinizer ignore-call */ 
64
               checkAccess($params);
Loading history...
64 1
        $class = get_parent_class();
65
66 1
        return new ActiveDataProvider([
67 1
            'query' => $class::find()->innerJoinWith(['solicitude'])
68 1
                ->andFilterWhere([
69 1
                    'form_id' => $this->form_id,
70 1
                    'solicitude_id' => $this->solicitude_id,
71 1
                    'section_id' => $this->section_id,
72 1
                    'field_id' => $this->field_id,
73 1
                ])->andFilterWhere(['like', 'value', $this->value])
74
        ]);
75
    }
76
77
    /**
78
     * @inhertidoc
79
     */
80 1
    public function afterValidate()
81
    {
82 1
        Model::afterValidate();
83 1
    }
84
}
85