Add caching to StatusBoard_Incident::currentStatus()
Also renamed from status to currentStatus to better describe function.
This commit is contained in:
@@ -10,6 +10,8 @@ class StatusBoard_Incident {
|
|||||||
protected $estimated_end_time;
|
protected $estimated_end_time;
|
||||||
protected $actual_end_time;
|
protected $actual_end_time;
|
||||||
|
|
||||||
|
protected $current_status;
|
||||||
|
|
||||||
protected function __construct($id, $site, $reference, $description, $start_time, $estimated_end_time, $actual_end_time) {
|
protected function __construct($id, $site, $reference, $description, $start_time, $estimated_end_time, $actual_end_time) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->site = $site;
|
$this->site = $site;
|
||||||
@@ -75,14 +77,40 @@ class StatusBoard_Incident {
|
|||||||
return $incidents;
|
return $incidents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function status() {
|
public function currentStatus($ignore_cache = false) {
|
||||||
|
if ($this->current_status === null || $ignore_cache) {
|
||||||
$database = StatusBoard_Main::instance()->database();
|
$database = StatusBoard_Main::instance()->database();
|
||||||
$row = $database->selectOne('SELECT `status` FROM `incidentstatus_current` WHERE `incident`=:incident', array(
|
$row = $database->selectOne('SELECT `status` FROM `incidentstatus_current` WHERE `incident`=:incident', array(
|
||||||
array('name' => 'incident', 'value' => $this->id(), 'type' => PDO::PARAM_INT),
|
array('name' => 'incident', 'value' => $this->id(), 'type' => PDO::PARAM_INT),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $row['status'];
|
$this->current_status = $row['status'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->current_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the status of the most severe incident in the given set
|
||||||
|
*
|
||||||
|
* @param array(StatusBoard_Incident) $incidents
|
||||||
|
*/
|
||||||
|
public static function highestSeverityStatus(array $incidents) {
|
||||||
|
if ( ! $incidents) {
|
||||||
|
return StatusBoard_Status::STATUS_Resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for the highest severity incident.
|
||||||
|
$status = StatusBoard_Status::STATUS_Maintenance;
|
||||||
|
foreach ($incidents as $incident) {
|
||||||
|
$incident_status = $incident->currentStatus();
|
||||||
|
if (StatusBoard_Status::isMoreSevere($status, $incident_status)) {
|
||||||
|
$status = $incident_status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function create() {
|
protected function create() {
|
||||||
|
|||||||
Reference in New Issue
Block a user