mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Issue #11 - Standard manage table implemented, all outages still on the same table.
This commit is contained in:
@@ -129,8 +129,8 @@ class edit extends \moodleform {
|
||||
$this->_form->setDefaults([
|
||||
'id' => $outage->id,
|
||||
'starttime' => $outage->starttime,
|
||||
'outageduration' => $outage->stoptime - $outage->starttime,
|
||||
'warningduration' => $outage->starttime - $outage->warntime,
|
||||
'outageduration' => $outage->get_duration(),
|
||||
'warningduration' => $outage->get_warning_duration(),
|
||||
'title' => $outage->title,
|
||||
'description' => ['text' => $outage->description, 'format' => '1']
|
||||
]);
|
||||
|
||||
@@ -28,6 +28,29 @@ 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).
|
||||
*/
|
||||
@@ -150,4 +173,36 @@ class outage {
|
||||
$str
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the duration of the outage (start to stop, warning not included).
|
||||
* @return int Duration in seconds.
|
||||
*/
|
||||
public function get_duration() {
|
||||
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.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
79
classes/tables/manage.php
Normal file
79
classes/tables/manage.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_outage\tables;
|
||||
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
|
||||
/**
|
||||
* Manage outages table.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class manage extends \flexible_table {
|
||||
private static $autoid = 0;
|
||||
|
||||
public function __construct($id = null) {
|
||||
global $PAGE;
|
||||
|
||||
$id = (is_null($id) ? self::$autoid++ : $id);
|
||||
parent::__construct('auth_outage_manage_' . $id);
|
||||
|
||||
$this->define_columns(['starttime', 'stopsafter', 'warnbefore', 'title', '']);
|
||||
|
||||
$this->define_headers([
|
||||
get_string('tableheaderstarttime', 'auth_outage'),
|
||||
get_string('tableheaderstopsafter', 'auth_outage'),
|
||||
get_string('tableheaderwarnbefore', 'auth_outage'),
|
||||
get_string('tableheadertitle', 'auth_outage'),
|
||||
'',
|
||||
]
|
||||
);
|
||||
|
||||
$this->define_baseurl($PAGE->url);
|
||||
$this->set_attribute('class', 'generaltable admintable');
|
||||
$this->setup();
|
||||
}
|
||||
|
||||
public function set_data(array $outages) {
|
||||
global $OUTPUT;
|
||||
foreach ($outages as $outage) {
|
||||
$buttons = '';
|
||||
|
||||
$url = new \moodle_url('/auth/outage/edit.php', ['id' => $outage->id]);
|
||||
$html = \html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall'));
|
||||
$buttons .= \html_writer::link($url, $html, array('title' => get_string('edit')));
|
||||
|
||||
$url = new \moodle_url('/auth/outage/delete.php', ['id' => $outage->id]);
|
||||
$html = \html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall'));
|
||||
$buttons .= \html_writer::link($url, $html, array('title' => get_string('delete')));
|
||||
|
||||
// Table columns 'name', 'action', 'role', 'parent', 'continue', 'priority', 'data'.
|
||||
$values = [
|
||||
userdate($outage->starttime, get_string('tablerowstarts', 'auth_outage')),
|
||||
$outage->get_duration_string(),
|
||||
$outage->get_warning_duration_string(),
|
||||
$outage->get_title(),
|
||||
$buttons,
|
||||
];
|
||||
|
||||
$this->add_data($values);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user