Commit 06bedaf8 authored by Nadav Kavalerchik's avatar Nadav Kavalerchik Committed by Nick Phillips
Browse files

MDL-50011 qtype_multichoice: add settings (defaults for new questions)

parent 9e7afbbc
<?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/>.
/**
* Admin settings for the multichoice question type.
*
* @package qtype_multichoice
* @copyright 2015 onwards Nadav Kavalerchik
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Admin settings class for the multichoice question type method.
*
* Just so we can lazy-load the numbering style choices.
*
* @copyright 2015 onwards Nadav Kavalerchik
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_multichoice_admin_setting_answernumbering extends admin_setting_configselect {
/**
* This function may be used in ancestors for lazy loading of choices
*
* Override this method if loading of choices is expensive, such
* as when it requires multiple db requests.
*
* @return bool true if loaded, false if error
*/
public function load_choices() {
global $CFG;
if (is_array($this->choices)) {
return true;
}
require_once($CFG->dirroot . '/question/type/multichoice/questiontype.php');
$this->choices = qtype_multichoice::get_numbering_styles();
return true;
}
}
......@@ -46,17 +46,17 @@ class qtype_multichoice_edit_form extends question_edit_form {
);
$mform->addElement('select', 'single',
get_string('answerhowmany', 'qtype_multichoice'), $menu);
$mform->setDefault('single', 1);
$mform->setDefault('single', get_config('qtype_multichoice', 'answerhowmany'));
$mform->addElement('advcheckbox', 'shuffleanswers',
get_string('shuffleanswers', 'qtype_multichoice'), null, null, array(0, 1));
$mform->addHelpButton('shuffleanswers', 'shuffleanswers', 'qtype_multichoice');
$mform->setDefault('shuffleanswers', 1);
$mform->setDefault('shuffleanswers', get_config('qtype_multichoice', 'shuffleanswers'));
$mform->addElement('select', 'answernumbering',
get_string('answernumbering', 'qtype_multichoice'),
qtype_multichoice::get_numbering_styles());
$mform->setDefault('answernumbering', 'abc');
$mform->setDefault('answernumbering', get_config('qtype_multichoice', 'answernumbering'));
$this->add_per_answer_fields($mform, get_string('choiceno', 'qtype_multichoice', '{no}'),
question_bank::fraction_options_full(), max(5, QUESTION_NUMANS_START));
......
......@@ -24,6 +24,7 @@
*/
$string['answerhowmany'] = 'One or multiple answers?';
$string['answerhowmany_desc'] = 'Should the default for new multichoice questions be to require single or multiple answers?';
$string['answernumbering'] = 'Number the choices?';
$string['answernumbering123'] = '1., 2., 3., ...';
$string['answernumberingabc'] = 'a., b., c., ...';
......@@ -31,6 +32,7 @@ $string['answernumberingABCD'] = 'A., B., C., ...';
$string['answernumberingiii'] = 'i., ii., iii., ...';
$string['answernumberingIIII'] = 'I., II., III., ...';
$string['answernumberingnone'] = 'No numbering';
$string['answernumbering_desc'] = 'Set the default numbering style for new multichoice questions.';
$string['answersingleno'] = 'Multiple answers allowed';
$string['answersingleyes'] = 'One answer only';
$string['choiceno'] = 'Choice {$a}';
......@@ -65,6 +67,7 @@ $string['pluginnamesummary'] = 'Allows the selection of a single or multiple res
$string['selectmulti'] = 'Select one or more:';
$string['selectone'] = 'Select one:';
$string['shuffleanswers'] = 'Shuffle the choices?';
$string['shuffleanswers_desc'] = 'Should the default for new nultichoice questions be to shuffle answers?';
$string['shuffleanswers_help'] = 'If enabled, the order of the answers is randomly shuffled for each attempt, provided that "Shuffle within questions" in the activity settings is also enabled.';
$string['singleanswer'] = 'Choose one answer.';
$string['toomanyselected'] = 'You have selected too many options.';
<?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/>.
/**
* Admin settings for the multichoice question type.
*
* @package qtype_multichoice
* @copyright 2015 onwards Nadav Kavalerchik
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
if ($ADMIN->fulltree) {
$menu = array(
new lang_string('answersingleno', 'qtype_multichoice'),
new lang_string('answersingleyes', 'qtype_multichoice'),
);
$settings->add(new admin_setting_configselect('qtype_multichoice/answerhowmany',
new lang_string('answerhowmany', 'qtype_multichoice'),
new lang_string('answerhowmany_desc', 'qtype_multichoice'), '1', $menu));
$settings->add(new admin_setting_configcheckbox('qtype_multichoice/shuffleanswers',
new lang_string('shuffleanswers', 'qtype_multichoice'),
new lang_string('shuffleanswers_desc', 'qtype_multichoice'), '1'));
$settings->add(new qtype_multichoice_admin_setting_answernumbering('qtype_multichoice/answernumbering',
new lang_string('answernumbering', 'qtype_multichoice'),
new lang_string('answernumbering_desc', 'qtype_multichoice'), 'abc', null ));
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment