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-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @see http://hiqdev.com/hipanel-module-hosting |
13
|
|
|
* @license http://hiqdev.com/hipanel-module-hosting/license |
14
|
|
|
* @copyright Copyright (c) 2015 HiQDev |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace hipanel\modules\hosting\grid; |
18
|
|
|
|
19
|
|
|
use hipanel\grid\MainColumn; |
20
|
|
|
use hipanel\helpers\Url; |
21
|
|
|
use hipanel\modules\server\grid\ServerColumn; |
22
|
|
|
use hipanel\widgets\obj\ObjLabelWidget; |
23
|
|
|
use hipanel\widgets\obj\ObjLinkWidget; |
24
|
|
|
use hiqdev\xeditable\widgets\XEditable; |
25
|
|
|
use Yii; |
26
|
|
|
use yii\helpers\Html; |
27
|
|
|
|
28
|
|
|
class BackupingGridView extends \hipanel\grid\BoxedGridView |
29
|
|
|
{ |
30
|
|
|
public $typeOptions = []; |
31
|
|
|
|
32
|
|
|
public function init() |
33
|
|
|
{ |
34
|
|
|
parent::init(); |
35
|
|
|
$controller = Yii::$app->controller; |
36
|
|
|
if (empty($this->typeOptions) && method_exists($controller, 'getTypeOptions')) { |
37
|
|
|
$this->typeOptions = (array) $controller->getTypeOptions(); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getTypeOptions() |
42
|
|
|
{ |
43
|
|
|
$result = []; |
44
|
|
|
foreach ($this->typeOptions as $key => $value) { |
45
|
|
|
$result[$key] = Yii::t('hipanel:hosting:backuping:periodicity', $value); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $result; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function columns() |
52
|
|
|
{ |
53
|
|
|
$typeOptions = $this->getTypeOptions(); |
54
|
|
|
|
55
|
|
|
return array_merge(parent::columns(), [ |
56
|
|
|
'name' => [ |
57
|
|
|
'class' => MainColumn::class, |
58
|
|
|
'filterAttribute' => 'name_like', |
59
|
|
|
'format' => 'html', |
60
|
|
|
'value' => function ($model) { |
61
|
|
|
return Html::a($model->name, ['@' . $model->object . '/view', 'id' => $model->id], ['class' => 'bold']); |
62
|
|
|
}, |
63
|
|
|
], |
64
|
|
|
'main' => [ |
65
|
|
|
'attribute' => 'name', |
66
|
|
|
'filterAttribute' => 'name_like', |
67
|
|
|
'format' => 'raw', |
68
|
|
View Code Duplication |
'value' => function ($model) { |
|
|
|
|
69
|
|
|
return Html::a($model->name, ['@backuping/view', 'id' => $model->id], ['class' => 'bold']) . ' ' . |
70
|
|
|
ObjLinkWidget::widget(['model' => $model->getObj()]); |
71
|
|
|
}, |
72
|
|
|
], |
73
|
|
|
'account' => [ |
74
|
|
|
'attribute' => 'account_id', |
75
|
|
|
'class' => AccountColumn::class, |
76
|
|
|
], |
77
|
|
|
'server' => [ |
78
|
|
|
'attribute' => 'server_id', |
79
|
|
|
'class' => ServerColumn::class, |
80
|
|
|
], |
81
|
|
|
'object' => [ |
82
|
|
|
'filter' => false, |
83
|
|
|
'format' => 'raw', |
84
|
|
|
'value' => function ($model) { |
85
|
|
|
return ObjLabelWidget::widget(['model' => $model->getObj()]); |
86
|
|
|
}, |
87
|
|
|
], |
88
|
|
|
'backup_count' => [ |
89
|
|
|
'filter' => false, |
90
|
|
|
], |
91
|
|
|
'type' => [ |
92
|
|
|
'attribute' => 'type', |
93
|
|
|
'format' => 'raw', |
94
|
|
|
'filter' => false, |
95
|
|
|
'enableSorting' => false, |
96
|
|
|
'value' => function ($model) use ($typeOptions) { |
97
|
|
|
return XEditable::widget([ |
98
|
|
|
'model' => $model, |
99
|
|
|
'attribute' => 'type', |
100
|
|
|
'pluginOptions' => [ |
101
|
|
|
'type' => 'select', |
102
|
|
|
'source' => $typeOptions, |
103
|
|
|
'url' => Url::to('update'), |
104
|
|
|
], |
105
|
|
|
]); |
106
|
|
|
}, |
107
|
|
|
], |
108
|
|
|
'state_label' => [ |
109
|
|
|
'filter' => false, |
110
|
|
|
'enableSorting' => false, |
111
|
|
|
], |
112
|
|
|
'backup_last' => [ |
113
|
|
|
'filter' => false, |
114
|
|
|
'format' => 'raw', |
115
|
|
|
'value' => function ($model) { |
116
|
|
|
return Html::tag('nobr', Yii::$app->formatter->asDate($model->backup_last)) . ' ' . |
117
|
|
|
Html::tag('nobr', Yii::$app->formatter->asTime($model->backup_last)); |
118
|
|
|
}, |
119
|
|
|
], |
120
|
|
|
'total_du' => [ |
121
|
|
|
'filter' => false, |
122
|
|
|
'format' => 'html', |
123
|
|
|
'value' => function ($model) { |
124
|
|
|
return Yii::$app->formatter->asShortSize($model->total_du, 2); |
125
|
|
|
}, |
126
|
|
|
], |
127
|
|
|
]); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
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.