From a0f12575fe23e63d98d84369c52bc5f1694950a5 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 19 Nov 2014 15:49:38 +0000 Subject: [PATCH] Add API function to return event counts for console view --- web/api/app/Controller/EventsController.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/web/api/app/Controller/EventsController.php b/web/api/app/Controller/EventsController.php index 394e61caf..9cf18a004 100644 --- a/web/api/app/Controller/EventsController.php +++ b/web/api/app/Controller/EventsController.php @@ -108,4 +108,23 @@ class EventsController extends AppController { } else { return $this->flash(__('The event could not be deleted. Please, try again.'), array('action' => 'index')); } - }} + } + + + public function consoleEvents($interval = null) { + $this->Event->recursive = -1; + $results = array(); + + $query = $this->Event->query("select MonitorId, COUNT(*) AS Count from Events WHERE StartTime >= (DATE_SUB(NOW(), interval $interval)) GROUP BY MonitorId;"); + + foreach ($query as $result) { + $results[$result['Events']['MonitorId']] = $result[0]['Count']; + } + + $this->set(array( + 'results' => $results, + '_serialize' => array('results') + )); + } + +}