Full text search fixes - addresses laravel bug :(

This commit is contained in:
snipe 2017-10-17 12:48:18 -07:00
parent 9e9a5b7a53
commit e9c3d6bfb7

View file

@ -137,30 +137,61 @@ class AssetsController extends Controller
// 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
// related to fulltext searches on complex queries.
// I am sad. :(
switch ($request->input('status')) { switch ($request->input('status')) {
case 'Deleted': case 'Deleted':
$assets->withTrashed()->Deleted(); $assets->withTrashed()->Deleted();
break; break;
case 'Pending': case 'Pending':
$assets->Pending(); $assets->join('status_labels',function ($join) {
$join->on('status_labels.id', "=", "assets.status_id")
->where('status_labels.deployable','=',0)
->where('status_labels.pending','=',1)
->where('status_labels.archived', '=', 0);
});
break; break;
case 'RTD': case 'RTD':
$assets->RTD(); $assets->join('status_labels',function ($join) {
$join->on('status_labels.id', "=", "assets.status_id")
->where('status_labels.deployable','=',1)
->where('status_labels.pending','=',0)
->where('status_labels.archived', '=', 0);
});
break; break;
case 'Undeployable': case 'Undeployable':
$assets->Undeployable(); $assets->Undeployable();
break; break;
case 'Archived': case 'Archived':
$assets->Archived(); $assets->join('status_labels',function ($join) {
$join->on('status_labels.id', "=", "assets.status_id")
->where('status_labels.deployable','=',0)
->where('status_labels.pending','=',0)
->where('status_labels.archived', '=', 1);
});
break; break;
case 'Requestable': case 'Requestable':
$assets->RequestableAssets(); $assets->where('assets.requestable', '=', 1)
->join('status_labels',function ($join) {
$join->on('status_labels.id', "=", "assets.status_id")
->where('status_labels.deployable','=',1)
->where('status_labels.pending','=',0)
->where('status_labels.archived', '=', 0);
});
break; break;
case 'Deployed': case 'Deployed':
$assets->Deployed(); // more sad, horrible workarounds for laravel bugs when doing full text searches
$assets->where('assets.assigned_to', '>', '0');
break; break;
default: default:
$assets->NotArchived(); // terrible workaround for complex-query Laravel bug in fulltext
$assets->join('status_labels',function ($join) {
$join->on('status_labels.id', "=", "assets.status_id")
->where('status_labels.archived', '=', 0);
});
} }