1 | <?php |
||
21 | class Server extends \hipanel\base\Model |
||
22 | { |
||
23 | use \hipanel\base\ModelTrait; |
||
24 | |||
25 | const STATE_OK = 'ok'; |
||
26 | const STATE_DISABLED = 'disabled'; |
||
27 | const STATE_BLOCKED = 'blocked'; |
||
28 | const STATE_DELETED = 'deleted'; |
||
29 | |||
30 | public function rules() |
||
95 | |||
96 | /** |
||
97 | * Determine good server states. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | public function goodStates() |
||
105 | |||
106 | /** |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function isOperable() |
||
117 | |||
118 | public function canEnableVNC() |
||
119 | { |
||
120 | return $this->isVNCSupported() && $this->isStateGood(); |
||
121 | } |
||
122 | |||
123 | public function isStateGood() |
||
124 | { |
||
125 | return in_array($this->state, $this->goodStates(), true); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Checks whether server supports VNC. |
||
130 | * |
||
131 | * @return bool |
||
132 | */ |
||
133 | public function isVNCSupported() |
||
134 | { |
||
135 | return $this->type !== 'ovds'; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Checks whether server supports root password change. |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | public function isPwChangeSupported() |
||
144 | { |
||
145 | return $this->type === 'ovds'; |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * Checks whether server supports LiveCD. |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function isLiveCDSupported() |
||
154 | { |
||
155 | return $this->type !== 'ovds'; |
||
156 | } |
||
157 | |||
158 | public function getIsBlocked() |
||
159 | { |
||
160 | return $this->state === static::STATE_BLOCKED; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Checks whether server can be operated not. |
||
165 | * |
||
166 | * @throws NotSupportedException |
||
167 | * @return bool |
||
168 | * @see isOperable() |
||
169 | */ |
||
170 | public function checkOperable() |
||
177 | |||
178 | /** |
||
179 | * {@inheritdoc} |
||
180 | */ |
||
181 | public function scenarioActions() |
||
182 | { |
||
183 | return [ |
||
184 | 'reinstall' => 'resetup', |
||
185 | 'reset-password' => 'regen-root-password', |
||
186 | ]; |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * During 5 days after the last expiration client is able to refuse server with full refund. |
||
191 | * Method checks, whether 5 days passed. |
||
192 | * @return bool |
||
193 | */ |
||
194 | public function canFullRefuse() |
||
195 | { |
||
196 | return (time() - Yii::$app->formatter->asTimestamp($this->last_expires)) / 3600 / 24 < 5; |
||
197 | } |
||
198 | |||
199 | public function groupUsesForCharts() |
||
200 | { |
||
201 | return ServerHelper::groupUsesForChart($this->uses); |
||
202 | } |
||
203 | |||
204 | public function getUses() |
||
205 | { |
||
206 | return $this->hasMany(ServerUse::class, ['object_id' => 'id']); |
||
207 | } |
||
208 | |||
209 | public function getIps() |
||
213 | |||
214 | /** |
||
215 | * {@inheritdoc} |
||
216 | */ |
||
217 | public function attributeLabels() |
||
218 | { |
||
219 | return $this->mergeAttributeLabels([ |
||
220 | 'remoteid' => Yii::t('hipanel:server', 'Remote ID'), |
||
221 | 'name' => Yii::t('hipanel:server', 'Name'), |
||
222 | 'dc' => Yii::t('hipanel:server', 'DC'), |
||
241 | } |
||
242 |
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.