WIP Issue #9 - Fixed message on all pages, need to work on UI and DB.

This commit is contained in:
Daniel Thee Roperto
2016-09-05 19:50:26 +10:00
parent 98de8a6c69
commit aca6a0122e
6 changed files with 69 additions and 5 deletions

View File

@@ -49,4 +49,11 @@ class auth_plugin_outage extends auth_plugin_base
public function user_login($username, $password) {
return false;
}
/**
* Login page hook.
*/
function loginpage_hook() {
\auth_outage\outagelib::initialize();
}
}

View File

@@ -28,8 +28,9 @@ if (!defined('MOODLE_INTERNAL')) {
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class outagelib
{
class outagelib {
private static $initialized = false;
/**
* Initializes admin pages for outage.
*
@@ -39,9 +40,40 @@ class outagelib
global $PAGE;
admin_externalpage_setup('auth_outage_manage');
$PAGE->set_url(new \moodle_url('/auth/outage/list.php'));
return self::get_renderer();
}
/**
* Returns the outage renderer.
* @return \renderer_base
*/
public static function get_renderer() {
global $PAGE;
return $PAGE->get_renderer('auth_outage');
}
public static function initialize() {
global $CFG;
// Many hooks can call it, execute only once.
if (self::$initialized) {
return;
}
self::$initialized = true;
// Stop if no current outage is found.
$outage = new \auth_outage\models\outage([
'starttime' => time() - 60, // 1 minute ago.
'stoptime' => time() + 60 * 60, // In 1 hour.
'warningduration' => 1, // Does not matter.
'title' => 'Fixed Outage',
'description' => '<p>This is an <b>OUTAGE</b>.</p>'
]);
// FIXME Get from DB instead.
if (!$outage) return;
$CFG->additionalhtmltopofbody .= self::get_renderer()->renderbar($outage);
}
/**
* Loads data from an object or array into another object. It ensures no new fields are created in the $obj.
*

13
lib.php
View File

@@ -23,3 +23,16 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
function auth_outage_extend_navigation_user() {
\auth_outage\outagelib::initialize();
}
function auth_outage_extend_navigation($data) {
// Never called?
\auth_outage\outagelib::initialize();
}
function auth_outage_extend_navigation_frontpage() {
\auth_outage\outagelib::initialize();
}

View File

@@ -29,8 +29,7 @@ if (!defined('MOODLE_INTERNAL')) {
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_renderer extends plugin_renderer_base
{
class auth_outage_renderer extends plugin_renderer_base {
public function rendersubtitle($subtitlekey) {
if (!is_string($subtitlekey)) {
throw new \InvalidArgumentException('$subtitle is not a string.');
@@ -124,4 +123,15 @@ class auth_outage_renderer extends plugin_renderer_base
)
);
}
public function renderbar($outage) {
global $PAGE;
$PAGE->requires->css(new moodle_url('/auth/outage/res/outage.css'));
return html_writer::div(
html_writer::tag('b', $outage->title),
'auth_outage_warningbar'
);
}
}

3
res/outage.css Normal file
View File

@@ -0,0 +1,3 @@
.auth_outage_warningbar {
background-color: red;
}

View File

@@ -25,7 +25,6 @@
defined('MOODLE_INTERNAL') || die;
// FIXME If plugin not installed, it is still generating the category Outage under Auth Plugins.
if ($hassiteconfig) {
// Configure default settings page.
$settings->visiblename = get_string('menudefaults', 'auth_outage');