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 / Services / Helper.php

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

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