1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Finance module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
6
|
|
|
* @package hipanel-module-finance |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\models; |
12
|
|
|
|
13
|
|
|
use hipanel\base\ModelTrait; |
14
|
|
|
use Yii; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class DomainResource. |
18
|
|
|
*/ |
19
|
|
|
class DomainResource extends Resource |
20
|
|
|
{ |
21
|
|
|
use ModelTrait; |
22
|
|
|
|
23
|
|
|
public static function tableName() |
24
|
|
|
{ |
25
|
|
|
return 'resource'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
const TYPE_DOMAIN_REGISTRATION = 'dregistration'; |
29
|
|
|
const TYPE_DOMAIN_TRANSFER = 'dtransfer'; |
30
|
|
|
const TYPE_DOMAIN_RENEWAL = 'drenewal'; |
31
|
|
|
const TYPE_DOMAIN_DELETE_AGP = 'ddelete_agp'; |
32
|
|
|
const TYPE_DOMAIN_RESTORE_EXPIRED = 'drestore_expired'; |
33
|
|
|
const TYPE_DOMAIN_RESTORE_DELETED = 'drestore_deleted'; |
34
|
|
|
|
35
|
|
|
const TYPE_PREMIUM_DNS = 'premium_dns'; |
36
|
|
|
|
37
|
|
|
public function rules() |
38
|
|
|
{ |
39
|
|
|
$rules = parent::rules(); |
40
|
|
|
$rules['create-required'] = [ |
41
|
|
|
['object_id'], |
42
|
|
|
'required', |
43
|
|
|
'on' => ['create', 'update'], |
44
|
|
|
'when' => function ($model) { |
45
|
|
|
return $model->isTypeCorrect(); |
46
|
|
|
}, |
47
|
|
|
]; |
48
|
|
|
$rules['create-required-price'] = [['price'], 'required', 'on' => ['create', 'update']]; |
49
|
|
|
$rules[] = [['zone'], 'safe']; |
50
|
|
|
|
51
|
|
|
return $rules; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function getTypes() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
static::TYPE_DOMAIN_REGISTRATION => Yii::t('hipanel:finance:tariff', 'Registration'), |
61
|
|
|
static::TYPE_DOMAIN_TRANSFER => Yii::t('hipanel:finance:tariff', 'Transfer'), |
62
|
|
|
static::TYPE_DOMAIN_RENEWAL => Yii::t('hipanel:finance:tariff', 'Renewal'), |
63
|
|
|
static::TYPE_DOMAIN_DELETE_AGP => Yii::t('hipanel:finance:tariff', 'Delete in AGP'), |
64
|
|
|
static::TYPE_DOMAIN_RESTORE_EXPIRED => Yii::t('hipanel:finance:tariff', 'Restoring expired'), |
65
|
|
|
static::TYPE_DOMAIN_RESTORE_DELETED => Yii::t('hipanel:finance:tariff', 'Restoring deleted'), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getServiceTypes() |
70
|
|
|
{ |
71
|
|
|
return [ |
72
|
|
|
static::TYPE_PREMIUM_DNS => Yii::t('hipanel:finance:tariff', 'Premium DNS'), |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function isTypeCorrect() |
77
|
|
|
{ |
78
|
|
|
return isset($this->getTypes()[$this->type]); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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@property
annotation 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.