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

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

384 lines 10.7 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 $mimeHeadings = self::getAcceptedMimeHeadings();
106 $settings = (new Settings())->globalBusinessSettings();
107 $maxFileSize = absint($settings['max_file_size']);
108
109 return sprintf(__('Supported Types: %s and max file size: %dMB', 'fluent-support'), implode(', ', $mimeHeadings), $maxFileSize);
110 }
111
112 public static function getMimeGroups()
113 {
114 return [
115 'images' => [
116 'title' => __('Photos', 'fluent-support'),
117 'mimes' => [
118 'image/gif',
119 'image/ief',
120 'image/jpeg',
121 'image/webp',
122 'image/pjpeg',
123 'image/ktx',
124 'image/png'
125 ]
126 ],
127 'csv' => [
128 'title' => __('CSV', 'fluent-support'),
129 'mimes' => [
130 'application/csv',
131 'application/txt',
132 'text/csv',
133 'text/plain',
134 'text/comma-separated-values',
135 'text/anytext',
136 ]
137 ],
138 'documents' => [
139 'title' => __('PDF/Docs', 'fluent-support'),
140 'mimes' => [
141 'application/excel',
142 'application/vnd.ms-excel',
143 'application/vnd.msexcel',
144 'application/octet-stream',
145 'application/pdf',
146 ]
147 ],
148 'zip' => [
149 'title' => __('Zip', 'fluent-support'),
150 'mimes' => [
151 'application/zip'
152 ]
153 ],
154 'json' => [
155 'title' => __('JSON', 'fluent-support'),
156 'mimes' => [
157 'application/json',
158 'application/jsonml+json'
159 ]
160 ]
161 ];
162 }
163
164 public static function getOption($key, $default = '')
165 {
166 $data = Meta::where('object_type', 'option')
167 ->where('key', $key)
168 ->first();
169
170 if ($data) {
171 $value = maybe_unserialize($data->value);
172 if ($value) {
173 return $value;
174 }
175 }
176
177 return $default;
178 }
179
180 public static function updateOption($key, $value)
181 {
182 $data = Meta::where('object_type', 'option')
183 ->where('key', $key)
184 ->first();
185
186 if ($data) {
187 return Meta::where('id', $data->id)
188 ->update([
189 'value' => maybe_serialize($value)
190 ]);
191 }
192
193 return Meta::insert([
194 'object_type' => 'option',
195 'key' => $key,
196 'value' => maybe_serialize($value)
197 ]);
198 }
199
200 public static function getIntegrationOption($key, $default = '')
201 {
202 $data = Meta::where('object_type', 'integration_settings')
203 ->where('key', $key)
204 ->first();
205
206 if ($data) {
207 $value = maybe_unserialize($data->value);
208 if ($value) {
209 return $value;
210 }
211 }
212
213 return $default;
214 }
215
216 public static function updateIntegrationOption($key, $value)
217 {
218 $data = Meta::where('object_type', 'integration_settings')
219 ->where('key', $key)
220 ->first();
221
222 if ($data) {
223 return Meta::where('id', $data->id)
224 ->update([
225 'value' => maybe_serialize($value)
226 ]);
227 }
228
229 return Meta::insert([
230 'object_type' => 'integration_settings',
231 'key' => $key,
232 'value' => maybe_serialize($value)
233 ]);
234 }
235
236 public static function getTicketViewUrl($ticket)
237 {
238 $baseUrl = self::getPortalBaseUrl();
239
240 return $baseUrl . '/#/ticket/' . $ticket->id . '/view';
241 }
242
243 public static function getTicketViewSignedUrl($ticket)
244 {
245 if (!self::isPublicSignedTicketEnabled()) {
246 return self::getTicketViewUrl($ticket);
247 }
248
249 $baseUrl = self::getPortalBaseUrl();
250
251 $baseUrl = add_query_arg([
252 'fs_view' => 'ticket',
253 'support_hash' => $ticket->hash,
254 'ticket_id' => $ticket->id
255 ], $baseUrl);
256
257 return $baseUrl . '#/ticket/' . $ticket->id . '/view';
258 }
259
260 public static function isPublicSignedTicketEnabled()
261 {
262 $businessSettings = self::getBusinessSettings();
263
264 return (Arr::get($businessSettings, 'disable_public_ticket') != 'yes');
265 }
266
267 public static function getTicketAdminUrl($ticket)
268 {
269 $baseUrl = self::getPortalAdminBaseUrl();
270 return $baseUrl . 'tickets/' . $ticket->id . '/view';
271 }
272
273 public static function getPortalBaseUrl()
274 {
275 $businessSettings = self::getBusinessSettings();
276 $baseUrl = get_permalink($businessSettings['portal_page_id']);
277 $baseUrl = rtrim($baseUrl, '/\\');
278 return apply_filters('fluent_support/portal_base_url', $baseUrl);
279 }
280
281 public static function getPortalAdminBaseUrl()
282 {
283 return apply_filters('fluent_support/portal_admin_base_url', admin_url('admin.php?page=fluent-support/#/'));
284 }
285
286 public static function getBusinessSettings()
287 {
288 static $settings;
289
290 if ($settings) {
291 return $settings;
292 }
293
294 $settings = (new Settings())->globalBusinessSettings();
295
296 return $settings;
297 }
298
299 public static function getTicketMeta($ticketId, $key, $default = '')
300 {
301 $data = Meta::where('object_type', 'ticket_mata')
302 ->where('key', $key)
303 ->where('object_id', $ticketId)
304 ->first();
305
306 if ($data) {
307 $value = maybe_unserialize($data->value);
308 if ($value) {
309 return $value;
310 }
311 }
312
313 return $default;
314 }
315
316 public static function updateTicketMeta($ticketId, $key, $value)
317 {
318 $data = Meta::where('object_type', 'ticket_mata')
319 ->where('key', $key)
320 ->where('object_id', $ticketId)
321 ->first();
322
323 if ($data) {
324 return Meta::where('id', $data->id)
325 ->update([
326 'value' => maybe_serialize($value)
327 ]);
328 }
329
330 return Meta::insert([
331 'object_type' => 'ticket_mata',
332 'object_id' => $ticketId,
333 'key' => $key,
334 'value' => maybe_serialize($value)
335 ]);
336 }
337
338 public static function getWPPages()
339 {
340 $pages = (self::FluentSupport())->app->db
341 ->table('posts')
342 ->select(['ID', 'post_title'])
343 ->where('post_type', 'page')
344 ->where('post_status', 'publish')
345 ->orderBy('ID', 'DESC')
346 ->get();
347 $formattedPages = [];
348 foreach ($pages as $page) {
349 $formattedPages[] = [
350 'id' => strval($page->ID),
351 'title' => $page->post_title
352 ];
353 }
354 return $formattedPages;
355 }
356
357 public static function getDefaultMailBox()
358 {
359 $mailbox = MailBox::where('is_default', 'yes')->first();
360
361 if ($mailbox) {
362 return $mailbox;
363 }
364
365 return MailBox::orderBy('id', 'ASC')->first();
366 }
367
368 public static function getCurrentAgent()
369 {
370 return Agent::where('user_id', get_current_user_id())->first();
371 }
372
373 public static function getCurrentCustomer()
374 {
375 return Customer::where('user_id', get_current_user_id())->first();
376 }
377
378 public static function getCurrentPerson()
379 {
380 return Person::where('user_id', get_current_user_id())->first();
381 }
382
383 }
384