1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* HiPanel tickets module |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hipanel-module-ticket |
7
|
|
|
* @package hipanel-module-ticket |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\modules\ticket\grid; |
13
|
|
|
|
14
|
|
|
use hipanel\grid\ActionColumn; |
15
|
|
|
use hipanel\grid\BoxedGridView; |
16
|
|
|
use hipanel\modules\client\grid\ClientColumn; |
17
|
|
|
use hipanel\modules\ticket\assets\ThreadListCheckerAsset; |
18
|
|
|
use hipanel\modules\ticket\menus\TicketActionsMenu; |
19
|
|
|
use hipanel\modules\ticket\models\Thread; |
20
|
|
|
use hipanel\modules\ticket\widgets\Topic; |
21
|
|
|
use hipanel\widgets\ClientSellerLink; |
22
|
|
|
use hipanel\widgets\Gravatar; |
23
|
|
|
use hiqdev\yii2\menus\grid\MenuColumn; |
24
|
|
|
use Yii; |
25
|
|
|
use yii\helpers\Html; |
26
|
|
|
use yii\helpers\Json; |
27
|
|
|
use yii\helpers\Url; |
28
|
|
|
|
29
|
|
|
class TicketGridView extends BoxedGridView |
30
|
|
|
{ |
31
|
|
|
public $enableListChecker = false; |
32
|
|
|
|
33
|
|
|
public static function defaultColumns() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
'subject' => [ |
37
|
|
|
'attribute' => 'subject', |
38
|
|
|
'format' => 'raw', |
39
|
|
|
'filterInputOptions' => ['style' => 'width:100%', 'class' => 'form-control'], |
40
|
|
|
'value' => function ($model) { |
41
|
|
|
$ava = Html::tag('div', Gravatar::widget([ |
42
|
|
|
'emailHash' => $model->author_email, |
43
|
|
|
'defaultImage' => 'identicon', |
44
|
|
|
'options' => [ |
45
|
|
|
'alt' => Yii::t('hipanel:ticket', 'Avatar for {login}', ['login' => $model->author]), |
46
|
|
|
'class' => 'img-circle', |
47
|
|
|
], |
48
|
|
|
'size' => 40, |
49
|
|
|
]), ['class' => 'pull-right']); |
50
|
|
|
|
51
|
|
|
$titleLink = [ |
52
|
|
|
Html::a($model->subject, $model->threadUrl, [ |
53
|
|
|
'class' => 'text-bold', |
54
|
|
|
'style' => $model->state === Thread::STATE_CLOSE ? 'color: black !important;' : '', |
55
|
|
|
]), |
56
|
|
|
Topic::widget(['topics' => $model->topics]), |
57
|
|
|
Html::tag( |
58
|
|
|
'div', |
59
|
|
|
sprintf('#%s %s %s', |
60
|
|
|
$model->id, |
61
|
|
|
Html::tag('span', Yii::t('hipanel:ticket', $model->state_label), ['class' => 'text-bold']), |
62
|
|
|
Yii::$app->formatter->asDatetime($model->create_time) |
63
|
|
|
), |
64
|
|
|
['class' => 'text-muted'] |
65
|
|
|
), |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
return $ava . Html::tag('div', implode('', $titleLink)); |
69
|
|
|
}, |
70
|
|
|
], |
71
|
|
|
'author_id' => [ |
72
|
|
|
'class' => ClientColumn::class, |
73
|
|
|
'label' => Yii::t('hipanel:ticket', 'Author'), |
74
|
|
|
'idAttribute' => 'author_id', |
75
|
|
|
'sortAttribute' => 'author', |
76
|
|
|
'attribute' => 'author_id', |
77
|
|
|
'value' => function ($model) { |
78
|
|
|
return ClientSellerLink::widget(compact('model')); |
79
|
|
|
}, |
80
|
|
|
], |
81
|
|
|
'responsible_id' => [ |
82
|
|
|
'class' => ClientColumn::class, |
83
|
|
|
'idAttribute' => 'responsible_id', |
84
|
|
|
'sortAttribute' => 'responsible', |
85
|
|
|
'attribute' => 'responsible_id', |
86
|
|
|
'clientType' => ['admin', 'seller', 'manager'], |
87
|
|
|
'value' => function ($model) { |
88
|
|
|
return Html::a($model['responsible'], ['/client/client/view', 'id' => $model->responsible_id]); |
89
|
|
|
}, |
90
|
|
|
'visible' => Yii::$app->user->can('support'), |
91
|
|
|
], |
92
|
|
|
'recipient_id' => [ |
93
|
|
|
'class' => ClientColumn::class, |
94
|
|
|
'idAttribute' => 'recipient_id', |
95
|
|
|
'label' => Yii::t('hipanel:ticket', 'Recipient'), |
96
|
|
|
'sortAttribute' => 'recipient', |
97
|
|
|
'attribute' => 'recipient_id', |
98
|
|
|
'value' => function ($model) { |
99
|
|
|
return Html::a($model->recipient, ['/client/client/view', 'id' => $model->recipient_id]); |
100
|
|
|
|
101
|
|
|
}, |
102
|
|
|
'visible' => Yii::$app->user->can('support'), |
103
|
|
|
], |
104
|
|
|
'answer_count' => [ |
105
|
|
|
'attribute' => 'answer_count', |
106
|
|
|
'label' => Yii::t('hipanel:ticket', 'Answers'), |
107
|
|
|
'format' => 'raw', |
108
|
|
|
'filter' => false, |
109
|
|
|
'enableSorting' => false, |
110
|
|
|
'value' => function ($model) { |
111
|
|
|
$lastAnswer = [ |
112
|
|
|
ClientSellerLink::widget([ |
113
|
|
|
'model' => $model, |
114
|
|
|
'clientAttribute' => 'replier', |
115
|
|
|
'clientIdAttribute' => 'replier_id', |
116
|
|
|
'sellerAttribute' => false, |
117
|
|
|
]), '<br>', |
118
|
|
|
|
119
|
|
|
Html::tag('span', Yii::$app->formatter->asRelativeTime($model->reply_time), [ |
120
|
|
|
'style' => 'font-size: smaller;white-space: nowrap;', |
121
|
|
|
'class' => 'text-muted', |
122
|
|
|
]), ' ', |
123
|
|
|
|
124
|
|
|
Html::tag('span', $model->answer_count, [ |
125
|
|
|
'class' => 'label label-default', |
126
|
|
|
'title' => Yii::t('hipanel:ticket', |
127
|
|
|
'Ticket contains {n, plural, one{# answer} other{# answers}}', |
128
|
|
|
['n' => $model->answer_count] |
129
|
|
|
), |
130
|
|
|
]) |
131
|
|
|
]; |
132
|
|
|
|
133
|
|
|
return implode('', $lastAnswer); |
134
|
|
|
}, |
135
|
|
|
'contentOptions' => [ |
136
|
|
|
'class' => 'answer', |
137
|
|
|
], |
138
|
|
|
], |
139
|
|
|
'actions' => [ |
140
|
|
|
'class' => MenuColumn::class, |
141
|
|
|
'menuClass' => TicketActionsMenu::class, |
142
|
|
|
], |
143
|
|
|
]; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function run() |
147
|
|
|
{ |
148
|
|
|
if ($this->enableListChecker) { |
149
|
|
|
ThreadListCheckerAsset::register($this->view); |
150
|
|
|
$options = Json::encode(['pjaxSelector' => '#' . Yii::$app->params['pjax']['id']]); |
151
|
|
|
$this->view->registerJs("$('#{$this->id}').threadListChecker($options);"); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
parent::run(); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|