mirror of
https://github.com/snipe/snipe-it.git
synced 2026-03-29 20:04:21 +00:00
Additional API routes and controllers for models, suppliers, users, locations and status labels
This commit is contained in:
@ -780,89 +780,6 @@ class UsersController extends Controller
|
||||
return redirect()->route('users.index')->with('duplicates', $duplicates)->with('success', 'Success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON response with a list of user details for the getIndex() view.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.6]
|
||||
* @see UsersController::getIndex() method that consumed this JSON response
|
||||
* @return string JSON
|
||||
*/
|
||||
public function getDatatable(Request $request, $status = null)
|
||||
{
|
||||
$this->authorize('view', User::class);
|
||||
|
||||
$offset = request('offset', 0);
|
||||
$limit = request('limit', 50);
|
||||
|
||||
if (Input::get('sort')=='name') {
|
||||
$sort = 'first_name';
|
||||
} else {
|
||||
$sort = e(Input::get('sort'));
|
||||
}
|
||||
|
||||
$users = User::select([
|
||||
'users.id',
|
||||
'users.employee_num',
|
||||
'users.two_factor_enrolled',
|
||||
'users.jobtitle',
|
||||
'users.email',
|
||||
'users.username',
|
||||
'users.location_id',
|
||||
'users.manager_id',
|
||||
'users.first_name',
|
||||
'users.last_name',
|
||||
'users.created_at',
|
||||
'users.notes',
|
||||
'users.company_id',
|
||||
'users.deleted_at',
|
||||
'users.activated'
|
||||
])->with('manager', 'groups', 'userloc', 'company', 'throttle');
|
||||
$users = Company::scopeCompanyables($users);
|
||||
|
||||
switch ($status) {
|
||||
case 'deleted':
|
||||
$users = $users->withTrashed()->Deleted();
|
||||
break;
|
||||
}
|
||||
|
||||
if (Input::has('search')) {
|
||||
$users = $users->TextSearch(Input::get('search'));
|
||||
}
|
||||
|
||||
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
switch (Input::get('sort')) {
|
||||
case 'manager':
|
||||
$users = $users->OrderManager($order);
|
||||
break;
|
||||
case 'location':
|
||||
$users = $users->OrderLocation($order);
|
||||
break;
|
||||
default:
|
||||
$allowed_columns =
|
||||
[
|
||||
'last_name','first_name','email','jobtitle','username','employee_num',
|
||||
'assets','accessories', 'consumables','licenses','groups','activated','created_at',
|
||||
'two_factor_enrolled','two_factor_optin'
|
||||
];
|
||||
|
||||
$sort = in_array($sort, $allowed_columns) ? $sort : 'first_name';
|
||||
$users = $users->orderBy($sort, $order);
|
||||
break;
|
||||
}
|
||||
|
||||
$userCount = $users->count();
|
||||
$users = $users->skip($offset)->take($limit)->get();
|
||||
$rows = array();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$rows[] = $user->present()->forDataTable();
|
||||
}
|
||||
|
||||
$data = array('total'=>$userCount, 'rows'=>$rows);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON response with a list of user details for the getIndex() view.
|
||||
|
||||
Reference in New Issue
Block a user