| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentSupport\App\Models\Activity; |
| 6 |
use FluentSupport\App\Services\Helper; |
| 7 |
|
| 8 |
/** |
| 9 |
* ActivityLoggerController class for REST API |
| 10 |
* This class is responsible for getting data for all request related to activity and activity settings |
| 11 |
* @package FluentSupport\App\Http\Controllers |
| 12 |
* |
| 13 |
* @version 1.0.0 |
| 14 |
*/ |
| 15 |
class ActivityLoggerController extends Controller |
| 16 |
{ |
| 17 |
/** |
| 18 |
* getActivities method will get information regarding all activity with users(agent/customer) and activity settings |
| 19 |
* @return array |
| 20 |
*/ |
| 21 |
public function getActivities() |
| 22 |
{ |
| 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(); |
| 28 |
|
| 29 |
$settings = $this->getSettings(); |
| 30 |
|
| 31 |
return [ |
| 32 |
'activities' => $activities, |
| 33 |
'settings' => $settings['activity_settings'] |
| 34 |
]; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* getSettings method will get the list of activity settings and return |
| 39 |
* @return array |
| 40 |
*/ |
| 41 |
public function getSettings() |
| 42 |
{ |
| 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 |
|
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* updateSettings method will update existing activity settings |
| 60 |
* @return array |
| 61 |
*/ |
| 62 |
public function updateSettings() |
| 63 |
{ |
| 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 |
|
| 78 |
} |
| 79 |
} |
| 80 |
|