mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Issue #11 - Manage lists outages in separate tables.
This commit is contained in:
4
auth.php
4
auth.php
@@ -43,8 +43,8 @@ class auth_plugin_outage extends auth_plugin_base
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username Not unsed in this plugin.
|
||||
* @param string $password Not unsed in this plugin.
|
||||
* @param string $username Not used in this plugin.
|
||||
* @param string $password Not used in this plugin.
|
||||
* @return bool False
|
||||
* @SuppressWarnings("unused")
|
||||
*/
|
||||
|
||||
@@ -51,27 +51,46 @@ class manage extends \flexible_table {
|
||||
$this->setup();
|
||||
}
|
||||
|
||||
public function set_data(array $outages) {
|
||||
public function set_data(array $outages, $editdelete) {
|
||||
global $OUTPUT;
|
||||
if (!is_bool($editdelete)) {
|
||||
throw new \InvalidArgumentException('$editdelete must be a bool.');
|
||||
}
|
||||
|
||||
foreach ($outages as $outage) {
|
||||
$buttons = \html_writer::link(
|
||||
new \moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
|
||||
\html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/edit'),
|
||||
'alt' => get_string('edit'),
|
||||
'class' => 'iconsmall'
|
||||
]),
|
||||
['title' => get_string('edit')]
|
||||
)
|
||||
. \html_writer::link(
|
||||
new \moodle_url('/auth/outage/delete.php', ['id' => $outage->id]),
|
||||
\html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/delete'),
|
||||
'alt' => get_string('delete'),
|
||||
'class' => 'iconsmall'
|
||||
]),
|
||||
['title' => get_string('delete')]
|
||||
);
|
||||
new \moodle_url('/auth/outage/info.php', ['id' => $outage->id]),
|
||||
\html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/preview'),
|
||||
'alt' => get_string('view'),
|
||||
'class' => 'iconsmall',
|
||||
|
||||
]),
|
||||
[
|
||||
'title' => get_string('view'),
|
||||
'target' => '_blank',
|
||||
]
|
||||
);
|
||||
if ($editdelete) {
|
||||
$buttons .= \html_writer::link(
|
||||
new \moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
|
||||
\html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/edit'),
|
||||
'alt' => get_string('edit'),
|
||||
'class' => 'iconsmall'
|
||||
]),
|
||||
['title' => get_string('edit')]
|
||||
)
|
||||
. \html_writer::link(
|
||||
new \moodle_url('/auth/outage/delete.php', ['id' => $outage->id]),
|
||||
\html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/delete'),
|
||||
'alt' => get_string('delete'),
|
||||
'class' => 'iconsmall'
|
||||
]),
|
||||
['title' => get_string('delete')]
|
||||
);
|
||||
}
|
||||
|
||||
$this->add_data([
|
||||
userdate($outage->starttime, get_string('tablerowstarts', 'auth_outage')),
|
||||
|
||||
7
info.php
7
info.php
@@ -28,14 +28,15 @@ use auth_outage\outagelib;
|
||||
|
||||
require_once('../../config.php');
|
||||
|
||||
$outage = outagedb::get_active();
|
||||
$id = optional_param('id', null, PARAM_INT);
|
||||
$outage = is_null($id) ? outagedb::get_active() : outagedb::get_by_id($id);
|
||||
if (is_null($outage)) {
|
||||
redirect(new moodle_url('/'));
|
||||
}
|
||||
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_title("Outage Warning");
|
||||
$PAGE->set_heading("Outage Warning");
|
||||
$PAGE->set_title($outage->get_title());
|
||||
$PAGE->set_heading($outage->get_title());
|
||||
$PAGE->set_url(new \moodle_url('/auth/outage/info.php'));
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
@@ -45,13 +45,16 @@ $string['menudefaults'] = 'Default Settings';
|
||||
$string['menumanage'] = 'Manage';
|
||||
$string['messageoutageongoing'] = 'Our system will be under maintenance until {$a->stop}.';
|
||||
$string['messageoutagewarning'] = 'Shutting down in {{countdown}} ...';
|
||||
$string['notfound'] = 'No outages found.';
|
||||
$string['outageedit'] = 'Edit Outage';
|
||||
$string['outagecreate'] = 'Create Outage';
|
||||
$string['outagedelete'] = 'Delete Outage';
|
||||
$string['outagedeletewarning'] = 'You are about to permanently delete the outage below. This cannot be undone.';
|
||||
$string['outageduration'] = 'Outage Duration';
|
||||
$string['outagedurationerrorinvalid'] = 'Outage duration must be positive.';
|
||||
$string['outageslist'] = 'Outages List';
|
||||
$string['outageslistactive'] = 'Active Outages';
|
||||
$string['outageslistfuture'] = 'Future Outages';
|
||||
$string['outageslistpast'] = 'Past Outages';
|
||||
$string['pluginname'] = 'Outage manager';
|
||||
$string['readmore'] = 'Read More';
|
||||
$string['starttime'] = 'Start date and time';
|
||||
|
||||
@@ -33,6 +33,6 @@ $renderer = outagelib::pagesetup();
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$renderer->renderoutagelist(outagedb::get_all());
|
||||
$renderer->renderoutagelist(outagedb::get_all_active(), outagedb::get_all_future(), outagedb::get_all_past());
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
46
renderer.php
46
renderer.php
@@ -47,27 +47,47 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
* Outputs the HTML data listing all given outages.
|
||||
* @param array $outages Outages to list.
|
||||
*/
|
||||
public function renderoutagelist(array $outages) {
|
||||
public function renderoutagelist(array $active, array $future, array $past) {
|
||||
global $OUTPUT;
|
||||
|
||||
echo $this->rendersubtitle('outageslist');
|
||||
if (!empty($active)) {
|
||||
echo $this->rendersubtitle('outageslistactive');
|
||||
$table = new \auth_outage\tables\manage();
|
||||
$table->set_data($active, true);
|
||||
$table->finish_output();
|
||||
}
|
||||
|
||||
// Generate list of outages.
|
||||
$table = new \auth_outage\tables\manage();
|
||||
$table->set_data($outages);
|
||||
$table->finish_output(); // It will output HTML.
|
||||
echo $this->rendersubtitle('outageslistfuture');
|
||||
if (empty($future)) {
|
||||
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
|
||||
} else {
|
||||
$table = new \auth_outage\tables\manage();
|
||||
$table->set_data($future, true);
|
||||
$table->finish_output();
|
||||
}
|
||||
|
||||
echo $this->rendersubtitle('outageslistpast');
|
||||
if (empty($past)) {
|
||||
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
|
||||
} else {
|
||||
$table = new \auth_outage\tables\manage();
|
||||
$table->set_data($past, false);
|
||||
$table->finish_output();
|
||||
}
|
||||
|
||||
// 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']);
|
||||
echo html_writer::tag('p',
|
||||
html_writer::link(
|
||||
$url,
|
||||
$img . ' ' . get_string('outagecreate', 'auth_outage'),
|
||||
['title' => get_string('delete')]
|
||||
)
|
||||
);
|
||||
echo
|
||||
html_writer::empty_tag('hr')
|
||||
. html_writer::tag('p',
|
||||
html_writer::link(
|
||||
$url,
|
||||
$img . ' ' . get_string('outagecreate', 'auth_outage'),
|
||||
['title' => get_string('delete')]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function renderoutage(outage $outage, $buttons) {
|
||||
|
||||
Reference in New Issue
Block a user