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-2019, 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 DomainZonePrice. |
18
|
|
|
*/ |
19
|
|
|
class DomainZonePrice extends Price |
20
|
|
|
{ |
21
|
|
|
use ModelTrait; |
22
|
|
|
|
23
|
|
|
public static function tableName() |
24
|
|
|
{ |
25
|
|
|
return 'price'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public const TYPE_DOMAIN_REGISTRATION = 'domain,dregistration'; |
29
|
|
|
public const TYPE_DOMAIN_TRANSFER = 'domain,dtransfer'; |
30
|
|
|
public const TYPE_DOMAIN_RENEWAL = 'domain,drenewal'; |
31
|
|
|
public const TYPE_DOMAIN_DELETE_AGP = 'domain,ddelete_agp'; |
32
|
|
|
public const TYPE_DOMAIN_RESTORE_EXPIRED = 'domain,drestore_expired'; |
33
|
|
|
public const TYPE_DOMAIN_RESTORE_DELETED = 'domain,drestore_deleted'; |
34
|
|
|
|
35
|
|
|
public function rules() |
36
|
|
|
{ |
37
|
|
|
$rules = parent::rules(); |
38
|
|
|
$rules['create-required'] = [ |
39
|
|
|
['object_id'], |
40
|
|
|
'required', |
41
|
|
|
'on' => ['create', 'update'], |
42
|
|
|
'when' => function ($model) { |
43
|
|
|
/** @var parent $model */ |
44
|
|
|
return $model->isTypeCorrect(); |
45
|
|
|
}, |
46
|
|
|
]; |
47
|
|
|
$rules['create-required-price'] = [['price'], 'required']; |
48
|
|
|
$rules[] = [['price'], 'number', 'min' => 0]; |
49
|
|
|
|
50
|
|
|
return $rules; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function isTypeCorrect(): bool |
57
|
|
|
{ |
58
|
|
|
return isset($this->getTypes()[$this->type]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
|
|
public static function getTypes(): array |
65
|
|
|
{ |
66
|
|
|
return [ |
67
|
|
|
static::TYPE_DOMAIN_REGISTRATION => Yii::t('hipanel:finance:tariff', 'Registration'), |
68
|
|
|
static::TYPE_DOMAIN_TRANSFER => Yii::t('hipanel:finance:tariff', 'Transfer'), |
69
|
|
|
static::TYPE_DOMAIN_RENEWAL => Yii::t('hipanel:finance:tariff', 'Renewal'), |
70
|
|
|
static::TYPE_DOMAIN_DELETE_AGP => Yii::t('hipanel:finance:tariff', 'Delete in AGP'), |
71
|
|
|
static::TYPE_DOMAIN_RESTORE_EXPIRED => Yii::t('hipanel:finance:tariff', 'Restoring expired'), |
72
|
|
|
static::TYPE_DOMAIN_RESTORE_DELETED => Yii::t('hipanel:finance:tariff', 'Restoring deleted'), |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|