From babf7c064b2918dfdd9c69c1d363d36d9577ea9a Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Mar 2022 16:38:45 +0000 Subject: [PATCH] Added ability to filter status label index endpoint by status type Signed-off-by: snipe --- .../Controllers/Api/StatuslabelsController.php | 15 +++++++++++++++ app/Models/Statuslabel.php | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index 08025567b2..0ec94cde88 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -30,6 +30,21 @@ class StatuslabelsController extends Controller $statuslabels = $statuslabels->TextSearch($request->input('search')); } + + // if a status_type is passed, filter by that + if ($request->filled('status_type')) { + if (strtolower($request->input('status_type'))== 'pending') { + $statuslabels = $statuslabels->Pending(); + } elseif (strtolower($request->input('status_type'))== 'archived') { + $statuslabels = $statuslabels->Archived(); + } elseif (strtolower($request->input('status_type'))== 'deployable') { + $statuslabels = $statuslabels->Deployable(); + } elseif (strtolower($request->input('status_type'))== 'undeployable') { + $statuslabels = $statuslabels->Undeployable(); + } + + } + // 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); diff --git a/app/Models/Statuslabel.php b/app/Models/Statuslabel.php index da856b4b7f..01c796f9aa 100755 --- a/app/Models/Statuslabel.php +++ b/app/Models/Statuslabel.php @@ -120,6 +120,18 @@ class Statuslabel extends SnipeModel ->where('deployable', '=', 1); } + /** + * Query builder scope for deployable status types + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeUndeployable() + { + return $this->where('pending', '=', 0) + ->where('archived', '=', 0) + ->where('deployable', '=', 0); + } + /** * Helper function to determine type attributes *