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\models; |
13
|
|
|
|
14
|
|
|
use hipanel\models\File; |
15
|
|
|
use Yii; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Ticket. |
19
|
|
|
*/ |
20
|
|
|
class Answer extends \hipanel\base\Model |
21
|
|
|
{ |
22
|
|
|
use \hipanel\base\ModelTrait; |
23
|
|
|
|
24
|
|
|
public static function index() |
25
|
|
|
{ |
26
|
|
|
return 'threads'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public static function type() |
30
|
|
|
{ |
31
|
|
|
return 'thread'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static $i18nDictionary = 'hipanel:ticket'; |
35
|
|
|
|
36
|
|
|
public function init() |
37
|
|
|
{ |
38
|
|
|
$this->on(static::EVENT_BEFORE_INSERT, [$this, 'beforeChange']); |
39
|
|
|
$this->on(static::EVENT_BEFORE_UPDATE, [$this, 'beforeChange']); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function load($data, $formName = null) |
43
|
|
|
{ |
44
|
|
|
$result = parent::load($data, $formName); |
45
|
|
|
$this->prepareSpentTime(); |
46
|
|
|
|
47
|
|
|
return $result; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function beforeChange($event) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$this->switchId(); |
53
|
|
|
|
54
|
|
|
return true; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function switchId() |
58
|
|
|
{ |
59
|
|
|
if ($this->scenario === 'update') { |
60
|
|
|
$this->id = $this->answer_id; |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function behaviors() |
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
|
|
[ |
71
|
|
|
'class' => 'hipanel\behaviors\File', |
72
|
|
|
'attribute' => 'file', |
73
|
|
|
'targetAttribute' => 'file_ids', |
74
|
|
|
'scenarios' => ['create', 'answer'], |
75
|
|
|
], |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
public function attributes() |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
'id', |
86
|
|
|
'answer_id', |
87
|
|
|
'message', |
88
|
|
|
'private', |
89
|
|
|
'is_private', |
90
|
|
|
'is_answer', |
91
|
|
|
'changed_num', |
92
|
|
|
'author', |
93
|
|
|
'author_seller', |
94
|
|
|
'email_hash', |
95
|
|
|
'create_time', |
96
|
|
|
'author_id', |
97
|
|
|
'seller_id', |
98
|
|
|
'spent', |
99
|
|
|
'spent_hours', |
100
|
|
|
'is_moved', |
101
|
|
|
'ip', |
102
|
|
|
'file', |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public function rules() |
110
|
|
|
{ |
111
|
|
|
return [ |
112
|
|
|
[ |
113
|
|
|
['id', 'answer_id', 'spent', 'spent_hours'], |
114
|
|
|
'integer', |
115
|
|
|
'enableClientValidation' => false, |
116
|
|
|
], |
117
|
|
|
[ |
118
|
|
|
['message', 'id', 'answer_id'], |
119
|
|
|
'required', |
120
|
|
|
'on' => 'update', |
121
|
|
|
], |
122
|
|
|
[ |
123
|
|
|
['spent', '!spent_hours'], |
124
|
|
|
'safe', |
125
|
|
|
'on' => 'update', |
126
|
|
|
], |
127
|
|
|
[ |
128
|
|
|
['is_private'], |
129
|
|
|
'boolean', |
130
|
|
|
'on' => 'update', |
131
|
|
|
'when' => function () { |
132
|
|
|
return Yii::$app->user->can('support'); |
133
|
|
|
}, |
134
|
|
|
], |
135
|
|
|
]; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* {@inheritdoc} |
140
|
|
|
*/ |
141
|
|
|
public function attributeLabels() |
142
|
|
|
{ |
143
|
|
|
return $this->mergeAttributeLabels([ |
144
|
|
|
'author' => Yii::t('hipanel:ticket', 'Author'), |
145
|
|
|
'author_id' => Yii::t('hipanel:ticket', 'Author'), |
146
|
|
|
'recipient' => Yii::t('hipanel:ticket', 'Recipient'), |
147
|
|
|
'is_private' => Yii::t('hipanel:ticket', 'Make private'), |
148
|
|
|
'responsible' => Yii::t('hipanel:ticket', 'Assignee'), |
149
|
|
|
'responsible_id' => Yii::t('hipanel:ticket', 'Assignee'), |
150
|
|
|
'spent' => Yii::t('hipanel:ticket', 'Spent time'), |
151
|
|
|
'create_time' => Yii::t('hipanel:ticket', 'Created'), |
152
|
|
|
'a_reply_time' => Yii::t('hipanel:ticket', 'a_reply_time'), |
153
|
|
|
'file' => Yii::t('hipanel:ticket', 'Files'), |
154
|
|
|
'lastanswer' => Yii::t('hipanel:ticket', 'Last answer'), |
155
|
|
|
'author_seller' => Yii::t('hipanel:ticket', 'Seller'), |
156
|
|
|
]); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function getClient() |
160
|
|
|
{ |
161
|
|
|
return $this->author; |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function getClient_id() |
165
|
|
|
{ |
166
|
|
|
return $this->author_id; |
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function getSeller() |
170
|
|
|
{ |
171
|
|
|
return $this->author_seller; |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function getSeller_id() |
175
|
|
|
{ |
176
|
|
|
return $this->author_seller_id; |
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function prepareSpentTime() |
180
|
|
|
{ |
181
|
|
|
list($this->spent_hours, $this->spent) = explode(':', $this->spent, 2); |
|
|
|
|
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function getThread() |
185
|
|
|
{ |
186
|
|
|
return $this->hasOne(Thread::class, ['id' => 'id']); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function getFiles() |
190
|
|
|
{ |
191
|
|
|
return $this->hasMany(File::class, ['object_id' => 'id']); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function scenarioCommands() |
195
|
|
|
{ |
196
|
|
|
return [ |
197
|
|
|
'update' => 'update-answer', |
198
|
|
|
]; |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.