From 0c8c8a1cb497cade799de676bdbd81c8bb2bea99 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Tue, 20 Dec 2011 19:15:42 +0000 Subject: [PATCH] Add support for retriving incidents within set time period --- build/schema/mysql.sql | 34 +++++++++++++++++++++-- source/lib/StatusBoard/Incident.class.php | 9 ++++++ source/lib/StatusBoard/Site.class.php | 4 +++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/build/schema/mysql.sql b/build/schema/mysql.sql index d62eb72..c1e538b 100644 --- a/build/schema/mysql.sql +++ b/build/schema/mysql.sql @@ -159,13 +159,14 @@ CREATE VIEW `incidentstatus_current` AS ( ); -- --- Table structure for view `incidentstatus_open` +-- Table structure for view `incident_open` -- DROP VIEW IF EXISTS `incident_open`; CREATE VIEW `incident_open` AS ( SELECT - `i`.* + `i`.*, + `isc`.`ctime` FROM `incident` AS `i` JOIN `incidentstatus_current` AS `isc` @@ -174,6 +175,35 @@ CREATE VIEW `incident_open` AS ( `isc`.`status` IN (1,2,3,4) ); +-- +-- Table structure for view `incident_closedtime` +-- + +DROP VIEW IF EXISTS `incident_closedtime`; +CREATE VIEW `incident_closedtime` AS ( + SELECT + `incident` AS `incident`, + `ctime` AS `ctime` + FROM + `incidentstatus` + WHERE + `status` = 0 +); + +-- +-- Table structure for view `incident_opentimes` +-- + +DROP VIEW IF EXISTS `incident_opentimes`; +CREATE VIEW `incident_opentimes` AS ( + SELECT + `i`.*, + IFNULL(`t`.`ctime`, 0xffffffff+0) AS `ctime` + FROM + `incident` as `i` + LEFT JOIN `incident_closedtime` AS `t` ON `i`.`id`=`t`.`incident` +); + -- -- Table structure for table `user` -- diff --git a/source/lib/StatusBoard/Incident.class.php b/source/lib/StatusBoard/Incident.class.php index fceb849..dafcb40 100644 --- a/source/lib/StatusBoard/Incident.class.php +++ b/source/lib/StatusBoard/Incident.class.php @@ -19,6 +19,15 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject { return static::all_for('site', $site->id, 'incident_open'); } + public static function open_for_site_during(StatusBoard_Site $site, $start, $end) { + $params = array( + array('name' => 'start', 'value' => $start, 'type' => PDO::PARAM_INT), + array('name' => 'end', 'value' => $end, 'type' => PDO::PARAM_INT), + ); + + return static::all_for('site', $site->id, 'incident_opentimes', '`start_time` < :end AND `ctime` > :start', $params); + } + public function currentStatus($ignore_cache = false) { if ($this->current_status === null || $ignore_cache) { $database = StatusBoard_Main::instance()->database(); diff --git a/source/lib/StatusBoard/Site.class.php b/source/lib/StatusBoard/Site.class.php index 7688ccc..2e907b4 100644 --- a/source/lib/StatusBoard/Site.class.php +++ b/source/lib/StatusBoard/Site.class.php @@ -24,6 +24,10 @@ class StatusBoard_Site extends StatusBoard_DatabaseObject { return $this->incidents_open; } + public function openIncidentsDuring($start, $end) { + return StatusBoard_Incident::open_for_site_during($this, $start, $end); + } + public function status() { return StatusBoard_Incident::highestSeverityStatus($this->openIncidents()); }