PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.5
Fluent Support – Helpdesk & Customer Support Ticket System v2.4.5
2.4.5 2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 All 69 releases
fluent-support / app / Api / Classes / Tickets.php

Tickets.php in Fluent Support – Helpdesk & Customer Support Ticket System 2.4.5, at app/Api/Classes/Tickets.php

138 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Api\Classes;
4
5 use FluentSupport\App\Models\Agent;
6 use FluentSupport\App\Models\Customer;
7 use FluentSupport\App\Models\Ticket;
8 use FluentSupport\App\Services\Tickets\ResponseService;
9 use FluentSupport\App\Services\Tickets\TicketService;
10
11 /**
12 * Tickets PHP API.
13 *
14 * Example Usage: $ticketsApi = FluentSupportApi('tickets');
15 */
16 class Tickets
17 {
18 private $instance = null;
19
20 private $allowedInstanceMethods = [
21 'all',
22 'get',
23 'find',
24 'first',
25 'paginate'
26 ];
27
28 public function __construct(Ticket $instance)
29 {
30 $this->instance = $instance;
31 }
32
33 /**
34 * Paginated tickets, newest first.
35 *
36 * @return object
37 */
38 public function getTickets()
39 {
40 $ticketsQuery = Ticket::with([
41 'customer' => function ($query) {
42 $query->select(['first_name', 'last_name', 'id', 'email']);
43 }, 'agent' => function ($query) {
44 $query->select(['first_name', 'last_name', 'id', 'email']);
45 }
46 ])
47 ->orderBy('id', 'DESC');
48 $tickets = $ticketsQuery->paginate();
49
50 if (defined('FLUENTSUPPORTPRO')) {
51 foreach ($tickets as $ticket) {
52 $ticket->custom_fields = $ticket->customData();
53 }
54 }
55
56 return $tickets;
57 }
58
59 /**
60 * @param int $id
61 * @return object|false
62 */
63
64 public function getTicket(int $id)
65 {
66 if (is_numeric($id)) {
67 $ticket = Ticket::findOrFail($id);
68 if (defined('FLUENTSUPPORTPRO')) {
69 $ticket->custom_fields = $ticket->customData();
70 }
71 return $ticket;
72 }
73 return false;
74 }
75
76 /**
77 * @param array $data
78 * @param int $agentId
79 * @param int $ticketId
80 * @return array|boolean
81 */
82
83 public function addResponse(array $data, int $agentId, int $ticketId)
84 {
85 if (!$agentId || !$ticketId || !$data['content']) {
86 return false;
87 }
88
89 $agent = Agent::findOrFail($agentId);
90 $ticket = Ticket::findOrFail($ticketId);
91
92 if ($agent && $ticket) {
93 return (new ResponseService())->createResponse($data, $agent, $ticket);
94 }
95 return false;
96 }
97
98 /**
99 * @param array $data
100 * @return object|false
101 */
102
103 public function createTicket(array $data)
104 {
105 $customerId = $data['customer_id'] ?? null;
106
107 if (!$customerId || !($customer = Customer::find($customerId))) {
108 return false;
109 }
110
111 if (empty($data['title']) || empty($data['content'])) {
112 return false;
113 }
114
115 $createdTicket = (new TicketService())->storeTicket($data, $customer);
116
117 if (defined('FLUENTSUPPORTPRO')) {
118 $createdTicket->custom_fields = $createdTicket->customData();
119 }
120
121 return $createdTicket;
122 }
123
124 public function getInstance()
125 {
126 return $this->instance;
127 }
128
129 public function __call($method, $params)
130 {
131 if (in_array($method, $this->allowedInstanceMethods)) {
132 return call_user_func_array([$this->instance, $method], $params);
133 }
134
135 throw new \Exception(sprintf("Method %s does not exist.", esc_html($method)));
136 }
137 }
138