PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / trunk
Fluent Support – Helpdesk & Customer Support Ticket System vtrunk
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 / Models / Traits / ActivityTrait.php

ActivityTrait.php in Fluent Support – Helpdesk & Customer Support Ticket System trunk, at app/Models/Traits/ActivityTrait.php

100 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace FluentSupport\App\Models\Traits;
3
4 use Exception;
5 use FluentSupport\App\Services\Helper;
6 use FluentSupport\Framework\Support\Arr;
7
8 trait ActivityTrait
9 {
10 // Get All Activities
11 public function getActivities ( $data )
12 {
13 $agentId = intval( Arr::get($data, 'filters.agent_id') );
14
15 $activitiesQuery = static::with([
16 'person' => function ($query) {
17 $query->select(['first_name', 'person_type', 'email', 'last_name', 'id', 'avatar']);
18 }
19 ])->latest('id');
20
21 $from = sanitize_text_field( Arr::get( $data, 'from', '' ) );
22 $to = sanitize_text_field( Arr::get( $data, 'to', '') );
23
24 if ( $from != $to ) {
25 $from = $from . ' ' . '00:00:00'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
26 $to = $to . ' ' . '23:59:59'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
27 }
28
29 if ( ( !empty($from) && !empty($to) ) && $from == $to ) {
30 $activitiesQuery->whereDate('created_at', '=', $from);
31 } elseif (!empty($from) && !empty($to)) {
32 $activitiesQuery->whereBetween('created_at', [ $from, $to ]);
33 }
34
35 if ($agentId) {
36 $activitiesQuery->where('person_id', $agentId);
37 }
38
39 $activities = $activitiesQuery->paginate();
40
41 foreach ($activities as $activity) {
42 if($activity->person) {
43 $activity->person->makeHidden(['email']);
44 }
45 }
46
47 if (!$activities) {
48 throw new \Exception('No activities found');
49 }
50
51 $settings = $this->getSettings();
52
53 return [
54 'activities' => $activities,
55 'settings' => $settings['activity_settings']
56 ];
57 }
58
59 // Update Activity Settings
60 public function updateSettings ($settings)
61 {
62 $defaults = [
63 'delete_days' => 14,
64 'disable_logs' => 'no',
65 'open_link_in_new_tab' => 'no'
66 ];
67 $settings = wp_parse_args($settings, $defaults);
68 $settings['delete_days'] = (int)$settings['delete_days'];
69
70 Helper::updateOption('_activity_settings', $settings);
71
72 return [
73 'message' => __('Activity settings have been updated', 'fluent-support')
74 ];
75 }
76
77 // Get Activity Settings
78 public function getSettings()
79 {
80 $settings = Helper::getOption('_activity_settings', []);
81
82 $defaults = [
83 'delete_days' => 14,
84 'disable_logs' => 'no',
85 'open_link_in_new_tab' => 'no'
86 ];
87
88 $settings = wp_parse_args($settings, $defaults);
89
90 if (! $settings ) throw new \Exception('No activity settings found');
91
92 return [
93 'activity_settings' => $settings
94 ];
95
96 }
97
98
99 }
100