Issue #10 - Added link to warning bar and info page.

This commit is contained in:
Daniel Thee Roperto
2016-09-08 14:31:51 +10:00
parent efee27af40
commit a4de5d6bf1
7 changed files with 138 additions and 10 deletions

43
classes/forms/gohome.php Normal file
View File

@@ -0,0 +1,43 @@
<?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\forms;
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
require_once($CFG->libdir . '/formslib.php');
/**
* Home form. Shows a button 'Continue' and moves to home page once clicked.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class gohome extends \moodleform {
const TITLE_MAX_CHARS = 100;
/**
* {@inheritDoc}
* @see moodleform::definition()
*/
public function definition() {
$this->add_action_buttons(false, get_string('continue'));
}
}

View File

@@ -39,7 +39,7 @@ class outagelib {
public static function pagesetup() {
global $PAGE;
admin_externalpage_setup('auth_outage_manage');
$PAGE->set_url(new \moodle_url('/auth/outage/list.php'));
$PAGE->set_url(new \moodle_url('/auth/outage/manage.php'));
return self::get_renderer();
}
@@ -68,7 +68,7 @@ class outagelib {
return;
}
$CFG->additionalhtmltopofbody = self::get_renderer()->renderbar($active)
$CFG->additionalhtmltopofbody = self::get_renderer()->renderoutagebar($active)
. $CFG->additionalhtmltopofbody;
}

52
info.php Normal file
View File

@@ -0,0 +1,52 @@
<?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/>.
/**
* List outages
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use auth_outage\outagedb;
use auth_outage\outagelib;
require_once('../../config.php');
$outage = outagedb::get_active();
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_url(new \moodle_url('/auth/outage/info.php'));
$mform = new \auth_outage\forms\gohome();
if ($mform->get_data()) {
redirect(new moodle_url('/'));
}
echo $OUTPUT->header();
echo outagelib::get_renderer()->renderoutagepage($outage);
$mform->display();
echo $OUTPUT->footer();

View File

@@ -24,6 +24,8 @@
*/
$string['auth_outagedescription'] = 'Auxiliary plugin that warns users about a future outage and prevents them from logging in once the outage starts.';
$string['defaultlayoutcss'] = 'Layout CSS';
$string['defaultlayoutcssdescription'] = 'This CSS code will be used to display the Outage Warning Bar.';
$string['defaultwarningmessage'] = 'Default Warning Message';
$string['defaultwarningmessagedescription'] = 'Default warning message for outages. Use [from] and [until] placeholders as required.';
$string['defaultwarningmessagevalue'] = 'There is an scheduled maintenance from [from] to [until] and our system will not be available during that time.';

View File

@@ -125,10 +125,23 @@ class auth_outage_renderer extends plugin_renderer_base {
);
}
public function renderbar($outage) {
global $PAGE;
public function renderoutagepage(outage $outage) {
$start = userdate($outage->starttime, get_string('strftimedatetimeshort'));
$stop = userdate($outage->stoptime, get_string('strftimedatetimeshort'));
$PAGE->requires->css(new moodle_url('/auth/outage/res/outage.css'));
return html_writer::div(
html_writer::tag('p',
html_writer::tag('b', 'From: ')
. $start
. html_writer::tag('b', ' Until: ')
. $stop
)
. html_writer::div($outage->description)
);
}
public function renderoutagebar(outage $outage) {
global $CFG;
$start = userdate($outage->starttime, get_string('strftimedatetimeshort'));
$stop = userdate($outage->stoptime, get_string('strftimedatetimeshort'));
@@ -140,15 +153,21 @@ class auth_outage_renderer extends plugin_renderer_base {
);
return
html_writer::div(
html_writer::tag('style', $CFG->auth_outage_css)
. html_writer::div(
html_writer::div(
html_writer::div($outage->title, 'auth_outage_warningbar_box_title')
. html_writer::div($message, 'auth_outage_warningbar_box_message'),
. html_writer::div(
$message . ' '
. html_writer::tag('small',
'[' . html_writer::link(new moodle_url('/auth/outage/info.php'), 'more') . ']'
),
'auth_outage_warningbar_box_message'
),
'auth_outage_warningbar_box'
),
'auth_outage_warningbar'
)
.
html_writer::div('&nbsp;', 'auth_outage_warningbar_spacer');
. html_writer::div('&nbsp;', 'auth_outage_warningbar_spacer');
}
}

View File

@@ -1,3 +1,8 @@
/*
This file is used as default value for the 'auth_outage_css' settings.
If you need to make chances here, remember to update your settings inside Moodle.
*/
.auth_outage_warningbar {
background-color: white;
box-sizing: content-box;
@@ -33,4 +38,4 @@
.auth_outage_warningbar_spacer {
height: 80px;
}
}

View File

@@ -39,6 +39,13 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
get_string('defaultwarningmessagevalue', 'auth_outage'),
PARAM_TEXT)
);
$settings->add(
new admin_setting_configtextarea('auth_outage_css',
get_string('defaultlayoutcss', 'auth_outage'),
get_string('defaultlayoutcssdescription', 'auth_outage'),
file_get_contents($CFG->dirroot.'/auth/outage/res/default.css'),
PARAM_TEXT)
);
// Create category for Outage.
$ADMIN->add('authsettings', new admin_category('auth_outage', get_string('pluginname', 'auth_outage')));
// Add settings page toconfigure defaults.