PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.0
Fluent Support – Helpdesk & Customer Support Ticket System v2.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
← All changes | app/Http/Controllers/ActivityLoggerController.php +47 -46 1.5.52.4.0 View file →
@@ -3,8 +3,9 @@
3 3 namespace FluentSupport\App\Http\Controllers;
4 4
5 5 use FluentSupport\App\Models\Activity;
6 6 use FluentSupport\App\Services\Helper;
7 +use FluentSupport\Framework\Http\Request\Request;
7 8
8 9 /**
9 10 * ActivityLoggerController class for REST API
10 11 * This class is responsible for getting data for all request related to activity and activity settings
@@ -15,65 +16,65 @@
15 16 class ActivityLoggerController extends Controller
16 17 {
17 18 /**
18 19 * getActivities method will get information regarding all activity with users(agent/customer) and activity settings
19 - * @return array
20 + * @return \WP_REST_Response | array
20 21 */
21 - public function getActivities()
22 +
23 + public function getActivities (Request $request, Activity $activity)
22 24 {
23 - $activities = Activity::with([
24 - 'person' => function ($query) {
25 - $query->select(['first_name', 'person_type', 'last_name', 'id', 'avatar']);
26 - }
27 - ])->orderBy('id', 'DESC')->paginate();
25 + try {
26 + $filters = $request->get('filters', null);
27 + $filters = is_array($filters) ? map_deep($filters, 'sanitize_text_field') : [];
28 28
29 - $settings = $this->getSettings();
30 -
31 - return [
32 - 'activities' => $activities,
33 - 'settings' => $settings['activity_settings']
34 - ];
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 + }
35 41 }
36 42
37 43 /**
38 - * getSettings method will get the list of activity settings and return
39 - * @return array
44 + * updateSettings method will update existing activity settings
45 + * @return \WP_REST_Response | array
40 46 */
41 - public function getSettings()
47 + public function updateSettings (Request $request, Activity $activity)
42 48 {
43 - $settings = Helper::getOption('_activity_settings', []);
44 -
45 - $defaults = [
46 - 'delete_days' => 14,
47 - 'disable_logs' => 'no'
48 - ];
49 -
50 - $settings = wp_parse_args($settings, $defaults);
51 -
52 - return [
53 - 'activity_settings' => $settings
54 - ];
55 -
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 + }
56 64 }
57 65
58 66 /**
59 - * updateSettings method will update existing activity settings
60 - * @return array
67 + * getSettings method will get the list of activity settings and return
68 + * @return \WP_REST_Response | array
61 69 */
62 - public function updateSettings()
70 + public function getSettings(Activity $activity)
63 71 {
64 - $settings = $this->request->get('activity_settings', []);
65 - $defaults = [
66 - 'delete_days' => 14,
67 - 'disable_logs' => 'no'
68 - ];
69 - $settings = wp_parse_args($settings, $defaults);
70 - $settings['delete_days'] = (int)$settings['delete_days'];
71 -
72 - Helper::updateOption('_activity_settings', $settings);
73 -
74 - return [
75 - 'message' => __('Activity settings has been updated', 'fluent-support')
76 - ];
77 -
72 + try {
73 + return $activity->getSettings();
74 + } catch (\Exception $e) {
75 + return $this->sendError([
76 + 'message' => Helper::getSafeErrorMessage($e)
77 + ]);
78 + }
78 79 }
79 80 }