|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Finance module for HiPanel |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
|
7
|
|
|
* @package hipanel-module-finance |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hipanel\modules\finance\models; |
|
13
|
|
|
|
|
14
|
|
|
use hipanel\modules\finance\models\query\TariffQuery; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class Tariff |
|
18
|
|
|
* @package hipanel\modules\finance\models |
|
19
|
|
|
* @property Resource[]|DomainResource[]|ServerResource[] $resources |
|
20
|
|
|
*/ |
|
21
|
|
|
class Tariff extends \hipanel\base\Model |
|
22
|
|
|
{ |
|
23
|
|
|
use \hipanel\base\ModelTrait; |
|
24
|
|
|
|
|
25
|
|
|
const TYPE_DOMAIN = 'domain'; |
|
26
|
|
|
const TYPE_SVDS = 'svds'; |
|
27
|
|
|
const TYPE_OVDS = 'ovds'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function rules() |
|
33
|
|
|
{ |
|
34
|
|
|
return [ |
|
35
|
|
|
[['client_id', 'seller_id', 'id', 'parent_id'], 'integer'], |
|
36
|
|
|
[['client', 'seller', 'bill', 'name'], 'safe'], |
|
37
|
|
|
[['domain', 'server'], 'safe'], |
|
38
|
|
|
[['tariff', 'tariff_id'], 'safe'], |
|
39
|
|
|
[['type_id', 'state_id'], 'integer'], |
|
40
|
|
|
[['type', 'state'], 'safe'], |
|
41
|
|
|
[['used'], 'integer'], |
|
42
|
|
|
[['note', 'label'], 'safe'], |
|
43
|
|
|
[['is_personal'], 'boolean'], |
|
44
|
|
|
[['id'], 'required', 'on' => ['delete']], |
|
45
|
|
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getResources() |
|
49
|
|
|
{ |
|
50
|
|
|
if ($this->type === self::TYPE_DOMAIN) { |
|
|
|
|
|
|
51
|
|
|
return $this->hasMany(DomainResource::class, ['tariff_id' => 'id'])->inverseOf('tariff'); |
|
52
|
|
|
} elseif ($this->type === self::TYPE_SVDS || $this->type === self::TYPE_OVDS) { |
|
|
|
|
|
|
53
|
|
|
return $this->hasMany(ServerResource::class, ['tariff_id' => 'id'])->inverseOf('tariff'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this->hasMany(Resource::class, ['tariff_id' => 'id'])->inverseOf('tariff'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param $type |
|
61
|
|
|
* @return DomainResource|ServerResource|Resource |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getResourceByType($type) |
|
64
|
|
|
{ |
|
65
|
|
|
foreach ($this->resources as $resource) { |
|
66
|
|
|
if ($resource->type === $type) { |
|
67
|
|
|
return $resource; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
|
|
public function attributeLabels() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->mergeAttributeLabels([ |
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritdoc} |
|
85
|
|
|
* @return TariffQuery |
|
86
|
|
|
*/ |
|
87
|
|
|
public static function find($options = []) |
|
88
|
|
|
{ |
|
89
|
|
|
return new TariffQuery(get_called_class(), [ |
|
90
|
|
|
'options' => $options, |
|
91
|
|
|
]); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.