From 1543643f4ce6048be232c71ac61729849ac57e33 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 21 Apr 2015 10:13:08 +0100 Subject: [PATCH] Revert "Refactored the way incidents are pulled out of the database on the homepage" --- app/Http/Controllers/HomeController.php | 21 ++++++++++----------- resources/views/index.blade.php | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 63b7a6fc..95687216 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -74,24 +74,23 @@ class HomeController extends AbstractController $metrics = Metric::where('display_chart', 1)->get(); } + $allIncidents = []; $daysToShow = Setting::get('app_incident_days') ?: 7; $incidentDays = range(0, $daysToShow); $dateFormat = Setting::get('date_format') ?: 'jS F Y'; - $allIncidents = Incident::notScheduled()->whereBetween('created_at', [ - $startDate->copy()->subDays($daysToShow)->format('Y-m-d').' 00:00:00', - $startDate->format('Y-m-d').' 23:59:59', - ])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use ($dateFormat) { - return $incident->created_at->format($dateFormat); - }); - - // Add in days that have no incidents foreach ($incidentDays as $i) { $date = $startDate->copy()->subDays($i); - if (!isset($allIncidents[$date->format($dateFormat)])) { - $allIncidents[$date->format($dateFormat)] = []; - } + $incidents = Incident::notScheduled()->whereBetween('created_at', [ + $date->format('Y-m-d').' 00:00:00', + $date->format('Y-m-d').' 23:59:59', + ])->orderBy('created_at', 'desc')->get(); + + $allIncidents[] = [ + 'date' => (new Date($date->toDateString()))->format($dateFormat), + 'incidents' => $incidents, + ]; } // Scheduled maintenance code. diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index ec9ffca9..d741fc0b 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -34,8 +34,8 @@ @endif

{{ trans('cachet.incidents.past') }}

- @foreach($allIncidents as $date => $incidents) - @include('partials.incidents', compact('date', 'incidents')) + @foreach($allIncidents as $incidents) + @include('partials.incidents', $incidents) @endforeach