1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Server module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-server |
6
|
|
|
* @package hipanel-module-server |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\server\cart; |
12
|
|
|
|
13
|
|
|
use hipanel\modules\server\models\Config; |
14
|
|
|
use hipanel\modules\server\models\Osimage; |
15
|
|
|
use hipanel\modules\server\models\Package; |
16
|
|
|
use hipanel\modules\server\widgets\cart\OrderPositionDescriptionWidget; |
17
|
|
|
use Yii; |
18
|
|
|
use yii\helpers\ArrayHelper; |
19
|
|
|
|
20
|
|
|
class ServerOrderDedicatedProduct extends AbstractServerProduct |
21
|
|
|
{ |
22
|
|
|
/** {@inheritdoc} */ |
23
|
|
|
protected $_purchaseModel = ServerOrderDedicatedPurchase::class; |
24
|
|
|
|
25
|
|
|
/** @var Package */ |
26
|
|
|
protected $_model; |
27
|
|
|
|
28
|
|
|
/** {@inheritdoc} */ |
29
|
|
|
protected $_calculationModel = ConfigCalculation::class; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Osimage the selected OS image detailed information |
33
|
|
|
*/ |
34
|
|
|
protected $_image; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public $location; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var integer |
43
|
|
|
*/ |
44
|
|
|
public $object_id; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var integer |
48
|
|
|
*/ |
49
|
|
|
public $tariff_id; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
public $label; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string link to any kind of social network |
58
|
|
|
*/ |
59
|
|
|
public $administration; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string osimage name. Is used to load [[_image]] on product initialisation |
63
|
|
|
*/ |
64
|
|
|
public $osimage; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var string software package name |
68
|
|
|
*/ |
69
|
|
|
public $softpack; |
70
|
|
|
|
71
|
|
|
/** {@inheritdoc} */ |
72
|
|
|
public function load($data, $formName = null) |
73
|
|
|
{ |
74
|
|
|
if ($result = parent::load($data, '')) { |
75
|
|
|
$this->ensureRelatedData(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $result; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** {@inheritdoc} */ |
82
|
|
|
private function ensureRelatedData() |
83
|
|
|
{ |
84
|
|
|
$this->_model = Config::findOne($this->object_id); |
|
|
|
|
85
|
|
|
$this->_image = Osimage::find()->where(['osimage' => $this->osimage, 'type' => 'dedicated'])->one(); |
|
|
|
|
86
|
|
|
$this->name = $this->_model->name; |
87
|
|
|
$this->description = $this->_model->descr; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** {@inheritdoc} */ |
91
|
|
|
public function getId() |
92
|
|
|
{ |
93
|
|
|
if ($this->_id === null) { |
94
|
|
|
$this->_id = hash('crc32b', implode('_', ['server', 'order', 'dedicated', $this->_model->id])); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $this->_id; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** {@inheritdoc} */ |
101
|
|
|
public function getCalculationModel($options = []) |
102
|
|
|
{ |
103
|
|
|
return parent::getCalculationModel(array_merge([ |
104
|
|
|
'tariff_id' => $this->tariff_id, |
105
|
|
|
'object_id' => $this->object_id, |
106
|
|
|
'location' => $this->location, |
107
|
|
|
], $options)); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** {@inheritdoc} */ |
111
|
|
|
public function getPurchaseModel($options = []) |
112
|
|
|
{ |
113
|
|
|
$this->ensureRelatedData(); |
114
|
|
|
|
115
|
|
|
$options = array_merge([ |
116
|
|
|
'osimage' => $this->osimage, |
117
|
|
|
'object_id' => $this->object_id, |
118
|
|
|
'label' => $this->label, |
119
|
|
|
'administration' => $this->administration, |
120
|
|
|
'softpack' => $this->softpack, |
121
|
|
|
'tariff_id' => $this->tariff_id, |
122
|
|
|
], $options); |
123
|
|
|
|
124
|
|
|
return parent::getPurchaseModel($options); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** {@inheritdoc} */ |
128
|
|
|
public function rules() |
129
|
|
|
{ |
130
|
|
|
return array_merge(parent::rules(), [ |
131
|
|
|
[['object_id', 'tariff_id'], 'integer'], |
132
|
|
|
[['administration', 'osimage', 'label', 'location'], 'string'], |
133
|
|
|
[['tariff_id', 'object_id', 'osimage', 'location'], 'required'], |
134
|
|
|
]); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** {@inheritdoc} */ |
138
|
|
|
public function attributeLabels() |
139
|
|
|
{ |
140
|
|
|
return ArrayHelper::merge(parent::attributeLabels(), [ |
141
|
|
|
'object_id' => Yii::t('hipanel:server:order', 'Server config'), |
142
|
|
|
'label' => Yii::t('hipanel:server:order', 'Label'), |
143
|
|
|
]); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** {@inheritdoc} */ |
147
|
|
|
public function attributeHints() |
148
|
|
|
{ |
149
|
|
|
return ArrayHelper::merge(parent::attributeHints(), [ |
150
|
|
|
'label' => Yii::t('hipanel:server:order', 'How are you going to use the server?'), |
151
|
|
|
'administration' => Yii::t('hipanel:server:order', 'Any social network link. Will be used in case of emergency contact'), |
152
|
|
|
]); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** {@inheritdoc} */ |
156
|
|
|
public function renderDescription() |
157
|
|
|
{ |
158
|
|
|
return OrderPositionDescriptionWidget::widget(['position' => $this]); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return Osimage |
163
|
|
|
*/ |
164
|
|
|
public function getImage() |
165
|
|
|
{ |
166
|
|
|
return $this->_image; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
protected function serializationMap() |
170
|
|
|
{ |
171
|
|
|
$parent = parent::serializationMap(); |
172
|
|
|
$parent['object_id'] = $this->object_id; |
173
|
|
|
$parent['osimage'] = $this->osimage; |
174
|
|
|
$parent['label'] = $this->label; |
175
|
|
|
$parent['administration'] = $this->administration; |
176
|
|
|
$parent['softpack'] = $this->softpack; |
177
|
|
|
$parent['tariff_id'] = $this->tariff_id; |
178
|
|
|
$parent['location'] = $this->location; |
179
|
|
|
$parent['_image'] = $this->_image; |
180
|
|
|
|
181
|
|
|
return $parent; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..