From 5ccd601695af376e8ae3d162739712ad7c4e07eb Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sun, 3 Jan 2016 12:26:27 +0000 Subject: [PATCH] Fixes missing titles --- app/Models/ComponentGroup.php | 12 +++++++++++- app/Presenters/ComponentGroupPresenter.php | 12 ++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/Models/ComponentGroup.php b/app/Models/ComponentGroup.php index 6122bc45..b687c286 100644 --- a/app/Models/ComponentGroup.php +++ b/app/Models/ComponentGroup.php @@ -53,7 +53,7 @@ class ComponentGroup extends Model implements HasPresenter * * @var string[] */ - protected $with = ['enabled_components']; + protected $with = ['enabled_components', 'enabled_components_lowest']; /** * A group can have many components. @@ -75,6 +75,16 @@ class ComponentGroup extends Model implements HasPresenter return $this->components()->enabled(); } + /** + * Return all of the enabled components ordered by status. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function enabled_components_lowest() + { + return $this->components()->enabled()->orderBy('status', 'desc'); + } + /** * Get the presenter class. * diff --git a/app/Presenters/ComponentGroupPresenter.php b/app/Presenters/ComponentGroupPresenter.php index e31a45f4..4899fecc 100644 --- a/app/Presenters/ComponentGroupPresenter.php +++ b/app/Presenters/ComponentGroupPresenter.php @@ -24,8 +24,8 @@ class ComponentGroupPresenter extends AbstractPresenter */ public function lowest_status() { - if ($enabledComponents = $this->wrappedObject->enabled_components()->orderBy('status', 'desc')->first()) { - return $enabledComponents->status; + if ($component = $this->wrappedObject->enabled_components_lowest->first()) { + return $component->status; } } @@ -36,8 +36,8 @@ class ComponentGroupPresenter extends AbstractPresenter */ public function lowest_human_status() { - if ($enabledComponents = $this->wrappedObject->enabled_components()->orderBy('status', 'desc')->first()) { - return $enabledComponents->human_status; + if ($component = $this->wrappedObject->enabled_components_lowest->first()) { + return $component->human_status; } } @@ -48,8 +48,8 @@ class ComponentGroupPresenter extends AbstractPresenter */ public function lowest_status_color() { - if ($enabledComponents = $this->wrappedObject->enabled_components()->orderBy('status', 'desc')->first()) { - return $enabledComponents->status_color; + if ($component = $this->wrappedObject->enabled_components_lowest->first()) { + return $component->status_color; } }