PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.5.2
Fluent Support – Helpdesk & Customer Support Ticket System v1.5.2
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 / Services / Helper.php

Helper.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.5.2, at app/Services/Helper.php

442 lines 12.9 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\Services;
4
5 use FluentSupport\App\App;
6 use FluentSupport\App\Models\Agent;
7 use FluentSupport\App\Models\Customer;
8 use FluentSupport\App\Models\MailBox;
9 use FluentSupport\App\Models\Meta;
10 use FluentSupport\App\Models\Person;
11 use FluentSupport\App\Services\EmailNotification\Settings;
12 use FluentSupport\Framework\Support\Arr;
13
14 class Helper
15 {
16 public static function FluentSupport($module = null)
17 {
18 return App::getInstance($module);
19 }
20
21 public static function getAgentByUserId($userId = null)
22 {
23 if ($userId === null) {
24 $userId = get_current_user_id();
25 }
26 if (!$userId) {
27 return false;
28 }
29
30 return Agent::where('user_id', $userId)->first();
31 }
32
33 public static function customerTicketPriorities()
34 {
35 return apply_filters('fluent_support/customer_ticket_priorities', [
36 'normal' => __('Normal', 'fluent-support'),
37 'medium' => __('Medium', 'fluent-support'),
38 'critical' => __('Critical', 'fluent-support')
39 ]);
40 }
41
42 public static function adminTicketPriorities()
43 {
44 return apply_filters('fluent_support/admin_ticket_priorities', [
45 'normal' => __('Normal', 'fluent-support'),
46 'medium' => __('Medium', 'fluent-support'),
47 'critical' => __('Critical', 'fluent-support')
48 ]);
49 }
50
51 public static function ticketStatusGroups()
52 {
53 return apply_filters('fluent_support/ticket_status_groups', [
54 'open' => ['new', 'active'],
55 'active' => ['active'],
56 'closed' => ['closed'],
57 'new' => ['new'],
58 'all' => []
59 ]);
60 }
61
62 public static function getTkStatusesByGroupName($groupName)
63 {
64 $groups = self::ticketStatusGroups();
65 return Arr::get($groups, $groupName, []);
66 }
67
68 public static function ticketAcceptedFileMiles()
69 {
70 $groups = self::getMimeGroups();
71 $globalSettings = (new Settings())->globalBusinessSettings();
72
73 if (empty($globalSettings['accepted_file_types'])) {
74 return apply_filters('fluent_support/accepted_ticket_mimes', []);
75 }
76
77 $mimes = [];
78 $typesGroups = Arr::only($groups, $globalSettings['accepted_file_types']);
79 foreach ($typesGroups as $mimesGroup) {
80 $mimes = array_merge($mimes, $mimesGroup['mimes']);
81 }
82
83 return apply_filters('fluent_support/accepted_ticket_mimes', $mimes);
84 }
85
86 public static function getAcceptedMimeHeadings()
87 {
88 $groups = self::getMimeGroups();
89 $globalSettings = (new Settings())->globalBusinessSettings();
90
91 if (empty($globalSettings['accepted_file_types'])) {
92 return [];
93 }
94
95 $mimeNames = [];
96 $typesGroups = Arr::only($groups, $globalSettings['accepted_file_types']);
97 foreach ($typesGroups as $mimesGroup) {
98 $mimeNames[] = $mimesGroup['title'];
99 }
100
101 return $mimeNames;
102 }
103
104 public static function getFileUploadMessage()
105 {
106 $mimeHeadings = self::getAcceptedMimeHeadings();
107 $settings = (new Settings())->globalBusinessSettings();
108 $maxFileSize = absint($settings['max_file_size']);
109
110 return sprintf(__('Supported Types: %s and max file size: %dMB', 'fluent-support'), implode(', ', $mimeHeadings), $maxFileSize);
111 }
112
113 public static function getMimeGroups()
114 {
115 return [
116 'images' => [
117 'title' => __('Photos', 'fluent-support'),
118 'mimes' => [
119 'image/gif',
120 'image/ief',
121 'image/jpeg',
122 'image/webp',
123 'image/pjpeg',
124 'image/ktx',
125 'image/png'
126 ]
127 ],
128 'csv' => [
129 'title' => __('CSV', 'fluent-support'),
130 'mimes' => [
131 'application/csv',
132 'application/txt',
133 'text/csv',
134 'text/plain',
135 'text/comma-separated-values',
136 'text/anytext',
137 ]
138 ],
139 'documents' => [
140 'title' => __('PDF/Docs', 'fluent-support'),
141 'mimes' => [
142 'application/excel',
143 'application/vnd.ms-excel',
144 'application/vnd.msexcel',
145 'application/octet-stream',
146 'application/pdf',
147 ]
148 ],
149 'zip' => [
150 'title' => __('Zip', 'fluent-support'),
151 'mimes' => [
152 'application/zip'
153 ]
154 ],
155 'json' => [
156 'title' => __('JSON', 'fluent-support'),
157 'mimes' => [
158 'application/json',
159 'application/jsonml+json'
160 ]
161 ]
162 ];
163 }
164
165 public static function getOption($key, $default = '')
166 {
167 $data = Meta::where('object_type', 'option')
168 ->where('key', $key)
169 ->first();
170
171 if ($data) {
172 $value = maybe_unserialize($data->value);
173 if ($value) {
174 return $value;
175 }
176 }
177
178 return $default;
179 }
180
181 public static function updateOption($key, $value)
182 {
183 $data = Meta::where('object_type', 'option')
184 ->where('key', $key)
185 ->first();
186
187 if ($data) {
188 return Meta::where('id', $data->id)
189 ->update([
190 'value' => maybe_serialize($value)
191 ]);
192 }
193
194 return Meta::insert([
195 'object_type' => 'option',
196 'key' => $key,
197 'value' => maybe_serialize($value)
198 ]);
199 }
200
201 public static function getIntegrationOption($key, $default = '')
202 {
203 $data = Meta::where('object_type', 'integration_settings')
204 ->where('key', $key)
205 ->first();
206
207 if ($data) {
208 $value = maybe_unserialize($data->value);
209 if ($value) {
210 return $value;
211 }
212 }
213
214 return $default;
215 }
216
217 public static function updateIntegrationOption($key, $value)
218 {
219 $data = Meta::where('object_type', 'integration_settings')
220 ->where('key', $key)
221 ->first();
222
223 if ($data) {
224 return Meta::where('id', $data->id)
225 ->update([
226 'value' => maybe_serialize($value)
227 ]);
228 }
229
230 return Meta::insert([
231 'object_type' => 'integration_settings',
232 'key' => $key,
233 'value' => maybe_serialize($value)
234 ]);
235 }
236
237 public static function getTicketViewUrl($ticket)
238 {
239 $baseUrl = self::getPortalBaseUrl();
240
241 return $baseUrl . '/#/ticket/' . $ticket->id . '/view';
242 }
243
244 public static function getTicketViewSignedUrl($ticket)
245 {
246 if (!self::isPublicSignedTicketEnabled()) {
247 return self::getTicketViewUrl($ticket);
248 }
249
250 $baseUrl = self::getPortalBaseUrl();
251
252 $baseUrl = add_query_arg([
253 'fs_view' => 'ticket',
254 'support_hash' => $ticket->hash,
255 'ticket_id' => $ticket->id
256 ], $baseUrl);
257
258 return $baseUrl . '#/ticket/' . $ticket->id . '/view';
259 }
260
261 public static function isPublicSignedTicketEnabled()
262 {
263 $businessSettings = self::getBusinessSettings();
264
265 return (Arr::get($businessSettings, 'disable_public_ticket') != 'yes');
266 }
267
268 public static function getTicketAdminUrl($ticket)
269 {
270 $baseUrl = self::getPortalAdminBaseUrl();
271 return $baseUrl . 'tickets/' . $ticket->id . '/view';
272 }
273
274 public static function getPortalBaseUrl()
275 {
276 $businessSettings = self::getBusinessSettings();
277 $baseUrl = get_permalink($businessSettings['portal_page_id']);
278 $baseUrl = rtrim($baseUrl, '/\\');
279 return apply_filters('fluent_support/portal_base_url', $baseUrl);
280 }
281
282 public static function getPortalAdminBaseUrl()
283 {
284 return apply_filters('fluent_support/portal_admin_base_url', admin_url('admin.php?page=fluent-support/#/'));
285 }
286
287 public static function getBusinessSettings()
288 {
289 static $settings;
290
291 if ($settings) {
292 return $settings;
293 }
294
295 $settings = (new Settings())->globalBusinessSettings();
296
297 return $settings;
298 }
299
300 public static function getTicketMeta($ticketId, $key, $default = '')
301 {
302 $data = Meta::where('object_type', 'ticket_meta')
303 ->where('key', $key)
304 ->where('object_id', $ticketId)
305 ->first();
306
307 if ($data) {
308 $value = maybe_unserialize($data->value);
309 if ($value) {
310 return $value;
311 }
312 }
313
314 return $default;
315 }
316
317 public static function updateTicketMeta($ticketId, $key, $value)
318 {
319 $data = Meta::where('object_type', 'ticket_meta')
320 ->where('key', $key)
321 ->where('object_id', $ticketId)
322 ->first();
323
324 if ($data) {
325 return Meta::where('id', $data->id)
326 ->update([
327 'value' => maybe_serialize($value)
328 ]);
329 }
330
331 return Meta::insert([
332 'object_type' => 'ticket_meta',
333 'object_id' => $ticketId,
334 'key' => $key,
335 'value' => maybe_serialize($value)
336 ]);
337 }
338
339 public static function getWPPages()
340 {
341 $pages = (self::FluentSupport())->app->db
342 ->table('posts')
343 ->select(['ID', 'post_title'])
344 ->where('post_type', 'page')
345 ->where('post_status', 'publish')
346 ->orderBy('ID', 'DESC')
347 ->get();
348 $formattedPages = [];
349 foreach ($pages as $page) {
350 $formattedPages[] = [
351 'id' => strval($page->ID),
352 'title' => $page->post_title
353 ];
354 }
355 return $formattedPages;
356 }
357
358 public static function getDefaultMailBox()
359 {
360 $mailbox = MailBox::where('is_default', 'yes')->first();
361
362 if ($mailbox) {
363 return $mailbox;
364 }
365
366 return MailBox::orderBy('id', 'ASC')->first();
367 }
368
369 public static function getCurrentAgent()
370 {
371 return Agent::where('user_id', get_current_user_id())->first();
372 }
373
374 public static function getCurrentCustomer()
375 {
376 return Customer::where('user_id', get_current_user_id())->first();
377 }
378
379 public static function getCurrentPerson()
380 {
381 return Person::where('user_id', get_current_user_id())->first();
382 }
383
384 public static function getFluentCRMTagConfig()
385 {
386 if (!defined('FLUENTCRM')) {
387 return [
388 'can_add_tags' => false,
389 'tags' => [],
390 'logo' => FLUENT_SUPPORT_PLUGIN_URL . 'assets/images/fluentcrm-logo.svg',
391 'icon' => FLUENT_SUPPORT_PLUGIN_URL . 'assets/images/fluent-crm-icon.png',
392 ];
393 }
394
395 $canAddTags = \FluentCrm\App\Services\PermissionManager::currentUserCan('fcrm_manage_contacts');
396
397 $canAddTags = apply_filters('fluent_support/can_user_add_tags_to_customer', $canAddTags);
398 $crmTags = [];
399 if ($canAddTags) {
400 $crmTags = \FluentCrm\App\Models\Tag::select(['id', 'title'])->orderBy('title', 'ASC')->get();
401 }
402
403 return [
404 'can_add_tags' => $canAddTags,
405 'tags' => $crmTags,
406 'logo' => FLUENT_SUPPORT_PLUGIN_URL . 'assets/images/fluentcrm-logo.svg',
407 'icon' => FLUENT_SUPPORT_PLUGIN_URL . 'assets/images/fluent-crm-icon.png',
408 ];
409
410 }
411
412 public static function getFluentCrmContactData($customer)
413 {
414 if (!defined('FLUENTCRM')) {
415 return false;
416 }
417 $contact = \FluentCrmApi('contacts')->getContactByUserRef($customer->email);
418 if ($contact) {
419 $tags = $contact->tags;
420 $urlBase = apply_filters('fluentcrm_menu_url_base', admin_url('admin.php?page=fluentcrm-admin#/'));
421 $crmProfileUrl = $urlBase . 'subscribers/' . $contact->id;
422
423 $contactData = [
424 'id' => $contact->id,
425 'first_name' => $contact->first_name,
426 'last_name' => $contact->last_name,
427 'full_name' => $contact->full_name,
428 'name_mismatch' => $contact->full_name != $customer->full_name,
429 'tags' => $tags,
430 'status' => $contact->status,
431 'stats' => $contact->stats(),
432 'view_url' => $crmProfileUrl
433 ];
434
435 return $contactData;
436 }
437
438 return false;
439 }
440
441 }
442