From 1d619cd892e5bf4b94755cc9ec2dac4e9ba8fbfe Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sun, 3 Jan 2016 12:02:20 +0000 Subject: [PATCH] Only pull back lowest if available --- app/Presenters/ComponentGroupPresenter.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Presenters/ComponentGroupPresenter.php b/app/Presenters/ComponentGroupPresenter.php index babcca94..e31a45f4 100644 --- a/app/Presenters/ComponentGroupPresenter.php +++ b/app/Presenters/ComponentGroupPresenter.php @@ -20,31 +20,37 @@ class ComponentGroupPresenter extends AbstractPresenter /** * Returns the lowest component status. * - * @return string + * @return string|null */ public function lowest_status() { - return $this->wrappedObject->enabled_components->first()->human_status; + if ($enabledComponents = $this->wrappedObject->enabled_components()->orderBy('status', 'desc')->first()) { + return $enabledComponents->status; + } } /** * Returns the lowest component status, readable by humans. * - * @return string + * @return string|null */ public function lowest_human_status() { - return $this->wrappedObject->enabled_components->first()->human_status; + if ($enabledComponents = $this->wrappedObject->enabled_components()->orderBy('status', 'desc')->first()) { + return $enabledComponents->human_status; + } } /** * Returns the lowest component status color. * - * @return string + * @return string|null */ public function lowest_status_color() { - return $this->wrappedObject->enabled_components->first()->status_color; + if ($enabledComponents = $this->wrappedObject->enabled_components()->orderBy('status', 'desc')->first()) { + return $enabledComponents->status_color; + } } /**