Cachet/app/Composers/StatusPageComposer.php

71 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Cachet.
*
2015-07-06 17:37:01 +01:00
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Composers;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident;
2015-06-01 11:45:48 +01:00
use Illuminate\Contracts\View\View;
class StatusPageComposer
{
/**
* Index page view composer.
*
2015-06-01 11:45:48 +01:00
* @param \Illuminate\Contracts\View\View $view
2015-08-30 22:45:27 +01:00
*
* @return void
*/
2015-01-28 00:51:28 -06:00
public function compose(View $view)
{
2015-01-14 10:11:47 +00:00
// Default data
$withData = [
2015-10-11 11:35:00 +01:00
'systemStatus' => 'warning',
2015-01-14 10:11:47 +00:00
'systemMessage' => trans('cachet.service.bad'),
'favicon' => 'favicon-high-alert',
2015-01-14 10:11:47 +00:00
];
2015-01-14 16:19:11 +00:00
if (Component::notStatus(1)->count() === 0) {
// If all our components are ok, do we have any non-fixed incidents?
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
$incidentCount = $incidents->count();
if ($incidentCount === 0 || ($incidentCount >= 1 && (int) $incidents->first()->status === 4)) {
2015-01-14 10:11:47 +00:00
$withData = [
'systemStatus' => 'success',
'systemMessage' => trans('cachet.service.good'),
'favicon' => 'favicon',
2015-01-14 10:11:47 +00:00
];
}
} else {
if (Component::whereIn('status', [2, 3])->count() > 0) {
$withData['favicon'] = 'favicon-medium-alert';
}
}
// Scheduled maintenance code.
$scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
// Component & Component Group lists.
$usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
$view->with($withData)
->withComponentGroups($componentGroups)
->withUngroupedComponents($ungroupedComponents)
->withScheduledMaintenance($scheduledMaintenance)
->withPageTitle(Setting::get('app_name'));
}
}