|
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\ActionColumn; |
|
14
|
|
|
use hipanel\grid\MainColumn; |
|
15
|
|
|
use hipanel\grid\RefColumn; |
|
16
|
|
|
use hipanel\modules\hosting\models\Mail; |
|
17
|
|
|
use hipanel\modules\hosting\widgets\mail\State; |
|
18
|
|
|
use hipanel\modules\hosting\widgets\mail\Type; |
|
19
|
|
|
use hipanel\modules\server\grid\ServerColumn; |
|
20
|
|
|
use hipanel\widgets\ArraySpoiler; |
|
21
|
|
|
use hipanel\widgets\Label; |
|
22
|
|
|
use Yii; |
|
23
|
|
|
use yii\helpers\Html; |
|
24
|
|
|
|
|
25
|
|
|
class MailGridView extends \hipanel\grid\BoxedGridView |
|
26
|
|
|
{ |
|
27
|
|
|
public function columns() |
|
28
|
|
|
{ |
|
29
|
|
|
return array_merge(parent::columns(), [ |
|
30
|
|
|
'mail' => [ |
|
31
|
|
|
'class' => MainColumn::class, |
|
32
|
|
|
'filterAttribute' => 'mail_like', |
|
33
|
|
|
], |
|
34
|
|
|
'state' => [ |
|
35
|
|
|
'class' => RefColumn::class, |
|
36
|
|
|
'i18nDictionary' => 'hipanel:hosting', |
|
37
|
|
|
'format' => 'raw', |
|
38
|
|
|
'value' => function ($model) { |
|
39
|
|
|
return State::widget(compact('model')); |
|
40
|
|
|
}, |
|
41
|
|
|
'gtype' => 'state,mail', |
|
42
|
|
|
], |
|
43
|
|
|
'server' => [ |
|
44
|
|
|
'class' => ServerColumn::class, |
|
45
|
|
|
], |
|
46
|
|
|
'du_limit' => [ |
|
47
|
|
|
'attribute' => 'du_limit', |
|
48
|
|
|
'format' => 'html', |
|
49
|
|
|
'value' => function ($model) { |
|
50
|
|
|
return !empty($model->du_limit) ? $model->du_limit . 'MB' : ''; |
|
51
|
|
|
}, |
|
52
|
|
|
], |
|
53
|
|
|
'domain' => [ |
|
54
|
|
|
'attribute' => 'hdomain_id', |
|
55
|
|
|
'format' => 'raw', |
|
56
|
|
|
'value' => function ($model) { |
|
57
|
|
|
return Html::a($model->domain, ['@hdomain/view', 'id' => $model->hdomain_id]); |
|
58
|
|
|
}, |
|
59
|
|
|
], |
|
60
|
|
|
'type' => [ |
|
61
|
|
|
'format' => 'raw', |
|
62
|
|
|
'filter' => function ($column, $model, $attribute) { |
|
63
|
|
|
return Html::activeDropDownList($model, $attribute, ['' => '----------'] + Mail::getTypes(), [ |
|
64
|
|
|
'class' => 'form-control', |
|
65
|
|
|
]); |
|
66
|
|
|
}, |
|
67
|
|
|
'value' => function ($model) { |
|
68
|
|
|
return Type::widget(['model' => $model, 'label' => $model->type]); |
|
69
|
|
|
}, |
|
70
|
|
|
], |
|
71
|
|
|
'forwards' => [ |
|
72
|
|
|
'format' => 'raw', |
|
73
|
|
|
'value' => function ($model) { |
|
74
|
|
|
return ArraySpoiler::widget([ |
|
75
|
|
|
'delimiter' => '<br>', |
|
76
|
|
|
'visibleCount' => 2, |
|
77
|
|
|
'data' => $model->forwards, |
|
78
|
|
|
'button' => [ |
|
79
|
|
|
'label' => '+{count}', |
|
80
|
|
|
'popoverOptions' => ['html' => true], |
|
81
|
|
|
], |
|
82
|
|
|
]); |
|
83
|
|
|
}, |
|
84
|
|
|
], |
|
85
|
|
|
'account' => ['class' => AccountColumn::class], |
|
86
|
|
|
'spam_action' => [ |
|
87
|
|
|
'format' => 'raw', |
|
88
|
|
|
'value' => function ($model) { |
|
89
|
|
|
/** @var $model Mail */ |
|
90
|
|
|
if ($model->spam_action === $model::SPAM_ACTION_DELETE) { |
|
|
|
|
|
|
91
|
|
|
return Label::widget([ |
|
92
|
|
|
'color' => 'danger', |
|
93
|
|
|
'label' => Yii::t('hipanel', 'Delete'), |
|
94
|
|
|
]); |
|
95
|
|
|
} elseif ($model->spam_action === '') { |
|
|
|
|
|
|
96
|
|
|
return Label::widget([ |
|
97
|
|
|
'color' => 'info', |
|
98
|
|
|
'label' => Yii::t('hipanel:hosting', 'Do nothing'), |
|
99
|
|
|
]); |
|
100
|
|
|
} else { |
|
101
|
|
|
return Label::widget([ |
|
102
|
|
|
'color' => 'primary', |
|
103
|
|
|
'label' => Yii::t('hipanel:hosting', 'Forward to'), |
|
104
|
|
|
]) . ' ' . ArraySpoiler::widget([ |
|
105
|
|
|
'data' => $model->spam_action, |
|
|
|
|
|
|
106
|
|
|
'visibleCount' => 2, |
|
107
|
|
|
]); |
|
108
|
|
|
} |
|
109
|
|
|
}, |
|
110
|
|
|
], |
|
111
|
|
|
'actions' => [ |
|
112
|
|
|
'class' => ActionColumn::class, |
|
113
|
|
|
'template' => '{view} {delete}', |
|
114
|
|
|
], |
|
115
|
|
|
]); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.