Completed
Pull Request — master (#2)
by Angel
08:33
created

CreditSearch::attributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace app\api\models;
4
5
use roaresearch\yii2\roa\ResourceSearch;
6
use roaresearch\yii2\workflow\models\Stage;
7
use yii\data\ActiveDataProvider;
8
9
class CreditSearch extends Credit implements ResourceSearch
10
{
11
    /**
12
     * @inhertidoc
13
     */
14
    public function attributes()
15
    {
16
        return array_merge(parent::attributes(), ['activeStage']);
17
    }
18
19
    /**
20
     * @inhertidoc
21
     */
22
    protected $autogenerateInitialWorklog = false;
23
24
    /**
25
     * @inhertidoc
26
     */
27
    public function rules()
28
    {
29
        return [
30
            [['created_by', 'activeStage'], 'integer'],
31
            [
32
                ['activeStage'],
33
                'exist',
34
                'targetAttribute' => ['stageActiveStage' => 'id'],
35
                'targetClass' => Stage::class,
36
                'message' => 'Stage not registered.'
37
            ],
38
        ];
39
    }
40
41
    /**
42
     * @inhertidoc
43
     */
44
    public function search(
45
        array $params,
46
        ?string $formName = ''
47
    ): ?ActiveDataProvider {
48
        $this->load($params, $formName);
49
        if (!$this->validate()) {
50
            return null;
51
        }
52
53
        $class = get_parent_class();
54
        return new ActiveDataProvider([
55
            'query' => $class::find()
56
                ->joinWith('activeWorklog')
57
                ->andFilterWhere([
58
                    'created_by' => $this->created_by,
0 ignored issues
show
Bug Best Practice introduced by
The property created_by does not exist on app\api\models\CreditSearch. Since you implemented __get, consider adding a @property annotation.
Loading history...
59
                    'activeWorklog.stage_id' => $this->activeStage,
0 ignored issues
show
Bug Best Practice introduced by
The property activeStage does not exist on app\api\models\CreditSearch. Since you implemented __get, consider adding a @property annotation.
Loading history...
60
                ])
61
        ]);
62
    }
63
}
64