Changed the event count lookups to use find() instead of custom functions
This commit is contained in:
parent
08f57b6b47
commit
1307ba41c8
|
@ -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) {
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue