/
Client.php
161 lines (139 loc) · 4.95 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* BoxBilling
*
* @copyright BoxBilling, Inc (http://www.boxbilling.com)
* @license Apache-2.0
*
* Copyright BoxBilling, Inc
* This source file is subject to the Apache-2.0 License that is bundled
* with this source code in the file LICENSE
*/
/**
* Client support tickets management
*/
namespace Box\Mod\Support\Api;
class Client extends \Api_Abstract
{
/**
* Get client tickets list
*
* @optional string status - filter tickets by status
* @optional string date_from - show tickets created since this day. Can be any string parsable by strtotime()
* @optional string date_to - show tickets created until this day. Can be any string parsable by strtotime()
*
* @return array
*/
public function ticket_get_list($data)
{
$identity = $this->getIdentity();
$data['client_id'] = $identity->id;
list($sql, $bindings) = $this->getService()->getSearchQuery($data);
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
$pager = $this->di['pager']->getAdvancedResultSet($sql, $bindings, $per_page);
foreach($pager['list'] as $key => $ticketArr){
$ticket = $this->di['db']->getExistingModelById('SupportTicket', $ticketArr['id'], 'Ticket not found');
$pager['list'][$key] = $this->getService()->toApiArray($ticket, true, $this->getIdentity());
}
return $pager;
}
/**
* Return ticket full details
*
* @param int $id - ticket id
*
* @return array
*/
public function ticket_get($data)
{
$required = array(
'id' => 'Ticket id required',
);
$this->di['validator']->checkRequiredParamsForArray($required, $data);
$ticket = $this->getService()->findOneByClient($this->getIdentity(), $data['id']);
return $this->getService()->toApiArray($ticket);
}
/**
* Return pairs for support helpdesk. Can be used to populate select box.
*
* @return array
*/
public function helpdesk_get_pairs()
{
return $this->getService()->helpdeskGetPairs();
}
/**
* Method to create open new ticket. Tickets can have tasks assigned to them
* via optional parameters.
*
* @param string $content - ticket message content
* @param string $subject - ticket subject
* @param string $support_helpdesk_id - Ticket helpdesk id.
*
* @optional int $rel_type - Ticket relation type
* @optional int $rel_id - Ticket relation id
* @optional int $rel_task - Ticket task codename
* @optional int $rel_new_value - Task can have new value assigned.
*
* @return int $id - ticket id
*/
public function ticket_create($data)
{
$required = array(
'content' => 'Ticket content required',
'subject' => 'Ticket subject required',
'support_helpdesk_id' => 'Ticket support_helpdesk_id required',
);
$this->di['validator']->checkRequiredParamsForArray($required, $data);
$helpdesk = $this->di['db']->getExistingModelById('SupportHelpdesk', $data['support_helpdesk_id'], 'Helpdesk invalid');
$client = $this->getIdentity();
return $this->getService()->ticketCreateForClient($client, $helpdesk, $data);
}
/**
* Add new conversation message to ticket. Ticket will be reopened if closed
*
* @param int $id - ticket id
* @param string $content - ticket message
*
* @return bool
*/
public function ticket_reply($data)
{
$required = array(
'id' => 'Ticket ID required',
'content' => 'Ticket content required',
);
$this->di['validator']->checkRequiredParamsForArray($required, $data);
$client = $this->getIdentity();
$bindings = array(
':id' => $data['id'],
':client_id' => $client->id
);
$ticket = $this->di['db']->findOne('SupportTicket', 'id = :id AND client_id = :client_id', $bindings);
if (!$ticket instanceof \Model_SupportTicket){
throw new \Box_Exception('Ticket not found');
}
if (!$this->getService()->canBeReopened($ticket)) {
throw new \Box_Exception('Ticket can not be reopened.');
}
$result = $this->getService()->ticketReply($ticket, $client, $data['content']);
return ($result > 0) ? true : false;
}
/**
* Close ticket
*
* @param int $id - ticket id
*
* @return boolean
*/
public function ticket_close($data)
{
$required = array(
'id' => 'Ticket ID required',
);
$this->di['validator']->checkRequiredParamsForArray($required, $data);
$client = $this->getIdentity();
$ticket = $this->getService()->findOneByClient($client, $data['id']);
return $this->getService()->closeTicket($ticket, $this->getIdentity());
}
}