2017-05-23 09:24:36 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\Actionlog;
|
|
|
|
use App\Http\Transformers\ActionlogsTransformer;
|
|
|
|
|
|
|
|
class ReportsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns Activity Report JSON.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
|
2017-08-25 18:40:20 -07:00
|
|
|
$actionlogs = Actionlog::with('item', 'user', 'target','location');
|
2017-05-23 09:24:36 -07:00
|
|
|
|
|
|
|
if ($request->has('search')) {
|
|
|
|
$actionlogs = $actionlogs->TextSearch(e($request->input('search')));
|
|
|
|
}
|
|
|
|
|
2017-06-08 19:09:42 -07:00
|
|
|
if (($request->has('target_type')) && ($request->has('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
|
|
|
}
|
|
|
|
|
2017-06-08 18:26:55 -07:00
|
|
|
if (($request->has('item_type')) && ($request->has('item_id'))) {
|
|
|
|
$actionlogs = $actionlogs->where('item_id','=',$request->input('item_id'))
|
|
|
|
->where('item_type','=',"App\\Models\\".ucwords($request->input('item_type')));
|
|
|
|
}
|
|
|
|
|
2017-08-25 10:04:19 -07:00
|
|
|
if ($request->has('action_type')) {
|
|
|
|
$actionlogs = $actionlogs->where('action_type','=',$request->input('action_type'))->orderBy('created_at', 'desc');
|
|
|
|
}
|
|
|
|
|
2018-05-02 14:13:06 -07:00
|
|
|
if ($request->has('uploads')) {
|
|
|
|
$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',
|
|
|
|
'action_type',
|
|
|
|
'note'
|
2017-05-23 14:30:29 -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
|
|
|
$offset = request('offset', 0);
|
|
|
|
$limit = request('limit', 50);
|
|
|
|
$total = $actionlogs->count();
|
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
|
|
|
|
|
|
|
}
|
|
|
|
}
|