|
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\Osimage; |
|
14
|
|
|
use yii\base\Widget; |
|
15
|
|
|
use yii\bootstrap\Modal; |
|
16
|
|
|
use yii\helpers\Html; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class OSFormatter. |
|
20
|
|
|
* |
|
21
|
|
|
* Renders a formatted information about OS |
|
22
|
|
|
* |
|
23
|
|
|
* @uses \yii\bootstrap\Modal |
|
24
|
|
|
* @uses \app\modules\server\models\Osimage |
|
25
|
|
|
* @author SilverFire |
|
26
|
|
|
*/ |
|
27
|
|
|
class OSFormatter extends Widget |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var array array of OsImages models |
|
31
|
|
|
*/ |
|
32
|
|
|
public $osimages = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var Osimage model |
|
36
|
|
|
*/ |
|
37
|
|
|
public $osimage; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string osimage code-name |
|
41
|
|
|
*/ |
|
42
|
|
|
public $imageName; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var bool whether to display a button with modal pop-up, containing OS soft information |
|
46
|
|
|
*/ |
|
47
|
|
|
public $infoCircle = true; |
|
48
|
|
|
|
|
49
|
|
|
public function init() |
|
50
|
|
|
{ |
|
51
|
|
|
parent::init(); |
|
52
|
|
|
|
|
53
|
|
|
if (is_array($this->osimages)) { |
|
|
|
|
|
|
54
|
|
|
foreach ($this->osimages as $osimage) { |
|
55
|
|
|
if ($osimage->osimage === $this->imageName) { |
|
56
|
|
|
$this->osimage = $osimage; |
|
57
|
|
|
break; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return string html code of definition list |
|
65
|
|
|
*/ |
|
66
|
|
|
public function generateOSInfo() |
|
67
|
|
|
{ |
|
68
|
|
|
$html = Html::beginTag('table', ['class' => 'table table-condensed table-striped']); |
|
69
|
|
|
$soft = []; |
|
70
|
|
|
if ($this->osimage->softpack['soft']) { |
|
71
|
|
|
$soft = $this->osimage->softpack['soft']; |
|
72
|
|
|
} else if ($this->osimage->softpack['packages']) { |
|
73
|
|
|
$soft = $this->osimage->softpack['packages']; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
foreach ($soft as $item) { |
|
77
|
|
|
$html .= Html::beginTag('tr'); |
|
78
|
|
|
$html .= Html::tag('th', $item['name'] . ' ' . $item['version'], ['class' => 'text-right']); |
|
79
|
|
|
$html .= Html::tag('td', str_replace(',', ', ', $item['description'])); |
|
80
|
|
|
$html .= Html::endTag('tr'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$html .= Html::endTag('table'); |
|
84
|
|
|
|
|
85
|
|
|
return $html; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Renders info-circle with modal popup. |
|
90
|
|
|
*/ |
|
91
|
|
|
public function generateInfoCircle() |
|
92
|
|
|
{ |
|
93
|
|
|
Modal::begin([ |
|
94
|
|
|
'toggleButton' => [ |
|
95
|
|
|
'class' => 'fa fa-info text-info os-info-popover', |
|
96
|
|
|
'label' => '', |
|
97
|
|
|
], |
|
98
|
|
|
'header' => Html::tag('h4', $this->osimage->getFullOsName()), |
|
99
|
|
|
'size' => Modal::SIZE_LARGE, |
|
100
|
|
|
]); |
|
101
|
|
|
echo Html::tag('div', $this->generateOSInfo(), [ |
|
102
|
|
|
'class' => 'table-responsive', |
|
103
|
|
|
]); |
|
104
|
|
|
Modal::end(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Renders the widget. |
|
109
|
|
|
*/ |
|
110
|
|
|
public function run() |
|
111
|
|
|
{ |
|
112
|
|
|
if (!$this->osimage instanceof Osimage) { |
|
|
|
|
|
|
113
|
|
|
echo $this->imageName; |
|
114
|
|
|
|
|
115
|
|
|
return; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
echo $this->osimage->getFullOsName(); |
|
119
|
|
|
echo ' '; |
|
120
|
|
|
if ($this->osimage->hasSoftPack() && $this->infoCircle) { |
|
121
|
|
|
$this->generateInfoCircle(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|