Dictionary   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 25
dl 0
loc 55
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A attributes() 0 5 1
A primaryKey() 0 2 1
A formName() 0 3 1
A rules() 0 4 1
A search() 0 26 3
1
<?php
2
/**
3
 * User: execut
4
 * Date: 25.07.16
5
 * Time: 14:55
6
 */
7
8
namespace execut\import\models;
9
10
11
use execut\yii\base\Model;
12
use yii\data\ActiveDataProvider;
13
use yii\db\ActiveQuery;
14
15
class Dictionary extends Model
16
{
17
    public $type = null;
18
    public $name = null;
19
20
    public function rules()
21
    {
22
        return [
23
            [['type', 'name'], 'safe'],
24
        ];
25
    }
26
27
    public function attributes()
28
    {
29
        return [
30
            'name',
31
            'type',
32
        ];
33
    }
34
    
35
    public static function primaryKey() {
36
        return ['id'];
37
    }
38
39
    public function search() {
40
        $types = SettingsSheet::getDictionaries();
41
        $type = explode('.', $this->type)[0];
42
        /**
43
         * @var ActiveQuery $query
44
         */
45
        if (isset($types[$type])) {
46
            $query = $types[$type];
47
        } else {
48
            $query = current($types);
49
            $query->where('0=1');
50
        }
51
52
        if ($this->name) {
53
            $query->andWhere([
54
                'ILIKE',
55
                'name',
56
                $this->name
57
            ]);
58
        }
59
60
        $dp = new ActiveDataProvider([
61
            'query' => $query,
62
        ]);
63
64
        return $dp;
65
    }
66
67
    public function formName()
68
    {
69
        return '';
70
    }
71
}