1 | <?php |
||
38 | class Plan extends Model |
||
39 | { |
||
40 | public const TYPE_SERVER = 'server'; |
||
41 | public const TYPE_PCDN = 'pcdn'; |
||
42 | public const TYPE_VCDN = 'vcdn'; |
||
43 | public const TYPE_TEMPLATE = 'template'; |
||
44 | public const TYPE_CERTIFICATE = 'certificate'; |
||
45 | public const TYPE_DOMAIN = 'domain'; |
||
46 | public const TYPE_SWITCH = 'switch'; |
||
47 | public const TYPE_AVDS = 'avds'; |
||
48 | public const TYPE_OVDS = 'ovds'; |
||
49 | public const TYPE_SVDS = 'svds'; |
||
50 | public const TYPE_CLIENT = 'client'; |
||
51 | public const TYPE_HARDWARE = 'hardware'; |
||
52 | |||
53 | use ModelTrait; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | public $monthly; |
||
59 | |||
60 | public $servers = []; |
||
61 | |||
62 | public function rules() |
||
63 | { |
||
64 | return array_merge(parent::rules(), [ |
||
65 | [['id', 'type_id', 'state_id', 'client_id', 'currency_id'], 'integer'], |
||
66 | [['type', 'state', 'client', 'name', 'plan', 'note', 'currency', 'is_grouping'], 'string'], |
||
67 | |||
68 | [['type', 'name', 'currency'], 'required', 'on' => ['create', 'update']], |
||
69 | [['id'], 'required', 'on' => ['update', 'delete', 'set-note']], |
||
70 | [['id'], 'required', 'on' => ['delete', 'restore']], |
||
71 | [['id', 'server_ids'], 'safe', 'on' => ['copy']], |
||
72 | [['your_tariff'], 'boolean'], |
||
73 | ]); |
||
74 | } |
||
75 | |||
76 | public function attributeLabels() |
||
77 | { |
||
78 | return array_merge(parent::attributeLabels(), [ |
||
79 | 'client' => Yii::t('hipanel', 'Seller'), |
||
80 | 'name' => Yii::t('hipanel:finance', 'Name'), |
||
81 | 'server_ids' => Yii::t('hipanel.finance.plan', 'Servers'), |
||
82 | 'monthly' => Yii::t('hipanel.finance.plan', 'Monthly'), |
||
83 | 'is_grouping' => Yii::t('hipanel.finance.plan', 'Grouping'), |
||
84 | 'currency' => Yii::t('hipanel:finance', 'Currency'), |
||
85 | ]); |
||
86 | } |
||
87 | |||
88 | public function getPrices() |
||
89 | { |
||
90 | if ($this->type === Plan::TYPE_CERTIFICATE) { |
||
91 | return $this->hasMany(CertificatePrice::class, ['plan_id' => 'id'])->inverseOf('plan'); |
||
92 | } |
||
93 | |||
94 | return $this->hasMany(Price::class, ['plan_id' => 'id'])->indexBy('id')->inverseOf('plan'); |
||
95 | } |
||
96 | |||
97 | public function getPriceHistory() |
||
101 | |||
102 | public function getDesiredPriceClass() |
||
103 | { |
||
104 | if ($this->type === Plan::TYPE_CERTIFICATE) { |
||
110 | |||
111 | public function getSales() |
||
115 | |||
116 | public function getTypeOptions() |
||
120 | |||
121 | public function getStateOptions() |
||
125 | |||
126 | public function isDeleted(): bool |
||
130 | |||
131 | public function supportsSharedPrices(): bool |
||
135 | |||
136 | /** |
||
137 | * {@inheritdoc} |
||
138 | * @return PlanQuery |
||
139 | */ |
||
140 | public static function find($options = []) |
||
146 | } |
||
147 |