Cachet/app/Composers/IndexComposer.php

55 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Cachet.
*
2015-05-25 17:59:08 +01:00
* (c) Cachet HQ <support@cachethq.io>
*
* 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\Models\Component;
use CachetHQ\Cachet\Models\Incident;
2015-06-01 11:45:48 +01:00
use Illuminate\Contracts\View\View;
class IndexComposer
{
/**
* Index page view composer.
*
2015-06-01 11:45:48 +01:00
* @param \Illuminate\Contracts\View\View $view
*/
2015-01-28 00:51:28 -06:00
public function compose(View $view)
{
2015-01-14 10:11:47 +00:00
// Default data
$withData = [
'systemStatus' => 'danger',
'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';
}
}
2015-01-14 10:11:47 +00:00
$view->with($withData);
}
}