diff --git a/question/type/multichoice/classes/admin_setting_answernumbering.php b/question/type/multichoice/classes/admin_setting_answernumbering.php new file mode 100644 index 00000000000..80de03a87d3 --- /dev/null +++ b/question/type/multichoice/classes/admin_setting_answernumbering.php @@ -0,0 +1,57 @@ +. + +/** + * 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; + } +} diff --git a/question/type/multichoice/edit_multichoice_form.php b/question/type/multichoice/edit_multichoice_form.php index b0dc614b4b7..372dfcadd0c 100644 --- a/question/type/multichoice/edit_multichoice_form.php +++ b/question/type/multichoice/edit_multichoice_form.php @@ -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)); diff --git a/question/type/multichoice/lang/en/qtype_multichoice.php b/question/type/multichoice/lang/en/qtype_multichoice.php index 73055521d4d..18aacbd660f 100644 --- a/question/type/multichoice/lang/en/qtype_multichoice.php +++ b/question/type/multichoice/lang/en/qtype_multichoice.php @@ -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.'; diff --git a/question/type/multichoice/settings.php b/question/type/multichoice/settings.php new file mode 100644 index 00000000000..83697b374e3 --- /dev/null +++ b/question/type/multichoice/settings.php @@ -0,0 +1,44 @@ +. + +/** + * 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 )); + +}