From 1307ba41c85c2fff60bf0112233a25cbf26b460c Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 8 May 2013 09:37:56 -0400 Subject: [PATCH] Changed the event count lookups to use find() instead of custom functions --- web/app/Controller/MonitorsController.php | 40 ++++++++++++++++++++--- web/app/Model/Monitor.php | 35 -------------------- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/web/app/Controller/MonitorsController.php b/web/app/Controller/MonitorsController.php index 58b7852d2..9eefd3ee8 100644 --- a/web/app/Controller/MonitorsController.php +++ b/web/app/Controller/MonitorsController.php @@ -2,13 +2,43 @@ class MonitorsController extends AppController { public function index() { + $this->loadModel('Event'); $monitoroptions['fields'] = array('Name', 'Id', 'Function', 'Host'); $this->set('monitors', $this->Monitor->find('all', $monitoroptions)); - $this->set('eventsLastHour', $this->Monitor->getEventsLastHour()); - $this->set('eventsLastDay', $this->Monitor->getEventsLastDay()); - $this->set('eventsLastWeek', $this->Monitor->getEventsLastWeek()); - $this->set('eventsLastMonth', $this->Monitor->getEventsLastMonth()); - $this->set('eventsArchived', $this->Monitor->getEventsArchived()); + $monitors = $this->Monitor->find('list', array('fields' => array('Id'))); + $intervals = array('HOUR', 'DAY', 'WEEK', 'MONTH'); + foreach ($monitors as $monitor) { + foreach ($intervals as $interval) { + + } + } + + $this->set('eventsLastHour', $this->Event->find('all', array( + 'fields' => 'COUNT(Event.Id) AS count', + 'group' => 'Event.MonitorId', + 'conditions' => 'Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 HOUR)' + ))); + $this->set('eventsLastDay', $this->Event->find('all', array( + 'fields' => 'COUNT(Event.Id) AS count', + 'group' => 'Event.MonitorId', + 'conditions' => 'Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 DAY)' + ))); + $this->set('eventsLastWeek', $this->Event->find('all', array( + 'fields' => 'COUNT(Event.Id) AS count', + 'group' => 'Event.MonitorId', + 'conditions' => 'Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 WEEK)' + ))); + $this->set('eventsLastMonth', $this->Event->find('all', array( + 'fields' => 'COUNT(Event.Id) AS count', + 'group' => 'Event.MonitorId', + 'conditions' => 'Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 MONTH)' + ))); + $this->set('eventsArchived', $this->Event->find('all', array( + 'fields' => 'COUNT(Event.Id) AS count', + 'group' => 'Event.MonitorId', + 'conditions' => array('Event.Archived' => 1) + ))); + } public function view($id = null) { diff --git a/web/app/Model/Monitor.php b/web/app/Model/Monitor.php index acec36da2..06e1e10e7 100644 --- a/web/app/Model/Monitor.php +++ b/web/app/Model/Monitor.php @@ -14,40 +14,5 @@ 'fields' => 'Zone.Id' ) ); - - public function getEventsLastHour() { - $conditions = array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 HOUR)'); - $group = array('Event.MonitorId'); - $fields = array('count(Event.Id) AS count'); - return $this->Event->find('all', compact('conditions', 'group', 'fields')); - } - - public function getEventsLastDay() { - $conditions = array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 DAY)'); - $group = array('Event.MonitorId'); - $fields = array('count(Event.Id) AS count'); - return $this->Event->find('all', compact('conditions', 'group', 'fields')); - } - - public function getEventsLastWeek() { - $conditions = array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 WEEK)'); - $group = array('Event.MonitorId'); - $fields = array('count(Event.Id) AS count'); - return $this->Event->find('all', compact('conditions', 'group', 'fields')); - } - - public function getEventsLastMonth() { - $conditions = array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 MONTH)'); - $group = array('Event.MonitorId'); - $fields = array('count(Event.Id) AS count'); - return $this->Event->find('all', compact('conditions', 'group', 'fields')); - } - - public function getEventsArchived() { - $conditions = array('Event.Archived = 1'); - $group = array('Event.MonitorId'); - $fields = array('count(Event.Id) AS count'); - return $this->Event->find('all', compact('conditions', 'group', 'fields')); - } } ?>