1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Hosting Plugin for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-hosting |
6
|
|
|
* @package hipanel-module-hosting |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\hosting\grid; |
12
|
|
|
|
13
|
|
|
use hipanel\grid\MainColumn; |
14
|
|
|
use hipanel\grid\RefColumn; |
15
|
|
|
use hipanel\helpers\FontIcon; |
16
|
|
|
use hipanel\modules\hosting\controllers\IpController; |
17
|
|
|
use hipanel\modules\hosting\menus\ServiceActionsMenu; |
18
|
|
|
use hipanel\modules\hosting\models\DbSearch; |
19
|
|
|
use hipanel\modules\hosting\models\HdomainSearch; |
20
|
|
|
use hipanel\modules\hosting\models\Soft; |
21
|
|
|
use hipanel\modules\server\grid\ServerColumn; |
22
|
|
|
use hipanel\widgets\ArraySpoiler; |
23
|
|
|
use hipanel\widgets\State; |
24
|
|
|
use hiqdev\yii2\menus\grid\MenuColumn; |
25
|
|
|
use Yii; |
26
|
|
|
use yii\helpers\Html; |
27
|
|
|
|
28
|
|
|
class ServiceGridView extends \hipanel\grid\BoxedGridView |
29
|
|
|
{ |
30
|
|
|
public function columns() |
31
|
|
|
{ |
32
|
|
|
return array_merge(parent::columns(), [ |
33
|
|
|
'service' => [ |
34
|
|
|
'class' => MainColumn::class, |
35
|
|
|
'attribute' => 'name', |
36
|
|
|
'filterAttribute' => 'service_like', |
37
|
|
|
], |
38
|
|
|
'server' => [ |
39
|
|
|
'class' => ServerColumn::class, |
40
|
|
|
], |
41
|
|
|
'object' => [ |
42
|
|
|
'format' => 'raw', |
43
|
|
|
'header' => Yii::t('hipanel:hosting', 'Object'), |
44
|
|
|
'value' => function ($model) { |
45
|
|
|
$html = $model->name . ' '; |
46
|
|
|
|
47
|
|
|
if ($model->soft_type === Soft::TYPE_WEB) { |
48
|
|
|
$url['ok'] = ['@hdomain', (new HdomainSearch())->formName() => ['server' => $model->server, 'service' => $model->name]]; |
49
|
|
|
$url['deleted'] = ['@hdomain', (new HdomainSearch())->formName() => ['server' => $model->server, 'service' => $model->name, 'state' => 'deleted']]; |
50
|
|
|
$type = function ($count) { |
51
|
|
|
return Yii::t('hipanel:hosting', '{0, plural, one{domain} other{domains}}', (int) $count); |
|
|
|
|
52
|
|
|
}; |
53
|
|
|
} elseif ($model->soft_type === Soft::TYPE_DB) { |
54
|
|
|
$url['ok'] = ['@db', (new DbSearch())->formName() => ['server' => $model->server, 'service' => $model->name]]; |
55
|
|
|
$url['deleted'] = ['@db', (new DbSearch())->formName() => ['server' => $model->server, 'service' => $model->name, 'state' => 'deleted']]; |
56
|
|
|
$type = function ($count) { |
57
|
|
|
return Yii::t('hipanel:hosting', '{0, plural, one{# DB} other{# DBs}}', (int) $count); |
|
|
|
|
58
|
|
|
}; |
59
|
|
|
} else { |
60
|
|
|
return $html; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
if ($count = $model->objects_count['ok']) { |
64
|
|
|
$html .= Html::a( |
65
|
|
|
(int) $count . ' ' . FontIcon::i('fa-check') . ' ' . $type($count), |
66
|
|
|
$url['ok'], |
67
|
|
|
['class' => 'btn btn-success btn-xs'] |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
$html .= ' '; |
71
|
|
View Code Duplication |
if (($count = $model->objects_count['deleted']) > 0) { |
72
|
|
|
$html .= Html::a( |
73
|
|
|
(int) $count . ' ' . FontIcon::i('fa-trash') . ' ' . $type($count), |
74
|
|
|
$url['deleted'], |
75
|
|
|
['class' => 'btn btn-xs btn-warning'] |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $html; |
80
|
|
|
}, |
81
|
|
|
], |
82
|
|
|
'ip' => [ |
83
|
|
|
'format' => 'raw', |
84
|
|
|
'label' => Yii::t('hipanel:hosting', 'IP'), |
85
|
|
|
'value' => function ($model) { |
86
|
|
|
return ArraySpoiler::widget(['data' => array_unique(array_merge((array) $model->ip, (array) $model->ips))]); |
87
|
|
|
}, |
88
|
|
|
], |
89
|
|
|
'ip_with_link' => [ |
90
|
|
|
'format' => 'raw', |
91
|
|
|
'label' => Yii::t('hipanel:hosting', 'IP'), |
92
|
|
|
'value' => function ($model) { |
93
|
|
|
$ips = Html::tag('span', ArraySpoiler::widget(['data' => array_unique(array_merge((array) $model->ip, (array) $model->ips))])); |
94
|
|
|
$linkToIPs = Html::a(Yii::t('hipanel', 'Show'), IpController::getSearchUrl([ |
95
|
|
|
'server_in' => $model->server, |
96
|
|
|
'service_id' => $model->id, |
97
|
|
|
]), ['class' => 'btn bg-olive btn-xs btn-flat', 'target' => '_blank', 'data-pjax' => 0]); |
98
|
|
|
|
99
|
|
|
return Html::tag('span', sprintf('%s %s', $ips, $linkToIPs), ['style' => 'display: flex; justify-content: space-between;']); |
100
|
|
|
}, |
101
|
|
|
], |
102
|
|
|
'bin' => [ |
103
|
|
|
'format' => 'html', |
104
|
|
|
'value' => function ($model) { |
105
|
|
|
return $model->bin ? Html::tag('code', $model->bin) : ''; |
106
|
|
|
}, |
107
|
|
|
], |
108
|
|
|
'etc' => [ |
109
|
|
|
'format' => 'html', |
110
|
|
|
'value' => function ($model) { |
111
|
|
|
return $model->etc ? Html::tag('code', $model->etc) : ''; |
112
|
|
|
}, |
113
|
|
|
], |
114
|
|
|
'soft' => [ |
115
|
|
|
'value' => function ($model) { |
116
|
|
|
return $model->soft; |
117
|
|
|
}, |
118
|
|
|
], |
119
|
|
|
'state' => [ |
120
|
|
|
'class' => RefColumn::class, |
121
|
|
|
'i18nDictionary' => 'hipanel:hosting', |
122
|
|
|
'format' => 'raw', |
123
|
|
|
'value' => function ($model) { |
124
|
|
|
return State::widget(compact('model')); |
125
|
|
|
}, |
126
|
|
|
'gtype' => 'state,service', |
127
|
|
|
], |
128
|
|
|
'actions' => [ |
129
|
|
|
'class' => MenuColumn::class, |
130
|
|
|
'menuClass' => ServiceActionsMenu::class, |
131
|
|
|
], |
132
|
|
|
]); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: