diff --git a/auth.php b/auth.php index b8838f9..c43863f 100644 --- a/auth.php +++ b/auth.php @@ -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(); + } } diff --git a/classes/outagelib.php b/classes/outagelib.php index 909ee8b..8f36e08 100644 --- a/classes/outagelib.php +++ b/classes/outagelib.php @@ -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' => '

This is an OUTAGE.

' + ]); + // 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. * diff --git a/lib.php b/lib.php index 56943f8..78ccf77 100644 --- a/lib.php +++ b/lib.php @@ -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(); +} diff --git a/renderer.php b/renderer.php index d6848b1..46e5a7b 100644 --- a/renderer.php +++ b/renderer.php @@ -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' + ); + } } diff --git a/res/outage.css b/res/outage.css new file mode 100644 index 0000000..65ca782 --- /dev/null +++ b/res/outage.css @@ -0,0 +1,3 @@ +.auth_outage_warningbar { + background-color: red; +} \ No newline at end of file diff --git a/settings.php b/settings.php index 1507e1b..fa082c6 100644 --- a/settings.php +++ b/settings.php @@ -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');