コード例 #1
0
ファイル: MetricsComposer.php プロジェクト: guduchango/Cachet
 /**
  * Metrics view composer.
  *
  * @param \Illuminate\Contracts\View\View $view
  *
  * @return void
  */
 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);
 }
コード例 #2
0
 /**
  * Returns metrics in a readily formatted way.
  *
  * @param \CachetHQ\Cachet\Models\Metric $metric
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function getMetrics(Metric $metric)
 {
     $metricData = [];
     $type = Binput::get('filter', 'last_hour');
     switch ($type) {
         case 'last_hour':
             $metricData = $this->metricRepository->listPointsLastHour($metric);
             break;
         case 'today':
             $metricData = $this->metricRepository->listPointsToday($metric);
             break;
         case 'week':
             $metricData = $this->metricRepository->listPointsForWeek($metric);
             break;
         case 'month':
             $metricData = $this->metricRepository->listPointsForMonth($metric);
             break;
     }
     return $this->item(['metric' => $metric->toArray(), 'items' => $metricData]);
 }