1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Hosting Plugin for HiPanel |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hipanel-module-hosting |
7
|
|
|
* @package hipanel-module-hosting |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\modules\hosting\grid; |
13
|
|
|
|
14
|
|
|
use hipanel\grid\ActionColumn; |
15
|
|
|
use hipanel\grid\MainColumn; |
16
|
|
|
use hipanel\grid\RefColumn; |
17
|
|
|
use hipanel\grid\XEditableColumn; |
18
|
|
|
use hipanel\helpers\Url; |
19
|
|
|
use hipanel\modules\hosting\widgets\backup\BackupGridRow; |
20
|
|
|
use hipanel\modules\hosting\widgets\hdomain\State; |
21
|
|
|
use hipanel\modules\server\grid\ServerColumn; |
22
|
|
|
use hipanel\widgets\ArraySpoiler; |
23
|
|
|
use hipanel\widgets\Label; |
24
|
|
|
use hipanel\widgets\XEditable; |
25
|
|
|
use Yii; |
26
|
|
|
use yii\helpers\Html; |
27
|
|
|
|
28
|
|
|
class HdomainGridView extends \hipanel\grid\BoxedGridView |
29
|
|
|
{ |
30
|
|
|
public static function defaultColumns() |
31
|
|
|
{ |
32
|
|
|
return [ |
33
|
|
|
'hdomain' => [ |
34
|
|
|
'class' => MainColumn::class, |
35
|
|
|
'filterAttribute' => 'domain_like', |
36
|
|
|
'attribute' => 'domain' |
37
|
|
|
], |
38
|
|
|
'hdomain_with_aliases' => [ |
39
|
|
|
'format' => 'raw', |
40
|
|
|
'attribute' => 'domain', |
41
|
|
|
'filterAttribute' => 'domain_like', |
42
|
|
|
'value' => function ($model) { |
43
|
|
|
$aliases = (array)$model->getAttribute('aliases'); |
44
|
|
|
|
45
|
|
|
$html = Html::a($model->domain, ['view', 'id' => $model->id], ['class' => 'bold']) . ' '; |
46
|
|
|
$html .= ArraySpoiler::widget([ |
47
|
|
|
'data' => $aliases, |
48
|
|
|
'visibleCount' => 0, |
49
|
|
|
'delimiter' => '<br />', |
50
|
|
|
'button' => [ |
51
|
|
|
'label' => Yii::t('app', '+{0, plural, one{# alias} other{# aliases}}', count($aliases)), |
|
|
|
|
52
|
|
|
'class' => 'badge progress-bar-info', |
53
|
|
|
'popoverOptions' => ['html' => true], |
54
|
|
|
], |
55
|
|
|
'formatter' => function ($value, $key) { |
56
|
|
|
return Html::a($value, ['view', 'id' => $key]); |
57
|
|
|
}, |
58
|
|
|
]); |
59
|
|
|
|
60
|
|
|
return $html; |
61
|
|
|
} |
62
|
|
|
], |
63
|
|
|
'account' => [ |
64
|
|
|
'class' => AccountColumn::class |
65
|
|
|
], |
66
|
|
|
'server' => [ |
67
|
|
|
'class' => ServerColumn::class |
68
|
|
|
], |
69
|
|
|
'ip' => [ |
70
|
|
|
'enableSorting' => false, |
71
|
|
|
'filter' => false, |
72
|
|
|
'format' => 'raw', |
73
|
|
|
'value' => function ($model) { |
74
|
|
|
$vhost = $model->getAttribute('vhost'); |
75
|
|
|
|
76
|
|
|
$html = $vhost['ip']; |
77
|
|
|
if (isset($vhost['port']) && $vhost['port'] !== 80) { |
78
|
|
|
$html .= ':' . $vhost['port']; |
79
|
|
|
} |
80
|
|
|
if ($model->isProxied) { |
81
|
|
|
$backend = $vhost['backend']; |
82
|
|
|
$html .= ' ' . Html::tag('i', '', ['class' => 'fa fa-long-arrow-right']) . ' ' . $backend['ip']; |
83
|
|
|
if ($backend['port'] !== 80) { |
84
|
|
|
$html .= ':' . $backend['port']; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
return $html; |
88
|
|
|
} |
89
|
|
|
], |
90
|
|
|
'service' => [ |
91
|
|
|
'label' => Yii::t('app', 'Service'), |
92
|
|
|
'value' => function ($model) { |
93
|
|
|
return $model->getAttribute('vhost')['service']; |
94
|
|
|
} |
95
|
|
|
], |
96
|
|
|
'state' => [ |
97
|
|
|
'class' => RefColumn::class, |
98
|
|
|
'i18nDictionary' => 'hipanel/hosting', |
99
|
|
|
'format' => 'raw', |
100
|
|
|
'value' => function ($model) { |
101
|
|
|
$html = ''; |
102
|
|
|
if ($model->dns_on && empty($model->dns_hdomain_id)) { |
103
|
|
|
$html .= Label::widget([ |
104
|
|
|
'color' => 'success', |
105
|
|
|
'label' => Yii::t('app', 'DNS'), |
106
|
|
|
'tag' => 'span', |
107
|
|
|
'labelOptions' => ['title' => Yii::t('app', 'DNS is enabled')], |
108
|
|
|
]); |
109
|
|
|
} |
110
|
|
|
$html .= ' ' . State::widget(compact('model')); |
111
|
|
|
return $html; |
112
|
|
|
}, |
113
|
|
|
'gtype' => 'state,hdomain', |
114
|
|
|
], |
115
|
|
|
'dns_on' => [ |
116
|
|
|
'format' => 'raw', |
117
|
|
|
'value' => function ($model) { |
118
|
|
|
return $model->dns_on ? Yii::t('hipanel', 'Enabled') : Yii::t('hipanel', 'Disabled'); |
119
|
|
|
} |
120
|
|
|
], |
121
|
|
|
'dns_switch' => [ |
122
|
|
|
'attribute' => 'dns_on', |
123
|
|
|
'label' => Yii::t('hipanel/hosting', 'DNS'), |
124
|
|
|
'format' => 'raw', |
125
|
|
|
'value' => function ($model) { |
126
|
|
|
if (empty($model->dns_hdomain_id)) { |
127
|
|
|
return Yii::createObject([ |
128
|
|
|
'class' => XEditable::className(), |
129
|
|
|
'model' => $model, |
130
|
|
|
'attribute' => 'dns_on', |
131
|
|
|
'pluginOptions' => [ |
132
|
|
|
'type' => 'select', |
133
|
|
|
'title' => Yii::t('hipanel/hosting', 'Toggles DNS records upload on NS server'), |
134
|
|
|
'source' => ['' => Yii::t('hipanel', 'Disabled'), '1' => Yii::t('hipanel', 'Enabled')], |
135
|
|
|
'url' => Url::to('set-dns-on'), |
136
|
|
|
'placement' => 'bottom', |
137
|
|
|
], |
138
|
|
|
'linkOptions' => [ |
139
|
|
|
'style' => ['word-break' => 'break-all'], |
140
|
|
|
], |
141
|
|
|
])->run(); |
142
|
|
|
} else { |
143
|
|
|
return Yii::t('hipanel/hosting', 'Belongs to {link}', [ |
144
|
|
|
'link' => Html::a($model->dns_hdomain_domain, Url::to(['@hdomain/view', 'id' => $model->dns_hdomain_id])) |
145
|
|
|
]); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
], |
149
|
|
|
'aliases' => [ |
150
|
|
|
'label' => Yii::t('app', 'Aliases'), |
151
|
|
|
'format' => 'raw', |
152
|
|
|
'value' => function ($model) { |
153
|
|
|
return ArraySpoiler::widget([ |
154
|
|
|
'data' => (array)$model->getAttribute('aliases'), |
155
|
|
|
'delimiter' => '<br />', |
156
|
|
|
'button' => ['popoverOptions' => ['html' => true]], |
157
|
|
|
]); |
158
|
|
|
} |
159
|
|
|
], |
160
|
|
|
'backups_widget' => [ |
161
|
|
|
'label' => Yii::t('hipanel/hosting', 'Backups'), |
162
|
|
|
'format' => 'raw', |
163
|
|
|
'value' => function ($model) { |
164
|
|
|
return BackupGridRow::widget(['model' => $model]); |
165
|
|
|
}, |
166
|
|
|
], |
167
|
|
|
'actions' => [ |
168
|
|
|
'class' => ActionColumn::class, |
169
|
|
|
'template' => '{view} {delete}' |
170
|
|
|
], |
171
|
|
|
]; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
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: