1 | <?php |
||
24 | class Thread extends \hipanel\base\Model |
||
25 | { |
||
26 | use \hipanel\base\ModelTrait; |
||
27 | |||
28 | public static $i18nDictionary = 'hipanel:ticket'; |
||
29 | |||
30 | const STATE_OPEN = 'opened'; |
||
31 | const STATE_CLOSE = 'closed'; |
||
32 | |||
33 | public $search_form; |
||
34 | |||
35 | public function init() |
||
36 | { |
||
37 | $this->on(static::EVENT_BEFORE_INSERT, [$this, 'beforeChange']); |
||
38 | $this->on(static::EVENT_BEFORE_UPDATE, [$this, 'beforeChange']); |
||
39 | } |
||
40 | |||
41 | public function beforeChange($event) |
||
|
|||
42 | { |
||
43 | $this->prepareSpentTime(); |
||
44 | $this->prepareTopic(); |
||
45 | |||
46 | return true; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return array |
||
51 | */ |
||
52 | public function behaviors() |
||
53 | { |
||
54 | return [ |
||
55 | [ |
||
56 | 'class' => File::class, |
||
57 | 'attribute' => 'file', |
||
58 | 'targetAttribute' => 'file_ids', |
||
59 | 'scenarios' => ['create', 'answer'], |
||
60 | ], |
||
61 | ]; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return array |
||
66 | */ |
||
67 | public function attributes() |
||
68 | { |
||
69 | return [ |
||
70 | 'id', |
||
71 | 'subject', |
||
72 | 'state', |
||
73 | 'state_label', |
||
74 | 'author_email', |
||
75 | 'author', |
||
76 | 'author_id', |
||
77 | 'responsible_id', |
||
78 | 'responsible_email', |
||
79 | 'author_seller', |
||
80 | 'author_seller_id', |
||
81 | 'recipient_id', |
||
82 | 'recipient', |
||
83 | 'recipient_seller', |
||
84 | 'recipient_seller_id', |
||
85 | 'replier_id', |
||
86 | 'replier', |
||
87 | 'replier_seller', |
||
88 | 'replier_name', |
||
89 | 'responsible', |
||
90 | 'priority', |
||
91 | 'priority_label', |
||
92 | 'spent', 'spent_hours', |
||
93 | 'answer_count', |
||
94 | 'status', |
||
95 | 'reply_time', |
||
96 | 'create_time', |
||
97 | 'a_reply_time', |
||
98 | 'elapsed', |
||
99 | 'topics', |
||
100 | 'topic', |
||
101 | 'watchers', |
||
102 | 'watcher', |
||
103 | 'add_tag_ids', |
||
104 | 'file_ids', |
||
105 | 'file', |
||
106 | 'message', // 'answer_message', |
||
107 | 'is_private', |
||
108 | |||
109 | 'anonym_name', |
||
110 | 'anonym_email', |
||
111 | 'anonym_seller', |
||
112 | |||
113 | 'lastanswer', |
||
114 | 'time', |
||
115 | 'add_watchers', 'del_watchers', |
||
116 | |||
117 | 'time_from', |
||
118 | 'time_till', |
||
119 | |||
120 | 'contact', |
||
121 | ]; |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function rules() |
||
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | public function attributeLabels() |
||
177 | { |
||
178 | return $this->mergeAttributeLabels([ |
||
179 | 'author' => Yii::t('hipanel:ticket', 'Author'), |
||
180 | 'author_id' => Yii::t('hipanel:ticket', 'Author'), |
||
181 | 'recipient' => Yii::t('hipanel:ticket', 'Recipient'), |
||
182 | 'is_private' => Yii::t('hipanel:ticket', 'Make private'), |
||
183 | 'responsible' => Yii::t('hipanel:ticket', 'Assignee'), |
||
184 | 'responsible_id' => Yii::t('hipanel:ticket', 'Assignee'), |
||
185 | 'spent' => Yii::t('hipanel:ticket', 'Spent time'), |
||
186 | 'create_time' => Yii::t('hipanel:ticket', 'Created'), |
||
187 | 'a_reply_time' => Yii::t('hipanel:ticket', 'a_reply_time'), |
||
188 | 'file' => Yii::t('hipanel:ticket', 'Files'), |
||
189 | 'lastanswer' => Yii::t('hipanel:ticket', 'Last answer'), |
||
190 | 'author_seller' => Yii::t('hipanel:ticket', 'Seller'), |
||
191 | ]); |
||
192 | } |
||
193 | |||
194 | public function getClient() |
||
198 | |||
199 | public function getClient_id() |
||
200 | { |
||
201 | return $this->author_id; |
||
202 | } |
||
203 | |||
204 | public function getSeller() |
||
208 | |||
209 | public function getSeller_id() |
||
210 | { |
||
211 | return $this->author_seller_id; |
||
212 | } |
||
213 | |||
214 | public function getThreadUrl() |
||
218 | |||
219 | public static function parseMessage($message) |
||
226 | |||
227 | public function prepareSpentTime() |
||
231 | |||
232 | public function prepareTopic() |
||
236 | |||
237 | public function getWatchersLogin() |
||
247 | |||
248 | public function xFormater(array $items) |
||
260 | |||
261 | public function getAnswers() |
||
266 | |||
267 | /** |
||
268 | * Returns array of client types, that can be set as responsible for the thread. |
||
269 | * |
||
270 | * @return array |
||
271 | */ |
||
272 | public static function getResponsibleClientTypes() |
||
273 | { |
||
274 | return [Client::TYPE_SELLER, Client::TYPE_ADMIN, Client::TYPE_MANAGER, Client::TYPE_OWNER]; |
||
275 | } |
||
276 | |||
277 | /** |
||
278 | * @param integer $id |
||
279 | * @param bool $throwOnError whether to throw an exception when answer is not found in thread |
||
280 | * @throws NotFoundHttpException |
||
281 | * @return Answer |
||
282 | */ |
||
283 | public function getAnswer($id, $throwOnError = true) |
||
284 | { |
||
285 | if (!isset($this->answers[$id]) && $throwOnError) { |
||
286 | throw new NotFoundHttpException('Answer does not belong to this model'); |
||
287 | } |
||
288 | |||
289 | return $this->answers[$id]; |
||
290 | } |
||
291 | |||
292 | public function getMaxAnswerId() |
||
300 | |||
301 | public function scenarioActions() |
||
302 | { |
||
303 | return [ |
||
304 | 'open' => 'answer', |
||
305 | 'close' => 'answer', |
||
306 | ]; |
||
307 | } |
||
308 | } |
||
309 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.