2014-11-16 22:26:08 +00:00
|
|
|
<?php
|
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers;
|
2014-12-01 16:46:56 +00:00
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
use CachetHQ\Cachet\Models\Component;
|
|
|
|
use CachetHQ\Cachet\Models\Incident;
|
|
|
|
use CachetHQ\Cachet\Models\Setting;
|
2015-01-04 12:33:38 +00:00
|
|
|
use Exception;
|
2015-01-03 00:36:27 -06:00
|
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
2015-01-01 19:44:15 +00:00
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown;
|
2015-01-01 15:45:04 +00:00
|
|
|
use Illuminate\Routing\Controller;
|
2015-01-01 16:18:24 +00:00
|
|
|
use Illuminate\Support\Facades\View;
|
2015-01-14 20:30:23 +00:00
|
|
|
use Jenssegers\Date\Date;
|
2014-12-01 16:46:56 +00:00
|
|
|
|
2015-01-01 15:45:04 +00:00
|
|
|
class HomeController extends Controller
|
|
|
|
{
|
2014-11-27 16:05:00 +00:00
|
|
|
/**
|
|
|
|
* Returns the rendered Blade templates.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-01 08:38:26 +00:00
|
|
|
* @return \Illuminate\View\View
|
2014-11-27 16:05:00 +00:00
|
|
|
*/
|
2014-12-20 21:20:17 +00:00
|
|
|
public function showIndex()
|
|
|
|
{
|
2015-01-01 13:37:47 +00:00
|
|
|
$components = Component::orderBy('order')->orderBy('created_at')->get();
|
|
|
|
|
2015-01-01 21:58:27 +00:00
|
|
|
$allIncidents = [];
|
|
|
|
|
2015-01-02 08:23:29 +00:00
|
|
|
$incidentDays = Setting::get('app_incident_days') ?: 7;
|
|
|
|
|
2015-01-14 20:30:23 +00:00
|
|
|
$today = Date::now();
|
|
|
|
$startDate = Date::now();
|
|
|
|
|
|
|
|
$dateFormat = Setting::get('date_format') ?: 'jS F Y';
|
2015-01-03 00:36:27 -06:00
|
|
|
|
|
|
|
// Check if we have another starting date
|
|
|
|
if (Binput::has('start_date')) {
|
|
|
|
try {
|
|
|
|
// If date provided is valid
|
2015-01-14 20:30:23 +00:00
|
|
|
$oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
|
2015-01-03 00:36:27 -06:00
|
|
|
// If trying to get a future date fallback to today
|
|
|
|
if ($today->gt($oldDate)) {
|
|
|
|
$startDate = $oldDate;
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Fallback to today
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 08:23:29 +00:00
|
|
|
foreach (range(0, $incidentDays) as $i) {
|
2015-01-03 00:36:27 -06:00
|
|
|
$date = $startDate->copy()->subDays($i);
|
2015-01-01 21:58:27 +00:00
|
|
|
$incidents = Incident::whereBetween('created_at', [
|
|
|
|
$date->format('Y-m-d').' 00:00:00',
|
|
|
|
$date->format('Y-m-d').' 23:59:59',
|
|
|
|
])->orderBy('created_at', 'desc')->get();
|
2015-01-14 20:30:23 +00:00
|
|
|
$allIncidents[] = ['date' => $date->format($dateFormat), 'incidents' => $incidents];
|
2015-01-01 21:58:27 +00:00
|
|
|
}
|
|
|
|
|
2014-12-30 22:25:38 +00:00
|
|
|
return View::make('index', [
|
2015-01-03 00:36:27 -06:00
|
|
|
'components' => $components,
|
|
|
|
'allIncidents' => $allIncidents,
|
|
|
|
'pageTitle' => Setting::get('app_name'),
|
|
|
|
'aboutApp' => Markdown::render(Setting::get('app_about')),
|
|
|
|
'canPageForward' => (bool) $today->gt($startDate),
|
|
|
|
'previousDate' => $startDate->copy()->subWeek()->subDay()->toDateString(),
|
|
|
|
'nextDate' => $startDate->copy()->addWeek()->addDay()->toDateString(),
|
2014-12-30 22:25:38 +00:00
|
|
|
]);
|
2014-11-27 16:05:00 +00:00
|
|
|
}
|
2014-11-27 22:08:28 +00:00
|
|
|
}
|