Issue #26 - Added the option to preview how a warning bar will look before and during an outage.

This commit is contained in:
Daniel Thee Roperto
2016-09-13 16:00:44 +10:00
parent 9cc954961a
commit 92681c7ec4
8 changed files with 176 additions and 32 deletions

View File

@@ -97,6 +97,25 @@ class outage {
throw new \InvalidArgumentException('$data must be null (default), an array or an object.');
}
/**
* Checks if the outage is active (in warning period or ongoing).
* @param int|null $time Null to check if the outage is active now or another time to use as reference.
* @return bool True if outage is ongoing or during the warning period.
*/
public function is_active($time = null) {
if ($time === null) {
$time = time();
}
if (!is_int($time) || ($time <= 0)) {
throw new \InvalidArgumentException('$time must be an positive int.');
}
if (is_null($this->warntime) || is_null($this->stoptime)) {
return false;
}
return (($this->warntime <= $time) && ($time < $this->stoptime));
}
/**
* Checks if the outage is happening.
* @param int|null $time Null to check if the outage is happening now or another time to use as reference.

View File

@@ -68,17 +68,17 @@ class outagelib {
$previewid = optional_param('auth_outage_preview', null, PARAM_INT);
$time = time();
if (is_null($previewid)) {
if (($active = outagedb::get_active()) == null) {
if (!$active = outagedb::get_active()) {
return;
}
} else {
if (($active = outagedb::get_by_id($previewid)) == null) {
if (!$active = outagedb::get_by_id($previewid)) {
return;
}
$delta = optional_param('auth_outage_delta', null, PARAM_FLOAT);
if ($delta) {
// Delta is float in minutes, allowing to check the redirect in a few seconds.
$time = $active->starttime + (int)($delta * 60);
// Delta is in seconds, setting the time our warning bar will consider relative to the outage start time.
$time = $active->starttime + optional_param('auth_outage_delta', 0, PARAM_INT);
if (!$active->is_active($time)) {
return;
}
}