mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Issue #11 - TDD to get future and past outages (outagedb).
This commit is contained in:
@@ -169,10 +169,7 @@ class outagedb {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all active outages, sorted by importance as:
|
||||
* - Ongoing outages more important than outages in warning period.
|
||||
* - Outages that start earlier are more important.
|
||||
* - Outages that stop later are more important.
|
||||
* Gets all active outages (including in warning period).
|
||||
* @param int|null $time Timestamp considered to check for outages, null for current date/time.
|
||||
* @return array An array of outages or an empty array if no active outage found.
|
||||
*/
|
||||
@@ -201,4 +198,67 @@ class outagedb {
|
||||
|
||||
return $outages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all future outages not in warning period.
|
||||
* @param int|null $time Timestamp considered to check for outages, null for current date/time.
|
||||
* @return array An array of outages or an empty array if no future outage found.
|
||||
*/
|
||||
public static function get_all_future($time = null) {
|
||||
global $DB;
|
||||
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time)) {
|
||||
throw new \InvalidArgumentException('$time must be null or an int.');
|
||||
}
|
||||
|
||||
$outages = [];
|
||||
|
||||
$rs = $DB->get_recordset_select(
|
||||
'auth_outage',
|
||||
'warntime > :datetime',
|
||||
['datetime' => $time],
|
||||
'starttime ASC, stoptime DESC, title ASC',
|
||||
'*');
|
||||
foreach ($rs as $r) {
|
||||
$outages[] = new outage($r);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
return $outages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets all past outages.
|
||||
* @param int|null $time Timestamp considered to check for outages, null for current date/time.
|
||||
* @return array An array of outages or an empty array if no past outage found.
|
||||
*/
|
||||
public static function get_all_past($time = null) {
|
||||
global $DB;
|
||||
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time)) {
|
||||
throw new \InvalidArgumentException('$time must be null or an int.');
|
||||
}
|
||||
|
||||
$outages = [];
|
||||
|
||||
$rs = $DB->get_recordset_select(
|
||||
'auth_outage',
|
||||
'stoptime < :datetime',
|
||||
['datetime' => $time],
|
||||
'stoptime DESC, starttime DESC, title ASC',
|
||||
'*');
|
||||
foreach ($rs as $r) {
|
||||
$outages[] = new outage($r);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
return $outages;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user