mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Issue #11 - Small fixed as suggested by Brendan.
This commit is contained in:
@@ -45,17 +45,17 @@ class edit extends \moodleform {
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$mform->addElement('duration', 'warningduration', get_string('warningduration', 'auth_outage'));
|
||||
|
||||
$mform->addElement('date_time_selector', 'starttime', get_string('starttime', 'auth_outage'));
|
||||
|
||||
$mform->addElement('duration', 'outageduration', get_string('outageduration', 'auth_outage'));
|
||||
|
||||
$mform->addElement('duration', 'warningduration', get_string('warningduration', 'auth_outage'));
|
||||
|
||||
$mform->addElement(
|
||||
'text',
|
||||
'title',
|
||||
get_string('title', 'auth_outage'),
|
||||
'maxlength="' . self::TITLE_MAX_CHARS . '"'
|
||||
'maxlength="' . self::TITLE_MAX_CHARS . '" size="60"'
|
||||
);
|
||||
$mform->setType('title', PARAM_TEXT);
|
||||
|
||||
|
||||
@@ -28,29 +28,6 @@ namespace auth_outage\models;
|
||||
use auth_outage\outagelib;
|
||||
|
||||
class outage {
|
||||
private static function get_seconds_duration_string($duration) {
|
||||
if (!is_int($duration)) {
|
||||
throw new \InvalidArgumentException('$seconds must be an int.');
|
||||
}
|
||||
|
||||
if (($duration < 60) || ($duration % 60 != 0)) {
|
||||
return $duration . ' ' . get_string('durationseconds', 'auth_outage');
|
||||
}
|
||||
|
||||
$duration /= 60;
|
||||
if (($duration < 60) || ($duration % 60 != 0)) {
|
||||
return $duration . ' ' . get_string('durationminutes', 'auth_outage');
|
||||
}
|
||||
|
||||
$duration /= 60;
|
||||
if (($duration < 60) || ($duration % 24 != 0)) {
|
||||
return $duration . ' ' . get_string('durationhours', 'auth_outage');
|
||||
}
|
||||
|
||||
$duration /= 24;
|
||||
return $duration . ' ' . get_string('durationdays', 'auth_outage');
|
||||
}
|
||||
|
||||
/**
|
||||
* @var int Outage ID (auto generated by the DB).
|
||||
*/
|
||||
@@ -182,14 +159,6 @@ class outage {
|
||||
return $this->stoptime - $this->starttime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the duration of the outage (start to stop, warning not included).
|
||||
* @return string The duration as text, for example '6 hour(s)'.
|
||||
*/
|
||||
public function get_duration_string() {
|
||||
return self::get_seconds_duration_string($this->get_duration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the warning duration from the outage (from warning time to start time).
|
||||
* @return int Warning duration in seconds.
|
||||
@@ -197,12 +166,4 @@ class outage {
|
||||
public function get_warning_duration() {
|
||||
return $this->starttime - $this->warntime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the warning duration from the outage (from warning time to start time).
|
||||
* @return string The warning duration as text, for example '6 hour(s)'.
|
||||
*/
|
||||
public function get_warning_duration_string() {
|
||||
return self::get_seconds_duration_string($this->get_warning_duration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,37 +168,6 @@ class outagedb {
|
||||
return (count($data) == 0) ? null : new \auth_outage\models\outage(array_shift($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static function get_all_active($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 <= :datetime1 AND stoptime >= :datetime2)',
|
||||
['datetime1' => $time, 'datetime2' => $time],
|
||||
'starttime ASC, stoptime DESC, title ASC',
|
||||
'*');
|
||||
foreach ($rs as $r) {
|
||||
$outages[] = new outage($r);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
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.
|
||||
@@ -218,7 +187,7 @@ class outagedb {
|
||||
|
||||
$rs = $DB->get_recordset_select(
|
||||
'auth_outage',
|
||||
'warntime > :datetime',
|
||||
'stoptime >= :datetime',
|
||||
['datetime' => $time],
|
||||
'starttime ASC, stoptime DESC, title ASC',
|
||||
'*');
|
||||
@@ -230,7 +199,6 @@ class outagedb {
|
||||
return $outages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets all past outages.
|
||||
* @param int|null $time Timestamp considered to check for outages, null for current date/time.
|
||||
|
||||
@@ -38,11 +38,11 @@ class manage extends \flexible_table {
|
||||
$this->define_columns(['starttime', 'stopsafter', 'warnbefore', 'title', '']);
|
||||
|
||||
$this->define_headers([
|
||||
get_string('tableheaderwarnbefore', 'auth_outage'),
|
||||
get_string('tableheaderstarttime', 'auth_outage'),
|
||||
get_string('tableheaderstopsafter', 'auth_outage'),
|
||||
get_string('tableheaderwarnbefore', 'auth_outage'),
|
||||
get_string('tableheadertitle', 'auth_outage'),
|
||||
'',
|
||||
get_string('actions'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -71,6 +71,7 @@ class manage extends \flexible_table {
|
||||
'target' => '_blank',
|
||||
]
|
||||
);
|
||||
$title = $outage->get_title();
|
||||
if ($editdelete) {
|
||||
$buttons .= \html_writer::link(
|
||||
new \moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
|
||||
@@ -90,13 +91,19 @@ class manage extends \flexible_table {
|
||||
]),
|
||||
['title' => get_string('delete')]
|
||||
);
|
||||
|
||||
$title = \html_writer::link(
|
||||
new \moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
|
||||
$title,
|
||||
['title' => get_string('edit')]
|
||||
);
|
||||
}
|
||||
|
||||
$this->add_data([
|
||||
format_time($outage->get_warning_duration()),
|
||||
userdate($outage->starttime, get_string('tablerowstarts', 'auth_outage')),
|
||||
$outage->get_duration_string(),
|
||||
$outage->get_warning_duration_string(),
|
||||
$outage->get_title(),
|
||||
format_time($outage->get_duration()),
|
||||
$title,
|
||||
$buttons,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user