A free open source IT asset/license management system
More shuffling of scopes
snipe4c3a306a6ee3
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.phpindex dc87dc999d..222f528e4a 100644--- a/app/Http/Controllers/Api/AssetsController.php+++ b/app/Http/Controllers/Api/AssetsController.php@@ -125,6 +125,8 @@ class AssetsController extends Controller$assets->InModelList($non_deprecable_models->toArray());}++// These are used by the API to query against specific ID numbers.// They are also used by the individual searches on detail pages like// locations, etc.@@ -136,12 +138,11 @@ class AssetsController extends Controller}}-- // Make sure the offset and limit are actually integers and do not exceed system limits- $offset = ($request->input('offset') > $assets->count()) ? $assets->count() : abs($request->input('offset'));- $limit = app('api_limit_value');-- $order = $request->input('order') === 'asc' ? 'asc' : 'desc';+ if ((! is_null($filter)) && (count($filter)) > 0) {+ $assets->ByFilter($filter);+ } elseif ($request->filled('search')) {+ $assets->TextSearch($request->input('search'));+ }// This is used by the audit reporting routesif (Gate::allows('audit', Asset::class)) {@@ -156,7 +157,6 @@ class AssetsController extends Controller}-// This is used by the sidenav, mostly// We switched from using query scopes here because of a Laravel bug@@ -206,7 +206,7 @@ class AssetsController extends Controllerbreak;case 'Deployed':// more sad, horrible workarounds for laravel bugs when doing full text searches- $assets->where('assets.assigned_to', '>', '0');+ $assets->whereNotNull('assets.assigned_to');break;case 'byod':// This is kind of redundant, since we already check for byod=1 above, but this keeps the@@ -232,12 +232,6 @@ class AssetsController extends Controller}- if ((! is_null($filter)) && (count($filter)) > 0) {- $assets->ByFilter($filter);- } elseif ($request->filled('search')) {- $assets->TextSearch($request->input('search'));- }-// Leave these under the TextSearch scope, else the fuzziness will override the specific ID (status ID, etc) requestedif ($request->filled('status_id')) {$assets->where('assets.status_id', '=', $request->input('status_id'));@@ -313,7 +307,8 @@ class AssetsController extends Controller// in the allowed_columns array)$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'assets.created_at';-+ $order = $request->input('order') === 'asc' ? 'asc' : 'desc';+switch ($sort_override) {case 'model':$assets->OrderModels($order);@@ -350,6 +345,10 @@ class AssetsController extends Controller}+ // Make sure the offset and limit are actually integers and do not exceed system limits+ $offset = ($request->input('offset') > $assets->count()) ? $assets->count() : abs($request->input('offset'));+ $limit = app('api_limit_value');+$total = $assets->count();$assets = $assets->skip($offset)->take($limit)->get();