zoneminder/web/app/Controller/EventsController.php

46 lines
2.1 KiB
PHP
Raw Normal View History

<?php
class EventsController extends AppController {
public $helpers = array('Paginator');
public $components = array('Paginator');
2013-05-16 05:51:53 +08:00
public function index() {
$this->loadModel('Monitor');
$conditions = array();
$events_per_page = Configure::read('ZM_WEB_EVENTS_PER_PAGE');
$this->paginate = array(
'fields' => array('Event.Name', 'Event.Length', 'Event.MonitorId', 'Event.Id', 'Monitor.Name'),
'limit' => $events_per_page,
'order' => array( 'Event.Id' => 'asc'),
'conditions' => $conditions
);
$data = $this->paginate('Event');
$this->set('events', $data);
$this->set('monitors', $this->Monitor->find('all', array('fields' => array('Monitor.Name') )));
$this->set('eventsLastHour', $this->Monitor->query('SELECT COUNT(Event.Id) AS count FROM Monitors AS Monitor LEFT JOIN Events as Event ON Monitor.Id = Event.MonitorId AND Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 HOUR) GROUP BY Monitor.Id'));
$this->set('eventsLastDay', $this->Monitor->query('SELECT COUNT(Event.Id) AS count FROM Monitors AS Monitor LEFT JOIN Events as Event ON Monitor.Id = Event.MonitorId AND Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY Monitor.Id'));
$this->set('eventsLastWeek', $this->Monitor->query('SELECT COUNT(Event.Id) AS count FROM Monitors AS Monitor LEFT JOIN Events as Event ON Monitor.Id = Event.MonitorId AND Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 WEEK) GROUP BY Monitor.Id'));
$this->set('eventsLastMonth', $this->Monitor->query('SELECT COUNT(Event.Id) AS count FROM Monitors AS Monitor LEFT JOIN Events as Event ON Monitor.Id = Event.MonitorId AND Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY Monitor.Id'));
$this->set('eventsArchived', $this->Monitor->query('SELECT COUNT(Event.Id) AS count FROM Monitors AS Monitor LEFT JOIN Events as Event ON Monitor.Id = Event.MonitorId AND Event.Archived = 1 GROUP BY Monitor.Id'));
2013-05-16 05:51:53 +08:00
}
public function view($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid event'));
}
$event = $this->Event->findById($id);
if (!$event) {
throw new NotFoundException(__('Invalid event'));
}
$this->set('event', $event);
}
}
?>