mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-02-12 11:31:07 +01:00
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
|
<?php
|
||
|
|
||
|
/*
|
||
|
* This file is part of Cachet.
|
||
|
*
|
||
|
* (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\Metric;
|
||
|
use CachetHQ\Cachet\Repositories\MetricRepository;
|
||
|
use Illuminate\Contracts\View\View;
|
||
|
|
||
|
class MetricsComposer
|
||
|
{
|
||
|
/**
|
||
|
* @var \CachetHQ\Cachet\Repositories\MetricRepository
|
||
|
*/
|
||
|
protected $metricRepository;
|
||
|
|
||
|
/**
|
||
|
* Construct a new home controller instance.
|
||
|
*
|
||
|
* @param \CachetHQ\Cachet\Repositories\MetricRepository $metricRepository
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function __construct(MetricRepository $metricRepository)
|
||
|
{
|
||
|
$this->metricRepository = $metricRepository;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Metrics view composer.
|
||
|
*
|
||
|
* @param \Illuminate\Contracts\View\View $view
|
||
|
*/
|
||
|
public function compose(View $view)
|
||
|
{
|
||
|
$metrics = null;
|
||
|
$metricData = [];
|
||
|
if ($displayMetrics = Setting::get('display_graphs')) {
|
||
|
$metrics = Metric::where('display_chart', 1)->get();
|
||
|
|
||
|
$metrics->map(function ($metric) use (&$metricData) {
|
||
|
$metricData[$metric->id] = [
|
||
|
'today' => $this->metricRepository->listPointsToday($metric),
|
||
|
'week' => $this->metricRepository->listPointsForWeek($metric),
|
||
|
'month' => $this->metricRepository->listPointsForMonth($metric),
|
||
|
];
|
||
|
});
|
||
|
}
|
||
|
|
||
|
$view->withDisplayMetrics($displayMetrics)
|
||
|
->withMetrics($metrics)
|
||
|
->withMetricData($metricData);
|
||
|
}
|
||
|
}
|