2013-05-01 19:02:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class EventsController extends AppController {
|
2013-05-03 19:34:45 +08:00
|
|
|
public $helpers = array('Paginator');
|
2013-05-01 19:02:12 +08:00
|
|
|
public $components = array('Paginator');
|
|
|
|
|
2013-05-16 05:51:53 +08:00
|
|
|
public function index() {
|
2013-07-19 19:30:13 +08:00
|
|
|
|
2013-05-16 05:42:42 +08:00
|
|
|
$this->loadModel('Monitor');
|
2013-05-31 10:54:51 +08:00
|
|
|
$this->loadModel('Frame');
|
2013-07-19 19:30:13 +08:00
|
|
|
$conditions = array();
|
|
|
|
|
|
|
|
$this->set('thumb_width', Configure::read('ZM_WEB_LIST_THUMB_WIDTH'));
|
2013-05-01 19:02:12 +08:00
|
|
|
|
2013-05-29 19:54:06 +08:00
|
|
|
$named = $this->extractNamedParams(
|
2013-07-19 19:30:13 +08:00
|
|
|
array('MonitorId', 'StartTime' )
|
2013-05-29 19:54:06 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($named) {
|
2013-07-19 19:30:13 +08:00
|
|
|
foreach ($named as $key => $value) {
|
|
|
|
switch ($key) {
|
|
|
|
case "StartTime":
|
|
|
|
$StartTime = array("$key BETWEEN FROM_UNIXTIME($value[0]) and FROM_UNIXTIME($value[1])");
|
|
|
|
array_push($conditions, $StartTime);
|
|
|
|
break;
|
|
|
|
case "MonitorId":
|
|
|
|
$$key = array($key => $value);
|
|
|
|
array_push($conditions, $$key);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-29 19:54:06 +08:00
|
|
|
};
|
|
|
|
|
2013-05-16 05:46:11 +08:00
|
|
|
$this->paginate = array(
|
2013-07-19 19:30:13 +08:00
|
|
|
'fields' => array('Event.Name', 'Event.Length', 'Event.MonitorId', 'Event.Id', 'Monitor.Name', 'Event.MaxScore', 'Event.Width', 'Event.Height', 'Event.StartTime', 'Event.TotScore', 'Event.AvgScore', 'Event.Cause', 'Event.AlarmFrames', 'TIMESTAMPDIFF (SECOND, Event.StartTime, Event.EndTime) AS Duration' ),
|
|
|
|
'limit' => Configure::read('ZM_WEB_EVENTS_PER_PAGE'),
|
2013-05-29 19:44:30 +08:00
|
|
|
'order' => array( 'Event.Id' => 'asc'),
|
|
|
|
'conditions' => $conditions
|
2013-05-16 05:46:11 +08:00
|
|
|
);
|
2013-05-01 19:02:12 +08:00
|
|
|
$data = $this->paginate('Event');
|
|
|
|
$this->set('events', $data);
|
|
|
|
|
2013-05-16 05:50:46 +08:00
|
|
|
$this->set('monitors', $this->Monitor->find('all', array('fields' => array('Monitor.Name') )));
|
|
|
|
|
2013-05-31 10:54:51 +08:00
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$thumbData[$key] = $this->Frame->createListThumbnail($value['Event']);
|
|
|
|
$this->set('thumbData', $thumbData);
|
|
|
|
}
|
2013-05-16 05:51:53 +08:00
|
|
|
}
|
2013-05-16 05:50:46 +08:00
|
|
|
|
2013-05-01 19:02:12 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|