PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / trunk
Fluent Support – Helpdesk & Customer Support Ticket System vtrunk
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 / Hooks / Handlers / ActivityLogger.php

ActivityLogger.php in Fluent Support – Helpdesk & Customer Support Ticket System trunk, at app/Hooks/Handlers/ActivityLogger.php

230 lines 8.3 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\Hooks\Handlers;
4
5 use FluentSupport\App\Models\Activity;
6 use FluentSupport\App\Services\Helper;
7
8 /**
9 * ActivityLogger class for Hooks
10 *
11 * @package FluentSupport\App\Hooks\Handlers
12 *
13 * @version 1.0.0
14 */
15
16 class ActivityLogger
17 {
18
19 /**
20 * init method will register all action hooks related to ticket creation, ticket response, response by agent, note by agent, ticket closed or reopen
21 */
22 public function init()
23 {
24 // Check if activity logs are disabled - if so, don't register any hooks
25 if (Helper::areLogsDisabled('_activity_settings')) {
26 return;
27 }
28
29 // Ticket Related activities
30 add_action('fluent_support/ticket_created', function ($ticket, $customer) {
31
32 $customer->last_response_at = current_time('mysql');
33 $customer->save();
34
35 $agent = Helper::getAgentByUserId();
36
37 if ($agent) {
38 $description = sprintf(
39 '%1$s created a %2$s on behalf of %3$s',
40 $this->getPersonMarkup($agent),
41 $this->getTicketMarkup($ticket),
42 $this->getPersonMarkup($customer)
43 );
44 $personId = $agent->id;
45 $personType = $agent->person_type;
46 } else {
47 $description = sprintf('%1$s created a %2$s via %3$s', $this->getPersonMarkup($customer), $this->getTicketMarkup($ticket), $ticket->source);
48 $personId = $customer->id;
49 $personType = $customer->person_type;
50 }
51
52 $log = [
53 'event_type' => 'fluent_support/ticket_created',
54 'person_id' => $personId,
55 'person_type' => $personType,
56 'object_id' => $ticket->id,
57 'object_type' => 'ticket',
58 'description' => $description
59 ];
60
61 Activity::create($log);
62 }, 20, 2);
63
64 //Response added by customer in a ticket
65 add_action('fluent_support/response_added_by_customer', function ($response, $ticket, $person) {
66
67 $person->last_response_at = current_time('mysql');
68 $person->save();
69
70 $description = sprintf('Customer %1$s added a response on %2$s via %3$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket), $response->source);
71
72 $log = [
73 'event_type' => 'fluent_support/response_added_by_customer',
74 'person_id' => $person->id,
75 'person_type' => $person->person_type,
76 'object_id' => $ticket->id,
77 'object_type' => 'ticket',
78 'description' => $description
79 ];
80
81 Activity::create($log);
82 }, 20, 3);
83
84 //Response added by agent in a ticket
85 add_action('fluent_support/response_added_by_agent', function ($response, $ticket, $person) {
86 $description = sprintf('%1$s added a response on %2$s via %3$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket), $response->source);
87
88 $log = [
89 'event_type' => 'fluent_support/response_added_by_agent',
90 'person_id' => $person->id,
91 'person_type' => $person->person_type,
92 'object_id' => $ticket->id,
93 'object_type' => 'ticket',
94 'description' => $description
95 ];
96
97 Activity::create($log);
98 }, 20, 3);
99
100 //Note added by agent to a ticket
101 add_action('fluent_support/note_added_by_agent', function ($response, $ticket, $person) {
102 $description = sprintf('%1$s added a note on %2$s via %3$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket), $response->source);
103
104 $log = [
105 'event_type' => 'fluent_support/note_added_by_agent',
106 'person_id' => $person->id,
107 'person_type' => $person->person_type,
108 'object_id' => $ticket->id,
109 'object_type' => 'ticket',
110 'description' => $description
111 ];
112
113 Activity::create($log);
114 }, 20, 3);
115
116 //Ticket closed by customer or agent
117 add_action('fluent_support/ticket_closed', function ($ticket, $person) {
118
119 if ($person->person_type == 'customer') {
120 $person->last_response_at = current_time('mysql');
121 $person->save();
122 }
123
124 $description = sprintf('%1$s closed %2$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket));
125
126 $log = [
127 'event_type' => 'fluent_support/ticket_closed',
128 'person_id' => $person->id,
129 'person_type' => $person->person_type,
130 'object_id' => $ticket->id,
131 'object_type' => 'ticket',
132 'description' => $description
133 ];
134
135 Activity::create($log);
136 }, 20, 2);
137
138 //Ticket reopen by customer or agent.
139 add_action('fluent_support/ticket_reopen', function ($ticket, $person) {
140
141 if ($person->person_type == 'customer') {
142 $person->last_response_at = current_time('mysql');
143 $person->save();
144 }
145
146 $description = sprintf('%1$s reopened on %2$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket));
147
148 $log = [
149 'event_type' => 'fluent_support/ticket_reopen',
150 'person_id' => $person->id,
151 'person_type' => $person->person_type,
152 'object_id' => $ticket->id,
153 'object_type' => 'ticket',
154 'description' => $description
155 ];
156
157 Activity::create($log);
158 }, 20, 2);
159
160 // Ticket Assigned by agent
161 add_action('fluent_support/agent_assigned_to_ticket', function ($assignedAgent, $ticket, $assigner) {
162
163 $description = sprintf('Assign %1$s ticket to %2$s by %3$s', $this->getTicketMarkup($ticket), $this->getPersonMarkup($assignedAgent), $this->getPersonMarkup($assigner));
164
165 if($assigner && isset($assigner->id) && isset($assigner->person_type)){
166 $log = [
167 'event_type' => 'fluent_support/agent_assigned_to_ticket',
168 'person_id' => $assigner->id,
169 'person_type' => $assigner->person_type,
170 'object_id' => $ticket->id,
171 'object_type' => 'ticket',
172 'description' => $description
173 ];
174 Activity::create($log);
175 }
176 }, 20, 3);
177
178 add_action('fluent_support/ticket_deleted', function($agent, $ticketData) {
179 if (!$agent || !$agent->id) {
180 return;
181 }
182
183 $description = sprintf('%s deleted %s(#%d) at %s', $this->getPersonMarkup($agent), esc_html($ticketData['title']), $ticketData['id'], current_time('mysql'));
184 $log = [
185 'event_type' => 'fluent_support/ticket_deleted',
186 'person_id' => $agent->id,
187 'person_type' => 'agent',
188 'object_id' => $ticketData['id'],
189 'object_type' => 'ticket',
190 'description' => $description
191 ];
192 Activity::create($log);
193 }, 20, 2);
194 }
195
196 /**
197 * getTicketMarkup method will generate hyperlink to view the ticket details
198 * @param $ticket
199 * @param false $ticketText
200 * @return string
201 */
202 public function getTicketMarkup($ticket, $ticketText = false)
203 {
204 if (!$ticketText) {
205 // translators: %s is the ticket title
206 $ticketText = sprintf(__('Ticket: %s', 'fluent-support'), esc_html($ticket->title));
207 }
208
209 return '<a class="fs_link_trans fs_tk" href="#view_ticket">' . $ticketText . '</a>';
210 }
211
212 /**
213 * getPersonMarkup method will generate hyperlink to view a customer or agent
214 * @param $person
215 * @return string
216 */
217 public function getPersonMarkup($person)
218 {
219 if (!$person) {
220 return '';
221 }
222
223 $route = 'view_agent';
224 if (isset($person->person_type) && $person->person_type == 'customer') {
225 $route = 'view_customer';
226 }
227 return '<a class="fs_link_trans fs_pr" href="#' . $route . '">' . esc_html($person->full_name) . '</a>';
228 }
229 }
230