mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Reports API controller
This commit is contained in:
parent
fba7f1ccf6
commit
52f24f7587
42
app/Http/Controllers/Api/ReportsController.php
Normal file
42
app/Http/Controllers/Api/ReportsController.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?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)
|
||||||
|
{
|
||||||
|
|
||||||
|
$actionlogs = Actionlog::with('item', 'user', 'target');
|
||||||
|
//$activitylogs = $activitylogs->Company::scopeCompanyables($activitylogs);
|
||||||
|
|
||||||
|
if ($request->has('search')) {
|
||||||
|
$actionlogs = $actionlogs->TextSearch(e($request->input('search')));
|
||||||
|
}
|
||||||
|
|
||||||
|
$allowed_columns = ['created_at'];
|
||||||
|
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
||||||
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
|
$offset = request('offset', 0);
|
||||||
|
$limit = request('limit', 50);
|
||||||
|
$total = $actionlogs->count();
|
||||||
|
$actionlogs = $actionlogs->orderBy($sort, $order);
|
||||||
|
$actionlogs = $actionlogs->skip($offset)->take($limit)->get();
|
||||||
|
return (new ActionlogsTransformer)->transformActionlogs($actionlogs, $total);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue