Add count and near/past deadline retrieval to Incident

This commit is contained in:
2011-12-23 01:34:31 +00:00
parent c4eb37d1c0
commit 7a0c2defe4

View File

@@ -43,6 +43,19 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject {
return static::allFor('site', $site->id, 'incident_opentimes', '`start_time` < :end AND `ctime` > :start', $params); return static::allFor('site', $site->id, 'incident_opentimes', '`start_time` < :end AND `ctime` > :start', $params);
} }
public static function allNearDeadline() {
return static::all('incident_open', "estimated_end_time>=:threshold AND estimated_end_time>=:now", array(
array('name' => 'threshold', 'value' => time() - StatusBoard_DateTime::HOUR, 'type' => PDO::PARAM_INT),
array('name' => 'now', 'value' => time(), 'type' => PDO::PARAM_INT),
));
}
public static function allPastDeadline() {
return static::all('incident_open', "estimated_end_time<=:threshold", array(
array('name' => 'threshold', 'value' => time(), 'type' => PDO::PARAM_INT),
));
}
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();
@@ -157,6 +170,26 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject {
return $new_status; return $new_status;
} }
public static function counts() {
$database = StatusBoard_Main::instance()->database();
$rows = $database->selectList('SELECT `status`, COUNT(*) AS `incident_count` FROM `incidentstatus_current` GROUP BY `status`');
$counts = array();
foreach (StatusBoard_Status::available() as $status) {
$counts[$status] = 0;
}
foreach ($rows as $row) {
$counts[$row['status']] = $row['incident_count'];
}
return $counts;
}
public static function compareEstimatedEndTimes(StatusBoard_Incident $first, StatusBoard_Incident $second) {
return $first->estimated_end_time < $second->estimated_end_time;
}
} }
?> ?>