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)) { |
||||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
30 | throw new InvalidParamException('Model should be an instance of Server model'); |
||||
0 ignored issues
–
show
The class
yii\base\InvalidParamException has been deprecated: since 2.0.14. Use [[InvalidArgumentException]] instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
31 | } |
||||
32 | } |
||||
33 | |||||
34 | /** |
||||
35 | * @return string |
||||
36 | */ |
||||
37 | public function run() |
||||
38 | { |
||||
39 | if ($this->model->state !== 'blocked') { |
||||
40 | $value = Yii::$app->formatter->asDate($this->model->expires); |
||||
41 | } else { |
||||
42 | $value = Yii::t('hipanel:server', 'Blocked {reason}', ['reason' => Yii::t('hipanel:block-reasons', $this->model->block_reason_label)]); |
||||
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 |