Completed
Push — master ( 844c41...030ae6 )
by Dmitry
04:17
created

AbstractTariffForm::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\finance\forms;
4
5
use hipanel\base\Model;
6
use hipanel\modules\finance\models\Tariff;
7
use Yii;
8
use yii\base\InvalidConfigException;
9
use yii\helpers\ArrayHelper;
10
11
abstract class AbstractTariffForm extends Model
12
{
13
    /**
14
     * @var int Tariff ID
15
     */
16
    public $id;
17
18
    /**
19
     * @var string Tariff name
20
     */
21
    public $name;
22
23
    /**
24
     * @var int Parent tariff ID
25
     */
26
    public $parent_id;
27
28
    /** @var Tariff */
29
    public $tariff;
30
31
    /** @var Tariff */
32
    public $baseTariff;
33
34
    /** @var Resource[] */
35
    protected $_resources;
36
37
    /** @inheritdoc */
38
    public function attributes()
39
    {
40
        return [
41
            'id',
42
            'parent_id',
43
            'name',
44
        ];
45
    }
46
47
    /** @inheritdoc */
48
    public function rules()
49
    {
50
        return [
51
            [['name'], 'safe'],
52
            [['parent_id', 'id'], 'integer']
53
        ];
54
    }
55
56
    /** @inheritdoc */
57
    public function fields()
58
    {
59
        return ArrayHelper::merge(array_combine($this->attributes(), $this->attributes()), [
60
            'resources' => '_resources'
61
        ]);
62
    }
63
64
    public function getResources()
65
    {
66
        return $this->_resources;
67
    }
68
69
70
    public function getResourceTypes()
71
    {
72
        return reset($this->baseTariff->resources)->getAvailableTypes();
73
    }
74
75
    public function attributeLabels()
76
    {
77
        return [
78
            'name' => Yii::t('hipanel/finance/tariff', 'Name'),
79
        ];
80
    }
81
82
    /**
83
     *
84
     * @param array $data to be loaded
85
     * @return bool
86
     * @throws InvalidConfigException when not implemented
87
     */
88
    public function load($data)
89
    {
90
        throw new InvalidConfigException("Method load must be implemented");
91
    }
92
93
    /**
94
     * @param array $data
95
     * @throws InvalidConfigException when not implemented
96
     */
97
    public function fill($data)
98
    {
99
        throw new InvalidConfigException("Method load must be implemented");
100
    }
101
102
    /**
103
     * @param array $resources
104
     * @throws InvalidConfigException when not implemented
105
     */
106
    public function setResources($resources)
107
    {
108
        throw new InvalidConfigException("Method load must be implemented");
109
    }
110
111
    public function insert($runValidation = true, $attributes = null, $options = [])
112
    {
113
        throw new InvalidConfigException("Method load must be implemented");
114
    }
115
116
    public function update($runValidation = true, $attributes = null, $options = [])
117
    {
118
        throw new InvalidConfigException("Method load must be implemented");
119
    }
120
}
121