FilesStatuse   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 15
eloc 37
dl 0
loc 81
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A isDelete() 0 2 1
A isDeleting() 0 2 1
A byKey() 0 13 3
A isReload() 0 2 1
A isNotLoading() 0 2 1
A byNotKey() 0 9 2
A isAllowedForKey() 0 19 2
A isNew() 0 2 1
A isLoading() 0 2 1
A forSelect() 0 2 1
A isLoaded() 0 2 1
1
<?php
2
/**
3
 * User: execut
4
 * Date: 18.07.16
5
 * Time: 10:35
6
 */
7
8
namespace execut\import\models\queries;
9
10
11
use yii\db\ActiveQuery;
12
use yii\helpers\ArrayHelper;
13
use \execut\import\models;
14
15
class FilesStatuse extends ActiveQuery
16
{
17
    public function isNew() {
18
        return $this->byKey(models\FilesStatuse::NEW);
19
    }
20
21
    public function isReload() {
22
        return $this->byKey(models\FilesStatuse::RELOAD);
23
    }
24
25
    public function isDelete() {
26
        return $this->byKey(models\FilesStatuse::DELETE);
27
    }
28
29
    public function isLoaded() {
30
        return $this->byKey(models\FilesStatuse::LOADED);
31
    }
32
33
    public function isLoading() {
34
        return $this->byKey(models\FilesStatuse::LOADING);
35
    }
36
37
    public function isDeleting() {
38
        return $this->byKey(models\FilesStatuse::DELETING);
39
    }
40
41
    public function isNotLoading() {
42
        return $this->byNotKey(models\FilesStatuse::LOADING);
43
    }
44
45
    public function byNotKey($key) {
46
        if (!is_array($key)) {
47
            $key = [$key];
48
        }
49
50
        return $this->andWhere([
51
            'NOT IN',
52
            'key',
53
            $key,
54
        ]);
55
    }
56
57
    public function byKey($key) {
58
        if (!is_array($key)) {
59
            $key = [$key];
60
        }
61
62
        if (!count($key)) {
63
            return $this->andWhere('0=1');
64
        }
65
66
        return $this->andWhere([
67
            'IN',
68
            'key',
69
            $key,
70
        ]);
71
    }
72
73
    public function forSelect() {
74
        return ArrayHelper::map($this->select(['id', 'name'])->asArray()->all(), 'id', 'name');
75
    }
76
77
    public function isAllowedForKey($key) {
78
        $keysChains = [
79
            models\FilesStatuse::NEW => [],
80
            models\FilesStatuse::RELOAD => [],
81
            models\FilesStatuse::DELETE => [],
82
            models\FilesStatuse::LOADED => [models\FilesStatuse::RELOAD, models\FilesStatuse::DELETE],
83
            models\FilesStatuse::LOADING => [models\FilesStatuse::STOP],
84
            models\FilesStatuse::DELETING => [],
85
            models\FilesStatuse::STOP => [],
86
            models\FilesStatuse::STOPED => [models\FilesStatuse::RELOAD, models\FilesStatuse::DELETE],
87
            models\FilesStatuse::ERROR => [models\FilesStatuse::RELOAD, models\FilesStatuse::DELETE],
88
        ];
89
90
        $keys = [$key];
91
        if (!empty($keysChains[$key])) {
92
            $keys = ArrayHelper::merge($keysChains[$key], $keys);
93
        }
94
95
        return $this->byKey($keys);
96
    }
97
}