2017-05-23 09:24:36 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Transformers\ActionlogsTransformer;
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Models\Actionlog;
|
|
|
|
use Illuminate\Http\Request;
|
2017-05-23 09:24:36 -07:00
|
|
|
|
|
|
|
class ReportsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns Activity Report JSON.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
2018-07-12 18:28:02 -07:00
|
|
|
$this->authorize('reports.view');
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2022-08-02 23:50:10 -07:00
|
|
|
$actionlogs = Actionlog::with('item', 'user', 'admin', 'target', 'location');
|
2017-05-23 09:24:36 -07:00
|
|
|
|
2018-07-24 22:51:31 -07:00
|
|
|
if ($request->filled('search')) {
|
2017-05-23 09:24:36 -07:00
|
|
|
$actionlogs = $actionlogs->TextSearch(e($request->input('search')));
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
if (($request->filled('target_type')) && ($request->filled('target_id'))) {
|
|
|
|
$actionlogs = $actionlogs->where('target_id', '=', $request->input('target_id'))
|
|
|
|
->where('target_type', '=', 'App\\Models\\'.ucwords($request->input('target_type')));
|
2017-05-23 14:30:29 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
if (($request->filled('item_type')) && ($request->filled('item_id'))) {
|
|
|
|
$actionlogs = $actionlogs->where('item_id', '=', $request->input('item_id'))
|
|
|
|
->where('item_type', '=', 'App\\Models\\'.ucwords($request->input('item_type')));
|
2017-06-08 18:26:55 -07:00
|
|
|
}
|
|
|
|
|
2018-07-24 22:51:31 -07:00
|
|
|
if ($request->filled('action_type')) {
|
2021-06-10 13:15:52 -07:00
|
|
|
$actionlogs = $actionlogs->where('action_type', '=', $request->input('action_type'))->orderBy('created_at', 'desc');
|
2017-08-25 10:04:19 -07:00
|
|
|
}
|
|
|
|
|
2023-12-14 06:34:08 -08:00
|
|
|
if ($request->filled('action_source')) {
|
|
|
|
$actionlogs = $actionlogs->where('action_source', '=', $request->input('action_source'))->orderBy('created_at', 'desc');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('remote_ip')) {
|
|
|
|
$actionlogs = $actionlogs->where('remote_ip', '=', $request->input('remote_ip'))->orderBy('created_at', 'desc');
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:51:31 -07:00
|
|
|
if ($request->filled('uploads')) {
|
2018-05-02 14:13:06 -07:00
|
|
|
$actionlogs = $actionlogs->whereNotNull('filename')->orderBy('created_at', 'desc');
|
|
|
|
}
|
|
|
|
|
2017-05-23 14:30:29 -07:00
|
|
|
$allowed_columns = [
|
|
|
|
'id',
|
2018-02-16 13:22:55 -08:00
|
|
|
'created_at',
|
|
|
|
'target_id',
|
|
|
|
'user_id',
|
2020-10-22 23:20:55 -07:00
|
|
|
'accept_signature',
|
2018-02-16 13:22:55 -08:00
|
|
|
'action_type',
|
2021-06-10 13:15:52 -07:00
|
|
|
'note',
|
2023-12-14 06:34:08 -08:00
|
|
|
'remote_ip',
|
|
|
|
'user_agent',
|
|
|
|
'action_source',
|
2017-05-23 14:30:29 -07:00
|
|
|
];
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2023-04-12 11:28:46 -07:00
|
|
|
|
|
|
|
// Make sure the offset and limit are actually integers and do not exceed system limits
|
2023-10-14 12:39:52 -07:00
|
|
|
$offset = ($request->input('offset') > $actionlogs->count()) ? $actionlogs->count() : app('api_offset_value');
|
2023-04-16 08:46:39 -07:00
|
|
|
$limit = app('api_limit_value');
|
2023-04-12 11:28:46 -07:00
|
|
|
|
2017-05-23 09:24:36 -07:00
|
|
|
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
2018-02-01 15:17:56 -08:00
|
|
|
$order = ($request->input('order') == 'asc') ? 'asc' : 'desc';
|
2017-05-23 09:24:36 -07:00
|
|
|
$total = $actionlogs->count();
|
2023-02-27 12:04:46 -08:00
|
|
|
|
2017-11-21 22:34:07 -08:00
|
|
|
$actionlogs = $actionlogs->orderBy($sort, $order)->skip($offset)->take($limit)->get();
|
2017-05-23 09:24:36 -07:00
|
|
|
|
2017-11-21 22:34:07 -08:00
|
|
|
return response()->json((new ActionlogsTransformer)->transformActionlogs($actionlogs, $total), 200, ['Content-Type' => 'application/json;charset=utf8'], JSON_UNESCAPED_UNICODE);
|
2017-05-23 09:24:36 -07:00
|
|
|
}
|
|
|
|
}
|