PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.2.0
Fluent Support – Helpdesk & Customer Support Ticket System v2.2.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 1.5.6 All 67 releases
fluent-support / app / Http / Controllers / ActivityLoggerController.php

ActivityLoggerController.php in Fluent Support – Helpdesk & Customer Support Ticket System 2.2.0, at app/Http/Controllers/ActivityLoggerController.php

81 lines 2.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\Http\Controllers;
4
5 use FluentSupport\App\Models\Activity;
6 use FluentSupport\App\Services\Helper;
7 use FluentSupport\Framework\Http\Request\Request;
8
9 /**
10 * ActivityLoggerController class for REST API
11 * This class is responsible for getting data for all request related to activity and activity settings
12 * @package FluentSupport\App\Http\Controllers
13 *
14 * @version 1.0.0
15 */
16 class ActivityLoggerController extends Controller
17 {
18 /**
19 * getActivities method will get information regarding all activity with users(agent/customer) and activity settings
20 * @return \WP_REST_Response | array
21 */
22
23 public function getActivities (Request $request, Activity $activity)
24 {
25 try {
26 $filters = $request->get('filters', null);
27 $filters = is_array($filters) ? map_deep($filters, 'sanitize_text_field') : [];
28
29 return $activity->getActivities( [
30 'page' => $request->getSafe('page', 'intval', 1),
31 'per_page' => $request->getSafe('per_page', 'intval', 10),
32 'from' => $request->getSafe('from', 'sanitize_text_field', ''),
33 'to' => $request->getSafe('to', 'sanitize_text_field', ''),
34 'filters' => $filters,
35 ] );
36 } catch (\Exception $e) {
37 return $this->sendError([
38 'message' => Helper::getSafeErrorMessage($e)
39 ]);
40 }
41 }
42
43 /**
44 * updateSettings method will update existing activity settings
45 * @return \WP_REST_Response | array
46 */
47 public function updateSettings (Request $request, Activity $activity)
48 {
49 try {
50 // Get raw array - do not use sanitize_text_field on the whole object (it would turn array into empty string)
51 $raw = $request->get('activity_settings', null);
52 $settings = is_array($raw) ? $raw : [];
53 $settings = [
54 'delete_days' => isset($settings['delete_days']) ? intval($settings['delete_days']) : 14,
55 'disable_logs' => isset($settings['disable_logs']) ? sanitize_text_field($settings['disable_logs']) : 'no',
56 'open_link_in_new_tab' => isset($settings['open_link_in_new_tab']) ? sanitize_text_field($settings['open_link_in_new_tab']) : 'no',
57 ];
58 return $activity->updateSettings($settings);
59 } catch (\Exception $e) {
60 return $this->sendError([
61 'message' => Helper::getSafeErrorMessage($e)
62 ]);
63 }
64 }
65
66 /**
67 * getSettings method will get the list of activity settings and return
68 * @return \WP_REST_Response | array
69 */
70 public function getSettings(Activity $activity)
71 {
72 try {
73 return $activity->getSettings();
74 } catch (\Exception $e) {
75 return $this->sendError([
76 'message' => Helper::getSafeErrorMessage($e)
77 ]);
78 }
79 }
80 }
81