2013-05-02 06:41:59 +08:00
|
|
|
<?php
|
|
|
|
class Monitor extends AppModel {
|
|
|
|
public $useTable = 'Monitors';
|
2013-05-02 20:55:59 +08:00
|
|
|
public $hasMany = array(
|
|
|
|
'Event' => array(
|
|
|
|
'className' => 'Event',
|
2013-05-05 10:41:27 +08:00
|
|
|
'foreignKey' => 'MonitorId',
|
|
|
|
'fields' => 'Event.Id'
|
2013-05-02 21:01:27 +08:00
|
|
|
),
|
|
|
|
'Zone' => array(
|
|
|
|
'className' => 'Zone',
|
2013-05-05 10:41:27 +08:00
|
|
|
'foreignKey' => 'MonitorId',
|
|
|
|
'fields' => 'Zone.Id'
|
2013-05-02 20:55:59 +08:00
|
|
|
)
|
|
|
|
);
|
2013-05-05 07:42:37 +08:00
|
|
|
|
|
|
|
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'));
|
|
|
|
}
|
2013-05-05 10:45:59 +08:00
|
|
|
|
|
|
|
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'));
|
|
|
|
}
|
2013-05-02 06:41:59 +08:00
|
|
|
}
|
|
|
|
?>
|