From 3361b859c05b3c3f74ef3a1a66c648190ee76a54 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 4 Feb 2020 12:32:24 -0800 Subject: [PATCH] Changes offset to use the actual item count as override instead of 0 (#7788) --- app/Http/Controllers/Api/AccessoriesController.php | 4 +++- app/Http/Controllers/Api/AssetMaintenancesController.php | 4 +++- app/Http/Controllers/Api/AssetModelsController.php | 4 +++- app/Http/Controllers/Api/AssetsController.php | 6 +++++- app/Http/Controllers/Api/CategoriesController.php | 4 +++- app/Http/Controllers/Api/CompaniesController.php | 4 +++- app/Http/Controllers/Api/ComponentsController.php | 4 +++- app/Http/Controllers/Api/ConsumablesController.php | 4 +++- app/Http/Controllers/Api/DepartmentsController.php | 4 +++- app/Http/Controllers/Api/DepreciationsController.php | 4 +++- app/Http/Controllers/Api/GroupsController.php | 4 +++- app/Http/Controllers/Api/LicensesController.php | 4 +++- app/Http/Controllers/Api/LocationsController.php | 5 +++-- app/Http/Controllers/Api/ManufacturersController.php | 6 +++--- app/Http/Controllers/Api/StatuslabelsController.php | 4 +++- app/Http/Controllers/Api/SuppliersController.php | 4 +++- app/Http/Controllers/Api/UsersController.php | 5 ++++- 17 files changed, 54 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index 5c74996f62..bd239a05d3 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -49,7 +49,9 @@ class AccessoriesController extends Controller $accessories->where('supplier_id','=',$request->input('supplier_id')); } - $offset = (($accessories) && (request('offset') > $accessories->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($accessories) && ($request->get('offset') > $accessories->count())) ? $accessories->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index 535147a6bc..fcf4c9f9a0 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -44,7 +44,9 @@ class AssetMaintenancesController extends Controller $maintenances->where('asset_id', '=', $request->input('asset_id')); } - $offset = (($maintenances) && (request('offset') > $maintenances->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($maintenances) && ($request->get('offset') > $maintenances->count())) ? $maintenances->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/AssetModelsController.php b/app/Http/Controllers/Api/AssetModelsController.php index 08a2cd68d0..aaa6bced98 100644 --- a/app/Http/Controllers/Api/AssetModelsController.php +++ b/app/Http/Controllers/Api/AssetModelsController.php @@ -60,7 +60,9 @@ class AssetModelsController extends Controller $assetmodels->TextSearch($request->input('search')); } - $offset = (($assetmodels) && (request('offset') > $assetmodels->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($assetmodels) && ($request->get('offset') > $assetmodels->count())) ? $assetmodels->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 708d596dda..e4fd538781 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -144,7 +144,11 @@ class AssetsController extends Controller $request->filled('order_number') ? $assets = $assets->where('assets.order_number', '=', e($request->get('order_number'))) : ''; - $offset = (($assets) && (request('offset') > $assets->count())) ? 0 : request('offset', 0); + + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($assets) && ($request->get('offset') > $assets->count())) ? $assets->count() : $request->get('offset', 0); + // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/CategoriesController.php b/app/Http/Controllers/Api/CategoriesController.php index beafb802e7..52d107f1a3 100644 --- a/app/Http/Controllers/Api/CategoriesController.php +++ b/app/Http/Controllers/Api/CategoriesController.php @@ -30,7 +30,9 @@ class CategoriesController extends Controller $categories = $categories->TextSearch($request->input('search')); } - $offset = (($categories) && (request('offset') > $categories->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($categories) && ($request->get('offset') > $categories->count())) ? $categories->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/CompaniesController.php b/app/Http/Controllers/Api/CompaniesController.php index 7a4fe2c218..7b4781e2c8 100644 --- a/app/Http/Controllers/Api/CompaniesController.php +++ b/app/Http/Controllers/Api/CompaniesController.php @@ -41,7 +41,9 @@ class CompaniesController extends Controller $companies->TextSearch($request->input('search')); } - $offset = (($companies) && (request('offset') > $companies->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($companies) && ($request->get('offset') > $companies->count())) ? $companies->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index cfaff1bdb2..d1e8ed1b89 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -43,7 +43,9 @@ class ComponentsController extends Controller $components->where('location_id','=',$request->input('location_id')); } - $offset = (($components) && (request('offset') > $components->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($components) && ($request->get('offset') > $components->count())) ? $components->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index 3604b3e065..0ae657adcc 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -44,7 +44,9 @@ class ConsumablesController extends Controller } - $offset = (($consumables) && (request('offset') > $consumables->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($consumables) && ($request->get('offset') > $consumables->count())) ? $consumables->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/DepartmentsController.php b/app/Http/Controllers/Api/DepartmentsController.php index 5a3fcdd29d..2105346e63 100644 --- a/app/Http/Controllers/Api/DepartmentsController.php +++ b/app/Http/Controllers/Api/DepartmentsController.php @@ -39,7 +39,9 @@ class DepartmentsController extends Controller $departments = $departments->TextSearch($request->input('search')); } - $offset = (($departments) && (request('offset') > $departments->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($departments) && ($request->get('offset') > $departments->count())) ? $departments->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php index 2cfb7fcc52..0cd4219a2e 100644 --- a/app/Http/Controllers/Api/DepreciationsController.php +++ b/app/Http/Controllers/Api/DepreciationsController.php @@ -28,7 +28,9 @@ class DepreciationsController extends Controller $depreciations = $depreciations->TextSearch($request->input('search')); } - $offset = (($depreciations) && (request('offset') > $depreciations->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($depreciations) && ($request->get('offset') > $depreciations->count())) ? $depreciations->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/GroupsController.php b/app/Http/Controllers/Api/GroupsController.php index 933b5423d8..7fe150a422 100644 --- a/app/Http/Controllers/Api/GroupsController.php +++ b/app/Http/Controllers/Api/GroupsController.php @@ -28,7 +28,9 @@ class GroupsController extends Controller $groups = $groups->TextSearch($request->input('search')); } - $offset = (($groups) && (request('offset') > $groups->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($groups) && ($request->get('offset') > $groups->count())) ? $groups->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 2f260ac246..a16dd4fa83 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -82,7 +82,9 @@ class LicensesController extends Controller } - $offset = (($licenses) && (request('offset') > $licenses->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($licenses) && ($request->get('offset') > $licenses->count())) ? $licenses->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index ce417ce05d..d634f59599 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -52,8 +52,9 @@ class LocationsController extends Controller } - - $offset = (($locations) && (request('offset') > $locations->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($locations) && ($request->get('offset') > $locations->count())) ? $locations->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/ManufacturersController.php b/app/Http/Controllers/Api/ManufacturersController.php index cbdf106c11..463219f63b 100644 --- a/app/Http/Controllers/Api/ManufacturersController.php +++ b/app/Http/Controllers/Api/ManufacturersController.php @@ -37,9 +37,9 @@ class ManufacturersController extends Controller } - - - $offset = (($manufacturers) && (request('offset') > $manufacturers->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($manufacturers) && ($request->get('offset') > $manufacturers->count())) ? $manufacturers->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index b90ea25c80..9e7373affc 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -30,7 +30,9 @@ class StatuslabelsController extends Controller $statuslabels = $statuslabels->TextSearch($request->input('search')); } - $offset = (($statuslabels) && (request('offset') > $statuslabels->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($statuslabels) && ($request->get('offset') > $statuslabels->count())) ? $statuslabels->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/SuppliersController.php b/app/Http/Controllers/Api/SuppliersController.php index 3b31781969..a739497944 100644 --- a/app/Http/Controllers/Api/SuppliersController.php +++ b/app/Http/Controllers/Api/SuppliersController.php @@ -33,7 +33,9 @@ class SuppliersController extends Controller $suppliers = $suppliers->TextSearch($request->input('search')); } - $offset = (($suppliers) && (request('offset') > $suppliers->count())) ? 0 : request('offset', 0); + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($suppliers) && ($request->get('offset') > $suppliers->count())) ? $suppliers->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 608a40d986..0375cdfabd 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -88,7 +88,10 @@ class UsersController extends Controller } $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; - $offset = (($users) && (request('offset') > $users->count())) ? 0 : request('offset', 0); + + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which + // case we override with the actual count, so we should return 0 items. + $offset = (($users) && ($request->get('offset') > $users->count())) ? $users->count() : $request->get('offset', 0); // Check to make sure the limit is not higher than the max allowed ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');