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 / Hooks / Handlers / PrivacyHandler.php

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

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