mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
Moved search scope lower to fix weird (possible Laravel) bug w/prepared statements
This commit is contained in:
parent
a4b32e2328
commit
9293f17707
|
@ -36,14 +36,15 @@ class AssetModelsController extends Controller
|
||||||
->with('category','depreciation', 'manufacturer','fieldset')
|
->with('category','depreciation', 'manufacturer','fieldset')
|
||||||
->withCount('assets');
|
->withCount('assets');
|
||||||
|
|
||||||
if ($request->has('search')) {
|
|
||||||
$assetmodels->TextSearch($request->input('search'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->has('status')) {
|
if ($request->has('status')) {
|
||||||
$assetmodels->onlyTrashed();
|
$assetmodels->onlyTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->has('search')) {
|
||||||
|
$assetmodels->TextSearch($request->input('search'));
|
||||||
|
}
|
||||||
|
|
||||||
$offset = $request->input('offset', 0);
|
$offset = $request->input('offset', 0);
|
||||||
$limit = $request->input('limit', 50);
|
$limit = $request->input('limit', 50);
|
||||||
|
@ -60,6 +61,7 @@ class AssetModelsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$total = $assetmodels->count();
|
$total = $assetmodels->count();
|
||||||
$assetmodels = $assetmodels->skip($offset)->take($limit)->get();
|
$assetmodels = $assetmodels->skip($offset)->take($limit)->get();
|
||||||
return (new AssetModelsTransformer)->transformAssetModels($assetmodels, $total);
|
return (new AssetModelsTransformer)->transformAssetModels($assetmodels, $total);
|
||||||
|
|
|
@ -54,6 +54,7 @@ class AssetsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->authorize('index', Asset::class);
|
$this->authorize('index', Asset::class);
|
||||||
|
|
||||||
$allowed_columns = [
|
$allowed_columns = [
|
||||||
|
@ -78,30 +79,28 @@ class AssetsController extends Controller
|
||||||
];
|
];
|
||||||
|
|
||||||
$filter = array();
|
$filter = array();
|
||||||
|
|
||||||
if ($request->has('filter')) {
|
if ($request->has('filter')) {
|
||||||
$filter = json_decode($request->input('filter'));
|
$filter = json_decode($request->input('filter'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
|
$all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
|
||||||
foreach ($all_custom_fields as $field) {
|
foreach ($all_custom_fields as $field) {
|
||||||
$allowed_columns[]=$field->db_column_name();
|
$allowed_columns[]=$field->db_column_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
$assets = Company::scopeCompanyables(Asset::select('assets.*'),"company_id","assets")->with(
|
$assets = Company::scopeCompanyables(Asset::select('assets.*'),"company_id","assets")
|
||||||
'location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo',
|
->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo',
|
||||||
'model.category', 'model.manufacturer', 'model.fieldset','supplier');
|
'model.category', 'model.manufacturer', 'model.fieldset','supplier');
|
||||||
|
|
||||||
|
|
||||||
if (count($filter) > 0) {
|
|
||||||
$assets->ByFilter($filter);
|
|
||||||
} elseif ($request->has('search')) {
|
|
||||||
$assets->TextSearch($request->input('search'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// These are used by the API to query against specific ID numbers
|
|
||||||
|
// 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.
|
||||||
if ($request->has('status_id')) {
|
if ($request->has('status_id')) {
|
||||||
$assets->where('assets.status_id', '=', $request->input('status_id'));
|
$assets->where('assets.status_id', '=', $request->input('status_id'));
|
||||||
}
|
}
|
||||||
|
@ -116,6 +115,7 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
if ($request->has('location_id')) {
|
if ($request->has('location_id')) {
|
||||||
$assets->where('assets.location_id', '=', $request->input('location_id'));
|
$assets->where('assets.location_id', '=', $request->input('location_id'));
|
||||||
|
// dd($assets->toSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->has('supplier_id')) {
|
if ($request->has('supplier_id')) {
|
||||||
|
@ -145,7 +145,6 @@ class AssetsController extends Controller
|
||||||
$limit = $request->input('limit', 50);
|
$limit = $request->input('limit', 50);
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
|
|
||||||
|
|
||||||
// This is used by the sidenav, mostly
|
// This is used by the sidenav, mostly
|
||||||
|
|
||||||
// We switched from using query scopes here because of a Laravel bug
|
// We switched from using query scopes here because of a Laravel bug
|
||||||
|
@ -205,6 +204,12 @@ class AssetsController extends Controller
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count($filter) > 0) {
|
||||||
|
$assets->ByFilter($filter);
|
||||||
|
} elseif ($request->has('search')) {
|
||||||
|
$assets->TextSearch($request->input('search'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// This is kinda gross, but we need to do this because the Bootstrap Tables
|
// This is kinda gross, but we need to do this because the Bootstrap Tables
|
||||||
// API passes custom field ordering as custom_fields.fieldname, and we have to strip
|
// API passes custom field ordering as custom_fields.fieldname, and we have to strip
|
||||||
|
|
|
@ -25,9 +25,6 @@ class LicensesController extends Controller
|
||||||
$this->authorize('view', License::class);
|
$this->authorize('view', License::class);
|
||||||
$licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier')->withCount('freeSeats'));
|
$licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier')->withCount('freeSeats'));
|
||||||
|
|
||||||
if ($request->has('search')) {
|
|
||||||
$licenses = $licenses->TextSearch($request->input('search'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->has('company_id')) {
|
if ($request->has('company_id')) {
|
||||||
$licenses->where('company_id','=',$request->input('company_id'));
|
$licenses->where('company_id','=',$request->input('company_id'));
|
||||||
|
@ -73,6 +70,12 @@ class LicensesController extends Controller
|
||||||
$licenses->where('supplier_id','=',$request->input('supplier_id'));
|
$licenses->where('supplier_id','=',$request->input('supplier_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($request->has('search')) {
|
||||||
|
$licenses = $licenses->TextSearch($request->input('search'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$offset = request('offset', 0);
|
$offset = request('offset', 0);
|
||||||
$limit = request('limit', 50);
|
$limit = request('limit', 50);
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
|
@ -94,7 +97,8 @@ class LicensesController extends Controller
|
||||||
$licenses = $licenses->orderBy($sort, $order);
|
$licenses = $licenses->orderBy($sort, $order);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$total = $licenses->count();
|
$total = $licenses->count();
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,6 @@ class UsersController extends Controller
|
||||||
$users = Company::scopeCompanyables($users);
|
$users = Company::scopeCompanyables($users);
|
||||||
|
|
||||||
|
|
||||||
if ($request->has('search')) {
|
|
||||||
$users = $users->TextSearch($request->input('search'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (($request->has('deleted')) && ($request->input('deleted')=='true')) {
|
if (($request->has('deleted')) && ($request->input('deleted')=='true')) {
|
||||||
$users = $users->GetDeleted();
|
$users = $users->GetDeleted();
|
||||||
}
|
}
|
||||||
|
@ -83,6 +78,10 @@ class UsersController extends Controller
|
||||||
$users = $users->where('users.department_id','=',$request->input('department_id'));
|
$users = $users->where('users.department_id','=',$request->input('department_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->has('search')) {
|
||||||
|
$users = $users->TextSearch($request->input('search'));
|
||||||
|
}
|
||||||
|
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
$offset = request('offset', 0);
|
$offset = request('offset', 0);
|
||||||
$limit = request('limit', 20);
|
$limit = request('limit', 20);
|
||||||
|
@ -111,6 +110,8 @@ class UsersController extends Controller
|
||||||
$users = $users->orderBy($sort, $order);
|
$users = $users->orderBy($sort, $order);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$total = $users->count();
|
$total = $users->count();
|
||||||
$users = $users->skip($offset)->take($limit)->get();
|
$users = $users->skip($offset)->take($limit)->get();
|
||||||
return (new UsersTransformer)->transformUsers($users, $total);
|
return (new UsersTransformer)->transformUsers($users, $total);
|
||||||
|
|
Loading…
Reference in a new issue