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\widgets\combo; |
12
|
|
|
|
13
|
|
|
use hiqdev\combo\Combo; |
14
|
|
|
use yii\helpers\ArrayHelper; |
15
|
|
|
use yii\web\JsExpression; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Account. |
19
|
|
|
*/ |
20
|
|
|
class VhostCombo extends Combo |
21
|
|
|
{ |
22
|
|
|
/** {@inheritdoc} */ |
23
|
|
|
public $type = 'hosting/vhost'; |
24
|
|
|
|
25
|
|
|
/** {@inheritdoc} */ |
26
|
|
|
public $name = 'domain'; |
27
|
|
|
|
28
|
|
|
/** {@inheritdoc} */ |
29
|
|
|
public $url = '/hosting/vhost/search'; |
30
|
|
|
|
31
|
|
|
/** {@inheritdoc} */ |
32
|
|
|
public $_return = ['id', 'domain', 'account', 'server', 'service', 'ip', 'port']; |
33
|
|
|
|
34
|
|
|
/** {@inheritdoc} */ |
35
|
|
|
public $_rename = ['text' => 'domain']; |
36
|
|
|
|
37
|
|
|
public $activeWhen = ['server/server', 'hosting/account']; |
38
|
|
|
|
39
|
|
|
/** {@inheritdoc} */ |
40
|
|
View Code Duplication |
public function getFilter() |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
return ArrayHelper::merge(parent::getFilter(), [ |
43
|
|
|
'server' => 'server/server', |
44
|
|
|
'account' => 'hosting/account', |
45
|
|
|
'state' => ['format' => 'ok'], |
46
|
|
|
]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** {@inheritdoc} */ |
50
|
|
|
public function getPluginOptions($options = []) |
51
|
|
|
{ |
52
|
|
|
return parent::getPluginOptions([ |
53
|
|
|
'clearWhen' => ['server/server'], |
54
|
|
|
'activeWhen' => $this->activeWhen, |
55
|
|
|
'select2Options' => [ |
56
|
|
|
'templateResult' => new JsExpression("function (data) { |
57
|
|
|
if (data.loading) { |
58
|
|
|
return data.text; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return data.domain + '<br><small>' + data.service + ' - ' + data.ip + ':' + data.port + '</small>'; |
62
|
|
|
}"), |
63
|
|
|
'escapeMarkup' => new JsExpression('function (markup) { |
64
|
|
|
return markup; // Allows HTML |
65
|
|
|
}'), |
66
|
|
|
], |
67
|
|
|
]); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.