mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Issue #26 - Added the option to preview how a warning bar will look before and during an outage.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user