PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.5.4
Fluent Support – Helpdesk & Customer Support Ticket System v1.5.4
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 1.5.5 All 68 releases
fluent-support / app / Api / Classes / Tickets.php

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

133 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
10 class Tickets
11 {
12 private $instance = null;
13
14 private $allowedInstanceMethods = [
15 'all',
16 'get',
17 'find',
18 'first',
19 'paginate'
20 ];
21
22 public function __construct(Ticket $instance)
23 {
24 $this->instance = $instance;
25 }
26
27 /**
28 * getTickets method will return all tickets
29 *
30 * @return object
31 */
32 public function getTickets()
33 {
34 $ticketsQuery = Ticket::with([
35 'customer' => function ($query) {
36 $query->select(['first_name', 'last_name', 'id', 'email']);
37 }, 'agent' => function ($query) {
38 $query->select(['first_name', 'last_name', 'id', 'email']);
39 }
40 ])
41 ->orderBy('id', 'DESC');
42 $tickets = $ticketsQuery->paginate();
43
44 if (defined('FLUENTSUPPORTPRO')){
45 foreach ($tickets as $ticket) {
46 $ticket->custom_fields = $ticket->customData();
47 }
48 }
49
50 return $tickets;
51 }
52
53 /**
54 * getTicket method will return a specific ticket by id
55 * @param int $id
56 */
57
58 public function getTicket(int $id)
59 {
60 if (is_numeric($id)) {
61 $ticket = Ticket::findOrFail($id);
62 if (defined('FLUENTSUPPORTPRO')){
63 $ticket->custom_fields = $ticket->customData();
64 }
65 return $ticket;
66 }
67 return false;
68 }
69
70 /**
71 * addResponse method add response to a ticket
72 * @param array $data
73 * @param int $agentId
74 * @param int $ticketId
75 */
76
77 public function addResponse(array $data, int $agentId, int $ticketId)
78 {
79 if(!$agentId || !$ticketId || !$data['content']){
80 return false;
81 }
82
83 $agent = Agent::findOrFail($agentId);
84 $ticket = Ticket::findOrFail($ticketId);
85
86 if($agent && $ticket){
87 return (new ResponseService())->createResponse($data, $agent, $ticket);
88 }
89 return false;
90 }
91
92 /**
93 * createTicket method will create a new ticket
94 * @param array $data
95 * @return object
96 */
97
98 public function createTicket(array $data)
99 {
100 if(!$data['customer_id'] || !Customer::findOrFail($data['customer_id'])) {
101 return false;
102 }
103
104 if (!$data['title'] || !$data['content']) {
105 return false;
106 }
107
108 $createdTicket = Ticket::create($data);
109
110 if (defined('FLUENTSUPPORTPRO') && !empty($data['custom_fields'])) {
111 $createdTicket->syncCustomFields($data['custom_fields']);
112 $createdTicket->custom_fields = $createdTicket->customData();
113 }
114
115 return $createdTicket;
116
117 }
118
119 public function getInstance()
120 {
121 return $this->instance;
122 }
123
124 public function __call($method, $params)
125 {
126 if (in_array($method, $this->allowedInstanceMethods)) {
127 return call_user_func_array([$this->instance, $method], $params);
128 }
129
130 throw new \Exception("Method {$method} does not exist.");
131 }
132 }
133