Add support for retriving incidents within set time period
This commit is contained in:
@@ -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`;
|
DROP VIEW IF EXISTS `incident_open`;
|
||||||
CREATE VIEW `incident_open` AS (
|
CREATE VIEW `incident_open` AS (
|
||||||
SELECT
|
SELECT
|
||||||
`i`.*
|
`i`.*,
|
||||||
|
`isc`.`ctime`
|
||||||
FROM
|
FROM
|
||||||
`incident` AS `i`
|
`incident` AS `i`
|
||||||
JOIN `incidentstatus_current` AS `isc`
|
JOIN `incidentstatus_current` AS `isc`
|
||||||
@@ -174,6 +175,35 @@ CREATE VIEW `incident_open` AS (
|
|||||||
`isc`.`status` IN (1,2,3,4)
|
`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`
|
-- Table structure for table `user`
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -19,6 +19,15 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject {
|
|||||||
return static::all_for('site', $site->id, 'incident_open');
|
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) {
|
public function currentStatus($ignore_cache = false) {
|
||||||
if ($this->current_status === null || $ignore_cache) {
|
if ($this->current_status === null || $ignore_cache) {
|
||||||
$database = StatusBoard_Main::instance()->database();
|
$database = StatusBoard_Main::instance()->database();
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ class StatusBoard_Site extends StatusBoard_DatabaseObject {
|
|||||||
return $this->incidents_open;
|
return $this->incidents_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function openIncidentsDuring($start, $end) {
|
||||||
|
return StatusBoard_Incident::open_for_site_during($this, $start, $end);
|
||||||
|
}
|
||||||
|
|
||||||
public function status() {
|
public function status() {
|
||||||
return StatusBoard_Incident::highestSeverityStatus($this->openIncidents());
|
return StatusBoard_Incident::highestSeverityStatus($this->openIncidents());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user