mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Issue #38 - Ensuring we always have default values for plugin config.
This commit is contained in:
@@ -88,4 +88,20 @@ class outagelib {
|
||||
$CFG->additionalhtmltopofbody = self::get_renderer()->renderoutagebar($active, $time)
|
||||
. $CFG->additionalhtmltopofbody;
|
||||
}
|
||||
|
||||
public static function get_config() {
|
||||
return (object)array_merge(self::get_config_defaults(), (array)get_config('auth_outage'));
|
||||
}
|
||||
|
||||
public static function get_config_defaults() {
|
||||
global $CFG;
|
||||
|
||||
return [
|
||||
'default_duration' => 60,
|
||||
'warning_duration' => 60,
|
||||
'warning_title' => get_string('defaultwarningtitlevalue', 'auth_outage'),
|
||||
'warning_description' => get_string('defaultwarningdescriptionvalue', 'auth_outage'),
|
||||
'css' => file_get_contents($CFG->dirroot . '/auth/outage/views/warningbar.css'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,14 @@
|
||||
|
||||
use auth_outage\cli\cliexception;
|
||||
use auth_outage\cli\create;
|
||||
use auth_outage\outagelib;
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require('../../config.php');
|
||||
|
||||
$cli = new create();
|
||||
|
||||
$config = get_config('auth_outage');
|
||||
$config = outagelib::get_config();
|
||||
$cli->set_defaults([
|
||||
'help' => false,
|
||||
'warn' => (int)($config->warning_duration),
|
||||
|
||||
2
new.php
2
new.php
@@ -41,7 +41,7 @@ if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_' . $id);
|
||||
}
|
||||
|
||||
$config = get_config('auth_outage');
|
||||
$config = outagelib::get_config();
|
||||
$defaults = new outage([
|
||||
'starttime' => time(),
|
||||
'stoptime' => time() + ($config->default_duration * 60),
|
||||
|
||||
69
settings.php
69
settings.php
@@ -22,42 +22,49 @@
|
||||
* @copyright Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
use auth_outage\outagelib;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
if ($hassiteconfig && is_enabled_auth('outage')) {
|
||||
$defaults = outagelib::get_config_defaults();
|
||||
// Configure default settings page.
|
||||
$settings->visiblename = get_string('menudefaults', 'auth_outage');
|
||||
$settings->add(
|
||||
new admin_setting_configtext('auth_outage/default_duration',
|
||||
get_string('defaultoutageduration', 'auth_outage'),
|
||||
get_string('defaultoutagedurationdescription', 'auth_outage'),
|
||||
60, PARAM_INT));
|
||||
$settings->add(
|
||||
new admin_setting_configtext('auth_outage/warning_duration',
|
||||
get_string('defaultwarningduration', 'auth_outage'),
|
||||
get_string('defaultwarningdurationdescription', 'auth_outage'),
|
||||
60, PARAM_INT));
|
||||
$settings->add(
|
||||
new admin_setting_configtext('auth_outage/warning_title',
|
||||
get_string('defaultwarningtitle', 'auth_outage'),
|
||||
get_string('defaultwarningtitledescription', 'auth_outage'),
|
||||
get_string('defaultwarningtitlevalue', 'auth_outage'),
|
||||
PARAM_TEXT)
|
||||
);
|
||||
$settings->add(
|
||||
new admin_setting_configtextarea('auth_outage/warning_description',
|
||||
get_string('defaultwarningdescription', 'auth_outage'),
|
||||
get_string('defaultwarningdescriptiondescription', 'auth_outage'),
|
||||
get_string('defaultwarningdescriptionvalue', '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/views/warningbar.css'),
|
||||
PARAM_TEXT)
|
||||
);
|
||||
$settings->add(new admin_setting_configtext(
|
||||
'auth_outage/default_duration',
|
||||
get_string('defaultoutageduration', 'auth_outage'),
|
||||
get_string('defaultoutagedurationdescription', 'auth_outage'),
|
||||
$defaults['default_duration'],
|
||||
PARAM_INT
|
||||
));
|
||||
$settings->add(new admin_setting_configtext(
|
||||
'auth_outage/warning_duration',
|
||||
get_string('defaultwarningduration', 'auth_outage'),
|
||||
get_string('defaultwarningdurationdescription', 'auth_outage'),
|
||||
$defaults['warning_duration'],
|
||||
PARAM_INT
|
||||
));
|
||||
$settings->add(new admin_setting_configtext(
|
||||
'auth_outage/warning_title',
|
||||
get_string('defaultwarningtitle', 'auth_outage'),
|
||||
get_string('defaultwarningtitledescription', 'auth_outage'),
|
||||
$defaults['warning_title'],
|
||||
PARAM_TEXT
|
||||
));
|
||||
$settings->add(new admin_setting_configtextarea(
|
||||
'auth_outage/warning_description',
|
||||
get_string('defaultwarningdescription', 'auth_outage'),
|
||||
get_string('defaultwarningdescriptiondescription', 'auth_outage'),
|
||||
$defaults['warning_description'],
|
||||
PARAM_TEXT
|
||||
));
|
||||
$settings->add(new admin_setting_configtextarea(
|
||||
'auth_outage/css',
|
||||
get_string('defaultlayoutcss', 'auth_outage'),
|
||||
get_string('defaultlayoutcssdescription', 'auth_outage'),
|
||||
$defaults['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.
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\outagelib;
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
}
|
||||
@@ -31,7 +33,7 @@ global $OUTPUT;
|
||||
|
||||
$infolink = new moodle_url('/auth/outage/info.php', ['id' => $outage->id]);
|
||||
|
||||
echo html_writer::tag('style', get_config('auth_outage', 'css'));
|
||||
echo html_writer::tag('style', outagelib::get_config()->css);
|
||||
?>
|
||||
|
||||
<div id="auth_outage_warningbar_box">
|
||||
|
||||
Reference in New Issue
Block a user