PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.2.0
Fluent Support – Helpdesk & Customer Support Ticket System v2.2.0
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 / PrivacyHandler.php

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

335 lines 11.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\Conversation;
6 use FluentSupport\App\Models\Customer;
7 use FluentSupport\App\Models\Ticket;
8
9 class PrivacyHandler
10 {
11 public function init()
12 {
13 add_filter('wp_privacy_personal_data_exporters', [$this, 'registerExporter']);
14 add_filter('wp_privacy_personal_data_erasers', [$this, 'registerEraser']);
15 }
16
17 // Registering exporters to export data
18 public function registerExporter($exporters)
19 {
20 $exporters['fluent-support-tickets'] = array(
21 'exporter_friendly_name' => __('Fluent Support Tickets Exporter', 'fluent-support'),
22 'callback' => [$this, 'exportTickets'],
23 );
24
25 $exporters['fluent-support-conversations'] = array(
26 'exporter_friendly_name' => __('Fluent Support Conversations Exporter', 'fluent-support'),
27 'callback' => [$this, 'exportConversations'],
28 );
29
30 $exporters['fluent-support-customer'] = array(
31 'exporter_friendly_name' => __('Fluent Support Customer Exporter', 'fluent-support'),
32 'callback' => [$this, 'exportCustomerData'],
33 );
34 return $exporters;
35 }
36
37 // Registering erasers to erase data
38 public function registerEraser($erasers)
39 {
40 $erasers['fluent-support'] = array(
41 'eraser_friendly_name' => __('Fluent Support Personal Data Eraser', 'fluent-support'),
42 'callback' => [$this, 'erasePersonalData'],
43 );
44 return $erasers;
45 }
46
47 // Method to handle tickets data exporter
48 public function exportTickets($user_email, $page = 1)
49 {
50 $customer = Customer::where('email', $user_email)->select(['id'])->first();
51
52 if (!$customer) {
53 return [
54 'data' => [],
55 'done' => true
56 ];
57 }
58
59 $tickets = Ticket::with(['customer', 'agent', 'product', 'mailbox', 'tags', 'attachments'])
60 ->where('customer_id', $customer->id)
61 ->get();
62 $data = [];
63
64 foreach ($tickets as $ticket) {
65 $data[] = [
66 'group_id' => 'fluent-support-tickets',
67 'group_label' => __('Fluent Support Tickets', 'fluent-support'),
68 'item_id' => 'ticket-' . $ticket->id,
69 'data' => [
70 [
71 'name' => __('Ticket ID', 'fluent-support'),
72 'value' => $ticket->id,
73 ],
74 [
75 'name' => __('Ticket Title', 'fluent-support'),
76 'value' => $ticket->title,
77 ],
78 [
79 'name' => __('Ticket Content', 'fluent-support'),
80 'value' => $ticket->content,
81 ],
82 [
83 'name' => __('Ticket Attachments', 'fluent-support'),
84 'value' => $this->ticketAttachments($ticket->attachments),
85 ],
86 [
87 'name' => __('Ticket Product', 'fluent-support'),
88 'value' => isset($ticket->product) ? $ticket->product->title : '',
89 ],
90 [
91 'name' => __('Ticket Tags', 'fluent-support'),
92 'value' => $this->ticketTags($ticket->tags),
93 ],
94 [
95 'name' => __('Ticket Status', 'fluent-support'),
96 'value' => $ticket->status,
97 ],
98 [
99 'name' => __('Ticket Priority', 'fluent-support'),
100 'value' => $ticket->priority,
101 ],
102 [
103 'name' => __('Ticket Created At', 'fluent-support'),
104 'value' => $ticket->created_at,
105 ]
106 ],
107 ];
108 }
109
110 /**
111 * Filter to modify tickets exportable data
112 * @param array $data
113 * @param object $tickets
114 * @return array Exportable data
115 * @since v1.5.5
116 */
117 $exportableData = apply_filters('fluent_support/exportable_tickets_data', $data, $tickets);
118 return [
119 'data' => $exportableData,
120 'done' => true,
121 ];
122 }
123
124 // Method to handle conversations data exporter
125 public function exportConversations($user_email, $page = 1)
126 {
127 $customer = Customer::where('email', $user_email)->select(['id'])->first();
128
129 if (!$customer) {
130 return [
131 'data' => [],
132 'done' => true
133 ];
134 }
135
136 $conversations = Conversation::with(['attachments'])
137 ->where('person_id', $customer->id)
138 ->where('conversation_type', 'response')
139 ->get();
140
141 $data = [];
142 foreach ($conversations as $conversation) {
143 $data[] = [
144 'group_id' => 'fluent-support-conversations',
145 'group_label' => __('Fluent Support Conversations', 'fluent-support'),
146 'item_id' => 'conversation-' . $conversation->id,
147 'data' => [
148 [
149 'name' => __('Conversation ID', 'fluent-support'),
150 'value' => $conversation->id,
151 ],
152 [
153 'name' => __('Ticket ID', 'fluent-support'),
154 'value' => $conversation->ticket_id,
155 ],
156 [
157 'name' => __('Conversation Content', 'fluent-support'),
158 'value' => $conversation->content,
159 ],
160 [
161 'name' => __('Conversation Attachments', 'fluent-support'),
162 'value' => $this->convAttachments($conversation->attachments),
163 ],
164 [
165 'name' => __('Conversation Created At', 'fluent-support'),
166 'value' => $conversation->created_at,
167 ]
168 ],
169 ];
170 }
171
172 /**
173 * Filter to modify conversations exportable data
174 * @param array $data
175 * @param object $conversations
176 * @return array Exportable data
177 * @since v1.5.5
178 */
179 $exportableData = apply_filters('fluent_support/exportable_conversations_data', $data, $conversations);
180 return [
181 'data' => $exportableData,
182 'done' => true,
183 ];
184 }
185
186 // Method to handle customers data exporter
187 public function exportCustomerData($user_email, $page = 1)
188 {
189 $customer = Customer::where('email', $user_email)->first();
190
191 if (!$customer) {
192 return [
193 'data' => [],
194 'done' => true
195 ];
196 }
197
198 $data[] = [
199 'group_id' => 'fluent-support-customer',
200 'group_label' => __('Fluent Support Customer', 'fluent-support'),
201 'item_id' => 'customer-' . $customer->id,
202 'data' => [
203 [
204 'name' => __('Customer ID', 'fluent-support'),
205 'value' => $customer->id,
206 ],
207 [
208 'name' => __('First Name', 'fluent-support'),
209 'value' => $customer->first_name,
210 ],
211 [
212 'name' => __('Last Name', 'fluent-support'),
213 'value' => $customer->last_name,
214 ],
215 [
216 'name' => __('Email', 'fluent-support'),
217 'value' => $customer->email,
218 ],
219 [
220 'name' => __('Status', 'fluent-support'),
221 'value' => $customer->status,
222 ],
223 [
224 'name' => __('IP Address', 'fluent-support'),
225 'value' => $customer->ip_address,
226 ],
227 [
228 'name' => __('Last IP Address', 'fluent-support'),
229 'value' => $customer->last_ip_address,
230 ],
231 [
232 'name' => __('Address Line One', 'fluent-support'),
233 'value' => $customer->address_line_1
234 ],
235 [
236 'name' => __('Address Line Two', 'fluent-support'),
237 'value' => $customer->address_line_2
238 ],
239 [
240 'name' => __('City', 'fluent-support'),
241 'value' => $customer->city
242 ],
243 [
244 'name' => __('Zip', 'fluent-support'),
245 'value' => $customer->zip
246 ],
247 [
248 'name' => __('State', 'fluent-support'),
249 'value' => $customer->state
250 ],
251 [
252 'name' => __('Country', 'fluent-support'),
253 'value' => $customer->country
254 ],
255 [
256 'name' => __('Created At', 'fluent-support'),
257 'value' => $customer->created_at
258 ],
259 ],
260 ];
261
262 /**
263 * Filter to modify customer exportable data
264 * @param array $data
265 * @param object $customer
266 * @return array Exportable data
267 * @since v1.5.5
268 */
269 $exportableData = apply_filters('fluent_support/exportable_customer_data', $data, $customer);
270 return [
271 'data' => $exportableData,
272 'done' => true,
273 ];
274 }
275
276 public function ticketAttachments($attachments)
277 {
278 $text = '';
279 foreach ($attachments as $attachment) {
280 $text .= '<a href=' . esc_url($attachment->secureUrl) . '>' . esc_html($attachment->title) . '</a>, <br>';
281 }
282
283 return $text;
284 }
285
286 public function convAttachments($attachments)
287 {
288 $text = '';
289 foreach ($attachments as $attachment) {
290 $text .= '<a href=' . esc_url($attachment->secureUrl) . '>' . esc_html($attachment->title) . '</a>, <br>';
291 }
292
293 return $text;
294 }
295
296 public function ticketTags($tags)
297 {
298 $ticketTags = '';
299 foreach ($tags as $tag) {
300 $ticketTags .= $tag->title . ', ';
301 }
302
303 return $ticketTags;
304 }
305
306 // Method to handle data eraser
307 public function erasePersonalData($user_email, $page = 1)
308 {
309 $customer = Customer::where('email', $user_email)->select(['id'])->first();
310
311 if (!$customer) {
312 return [
313 'items_removed' => true,
314 'items_retained' => false,
315 'messages' => [],
316 'done' => true
317 ];
318 }
319
320 $tickets = Ticket::where('customer_id', $customer->id)->get();
321 foreach ($tickets as $ticket) {
322 $ticket->deleteTicket();
323 }
324
325 $customer->delete();
326
327 return [
328 'items_removed' => true,
329 'items_retained' => false,
330 'messages' => [],
331 'done' => true,
332 ];
333 }
334 }
335