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\widgets; |
||
12 | |||
13 | use hipanel\modules\server\models\Server; |
||
14 | use Yii; |
||
15 | use yii\base\InvalidParamException; |
||
16 | use yii\base\Widget; |
||
17 | use yii\helpers\Html; |
||
18 | |||
19 | class StateFormatter extends Widget |
||
20 | { |
||
21 | /** |
||
22 | * @var Server |
||
23 | */ |
||
24 | public $model; |
||
25 | |||
26 | public function init() |
||
27 | { |
||
28 | parent::init(); |
||
29 | if (!($this->model instanceof Server)) { |
||
30 | throw new InvalidParamException('Model should be an instance of Server model'); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @return string |
||
36 | */ |
||
37 | public function run() |
||
38 | { |
||
39 | if ($this->model->state !== 'blocked') { |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
40 | $value = Yii::$app->formatter->asDate($this->model->expires); |
||
0 ignored issues
–
show
The property
expires does not exist on hipanel\modules\server\models\Server . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
41 | } else { |
||
42 | $value = Yii::t('hipanel:server', 'Blocked {reason}', ['reason' => Yii::t('hipanel:block-reasons', $this->model->block_reason_label)]); |
||
0 ignored issues
–
show
The property
block_reason_label does not exist on hipanel\modules\server\models\Server . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
43 | } |
||
44 | |||
45 | $class = ['label']; |
||
46 | |||
47 | if (strtotime('+7 days', time()) < strtotime($this->model->expires)) { |
||
48 | $class[] = 'label-info'; |
||
49 | } elseif (strtotime('+3 days', time()) < strtotime($this->model->expires)) { |
||
50 | $class[] = 'label-warning'; |
||
51 | } else { |
||
52 | $class[] = 'label-danger'; |
||
53 | } |
||
54 | $html = Html::tag('span', $value, ['class' => implode(' ', $class)]); |
||
55 | |||
56 | return $html; |
||
57 | } |
||
58 | } |
||
59 |