Completed
Pull Request — master (#1)
by Angel
07:01
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;
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);
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

62
        $this->/** @scrutinizer ignore-call */ 
63
               checkAccess($params);
Loading history...
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,
0 ignored issues
show
Bug Best Practice introduced by
The property form_id does not exist on roaresearch\yii2\formgen...citudeValueSimpleSearch. Since you implemented __get, consider adding a @property annotation.
Loading history...
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