mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,10 @@ $string['defaultwarningdescription'] = 'Description';
|
||||
$string['defaultwarningdescriptiondescription'] = 'Default warning message for outages. Use {{start}} and {{stop}} placeholders as required.';
|
||||
$string['defaultwarningdescriptionvalue'] = 'There is an scheduled maintenance from {{start}} to {{stop}} and our system will not be available during that time.';
|
||||
$string['description'] = 'Public Description';
|
||||
$string['durationseconds'] = 'second(s)';
|
||||
$string['durationminutes'] = 'minutes(s)';
|
||||
$string['durationhours'] = 'hour(s)';
|
||||
$string['durationdays'] = 'day(s)';
|
||||
$string['menudefaults'] = 'Default Settings';
|
||||
$string['menumanage'] = 'Manage';
|
||||
$string['messageoutageongoing'] = 'Our system will be under maintenance until {$a->stop}.';
|
||||
@@ -51,6 +55,11 @@ $string['outageslist'] = 'Outages List';
|
||||
$string['pluginname'] = 'Outage manager';
|
||||
$string['readmore'] = 'Read More';
|
||||
$string['starttime'] = 'Start date and time';
|
||||
$string['tableheaderstarttime'] = 'Starts on';
|
||||
$string['tableheaderstopsafter'] = 'Stops after';
|
||||
$string['tableheaderwarnbefore'] = 'Warns before';
|
||||
$string['tableheadertitle'] = 'Title';
|
||||
$string['tablerowstarts'] = '%d/%m/%Y %H:%M';
|
||||
$string['textplaceholdershint'] = 'You can use {{start}} and {{stop}} as placeholders on the title/description for the actual start/stop time.';
|
||||
$string['titleerrorinvalid'] = 'Title cannot be left blank.';
|
||||
$string['titleerrortoolong'] = 'Title cannot have more than {$a} characters.';
|
||||
|
||||
@@ -33,6 +33,8 @@ $renderer = outagelib::pagesetup();
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
echo $renderer->renderoutagelist(outagedb::get_all());
|
||||
$table = new \auth_outage\tables\manage();
|
||||
$table->set_data(outagedb::get_all());
|
||||
echo $table->finish_output();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
25
renderer.php
25
renderer.php
@@ -43,31 +43,6 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
. $this->renderoutage($outage, false);
|
||||
}
|
||||
|
||||
public function renderoutagelist(array $outages) {
|
||||
global $OUTPUT;
|
||||
|
||||
$html = $this->rendersubtitle('outageslist');
|
||||
|
||||
// Generate list of outages.
|
||||
foreach ($outages as $outage) {
|
||||
$html .= $this->renderoutage($outage, true);
|
||||
}
|
||||
|
||||
// Add 'add' button.
|
||||
$url = new moodle_url('/auth/outage/new.php');
|
||||
$img = html_writer::empty_tag('img',
|
||||
['src' => $OUTPUT->pix_url('t/add'), 'alt' => get_string('create'), 'class' => 'iconsmall']);
|
||||
$html .= html_writer::tag('p',
|
||||
html_writer::link(
|
||||
$url,
|
||||
$img . ' ' . get_string('outagecreate', 'auth_outage'),
|
||||
['title' => get_string('delete')]
|
||||
)
|
||||
);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function renderoutage(outage $outage, $buttons) {
|
||||
global $OUTPUT;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user