mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 16:13:28 +02:00
MDL-16564 Make admin settings work better with the cnfig_plugins table.
Also, take the opportunity to take the quiz-specific stuff out of adminlib.php, to make Petr happy.
This commit is contained in:
parent
0186b1d06c
commit
7fb0303d89
4 changed files with 186 additions and 160 deletions
136
lib/adminlib.php
136
lib/adminlib.php
|
@ -2377,12 +2377,37 @@ class admin_setting {
|
|||
* @param mixed $defaultsetting string or array depending on implementation
|
||||
*/
|
||||
function admin_setting($name, $visiblename, $description, $defaultsetting) {
|
||||
$this->name = $name;
|
||||
$this->parse_setting_name($name);
|
||||
$this->visiblename = $visiblename;
|
||||
$this->description = $description;
|
||||
$this->defaultsetting = $defaultsetting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up $this->name and possibly $this->plugin based on whether $name looks
|
||||
* like 'settingname' or 'plugin/settingname'. Also, do some sanity checking
|
||||
* on the names, that is, output a developer debug warning if the name
|
||||
* contains anything other than [a-zA-Z0-9_]+.
|
||||
*
|
||||
* @param string $name the setting name passed in to the constructor.
|
||||
*/
|
||||
private function parse_setting_name($name) {
|
||||
$bits = explode('/', $name);
|
||||
if (count($bits) > 2) {
|
||||
throw new moodle_exception('invalidadminsettingname', '', '', $name);
|
||||
}
|
||||
$this->name = array_pop($bits);
|
||||
if (!preg_match('/^[a-zA-Z0-9_]+$/', $this->name)) {
|
||||
throw new moodle_exception('invalidadminsettingname', '', '', $name);
|
||||
}
|
||||
if (!empty($bits)) {
|
||||
$this->plugin = array_pop($bits);
|
||||
if (!preg_match('/^[a-zA-Z0-9_]+$/', $this->plugin)) {
|
||||
throw new moodle_exception('invalidadminsettingname', '', '', $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_full_name() {
|
||||
return 's_'.$this->plugin.'_'.$this->name;
|
||||
}
|
||||
|
@ -4188,11 +4213,10 @@ class admin_setting_pickroles extends admin_setting_configmulticheckbox {
|
|||
}
|
||||
|
||||
/**
|
||||
* Text field linked to config_plugins for the quiz, with an advanced checkbox.
|
||||
* Text field with an advanced checkbox, that controls a additional "fix_$name" setting.
|
||||
*/
|
||||
class admin_setting_quiz_text extends admin_setting_configtext {
|
||||
class admin_setting_text_with_advanced extends admin_setting_configtext {
|
||||
function __construct($name, $visiblename, $description, $defaultsetting, $paramtype) {
|
||||
$this->plugin = 'quiz';
|
||||
parent::admin_setting_configtext($name, $visiblename, $description,
|
||||
$defaultsetting, $paramtype);
|
||||
}
|
||||
|
@ -4248,11 +4272,10 @@ class admin_setting_quiz_text extends admin_setting_configtext {
|
|||
}
|
||||
|
||||
/**
|
||||
* Dropdown menu linked to config_plugins for the quiz, with an advanced checkbox.
|
||||
* Dropdown menu with an advanced checkbox, that controls a additional "fix_$name" setting.
|
||||
*/
|
||||
class admin_setting_quiz_combo extends admin_setting_configselect {
|
||||
class admin_setting_combo_with_advanced extends admin_setting_configselect {
|
||||
function __construct($name, $visiblename, $description, $defaultsetting, $choices) {
|
||||
$this->plugin = 'quiz';
|
||||
parent::admin_setting_configselect($name, $visiblename, $description,
|
||||
$defaultsetting, $choices);
|
||||
}
|
||||
|
@ -4316,106 +4339,11 @@ class admin_setting_quiz_combo extends admin_setting_configselect {
|
|||
}
|
||||
}
|
||||
|
||||
class admin_setting_quiz_reviewoptions extends admin_setting {
|
||||
private static $times = array(
|
||||
QUIZ_REVIEW_IMMEDIATELY => 'reviewimmediately',
|
||||
QUIZ_REVIEW_OPEN => 'reviewopen',
|
||||
QUIZ_REVIEW_CLOSED => 'reviewclosed');
|
||||
private static $things = array(
|
||||
QUIZ_REVIEW_RESPONSES => 'responses',
|
||||
QUIZ_REVIEW_ANSWERS => 'answers',
|
||||
QUIZ_REVIEW_FEEDBACK => 'feedback',
|
||||
QUIZ_REVIEW_GENERALFEEDBACK => 'generalfeedback',
|
||||
QUIZ_REVIEW_SCORES => 'scores',
|
||||
QUIZ_REVIEW_OVERALLFEEDBACK => 'overallfeedback');
|
||||
|
||||
function __construct($name, $visiblename, $description, $defaultsetting) {
|
||||
$this->plugin = 'quiz';
|
||||
parent::admin_setting($name, $visiblename, $description, $defaultsetting);
|
||||
}
|
||||
|
||||
private function normalise_data($data) {
|
||||
$value = 0;
|
||||
foreach (admin_setting_quiz_reviewoptions::$times as $timemask => $timestring) {
|
||||
foreach (admin_setting_quiz_reviewoptions::$things as $thingmask => $thingstring) {
|
||||
if (!empty($data[$timemask][$thingmask])) {
|
||||
$value += $timemask & $thingmask;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function get_setting() {
|
||||
$value = $this->config_read($this->name);
|
||||
$fix = $this->config_read('fix_' . $this->name);
|
||||
if (is_null($value) or is_null($fix)) {
|
||||
return NULL;
|
||||
}
|
||||
return array('value' => $value, 'fix' => $fix);
|
||||
}
|
||||
|
||||
function write_setting($data) {
|
||||
if (!isset($data['value'])) {
|
||||
$data['value'] = $this->normalise_data($data);
|
||||
}
|
||||
$ok = $this->config_write($this->name, $data['value']);
|
||||
if ($ok) {
|
||||
if (empty($data['fix'])) {
|
||||
$ok = $this->config_write('fix_' . $this->name, 0);
|
||||
} else {
|
||||
$ok = $this->config_write('fix_' . $this->name, 1);
|
||||
}
|
||||
}
|
||||
if (!$ok) {
|
||||
return get_string('errorsetting', 'admin');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function output_html($data, $query='') {
|
||||
if (!isset($data['value'])) {
|
||||
$data['value'] = $this->normalise_data($data);
|
||||
}
|
||||
|
||||
$return = '<div id="adminquizreviewoptions" class="clearfix">' . "\n";
|
||||
foreach (admin_setting_quiz_reviewoptions::$times as $timemask => $timestring) {
|
||||
$return .= '<div class="group"><div class="fitemtitle">' . get_string($timestring, 'quiz') . "</div>\n";
|
||||
$nameprefix = $this->get_full_name() . '[' . $timemask . ']';
|
||||
$idprefix = $this->get_id(). '_' . $timemask . '_';
|
||||
foreach (admin_setting_quiz_reviewoptions::$things as $thingmask => $thingstring) {
|
||||
$id = $idprefix . $thingmask;
|
||||
$state = '';
|
||||
if ($data['value'] & $timemask & $thingmask) {
|
||||
$state = 'checked="checked" ';
|
||||
}
|
||||
$return .= '<span><input type="checkbox" name="' .
|
||||
$nameprefix . '[' . $thingmask . ']" value="1" id="' . $id .
|
||||
'" ' . $state . '/> <label for="' . $id . '">' .
|
||||
get_string($thingstring, 'quiz') . "</label></span>\n";
|
||||
}
|
||||
$return .= "</div>\n";
|
||||
}
|
||||
$return .= "</div>\n";
|
||||
|
||||
$fix = !empty($data['fix']);
|
||||
$return .= '<input type="checkbox" class="form-checkbox" id="' .
|
||||
$this->get_id() . '_fix" name="' . $this->get_full_name() .
|
||||
'[fix]" value="1" ' . ($fix ? 'checked="checked"' : '') . ' />' .
|
||||
' <label for="' . $this->get_id() . '_fix">' .
|
||||
get_string('advanced') . '</label> ';
|
||||
|
||||
return format_admin_setting($this, $this->visiblename, $return,
|
||||
$this->description, true, '', get_string('everythingon', 'quiz'), $query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specialisation of admin_setting_quiz_combo for easy yes/no choices.
|
||||
* Specialisation of admin_setting_combo_with_advanced for easy yes/no choices.
|
||||
*/
|
||||
class admin_setting_quiz_yesno extends admin_setting_quiz_combo {
|
||||
class admin_setting_yesno_with_advanced extends admin_setting_combo_with_advanced {
|
||||
function __construct($name, $visiblename, $description, $defaultsetting) {
|
||||
$this->plugin = 'quiz';
|
||||
parent::__construct($name, $visiblename, $description,
|
||||
$defaultsetting, array(get_string('no'), get_string('yes')));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue