Skip to content

Commit

Permalink
MDL-50011 qtype_multichoice: add settings (defaults for new questions)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavkav authored and nwp90 committed Jun 6, 2017
1 parent 9e7afbb commit 06bedaf
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 3 deletions.
@@ -0,0 +1,57 @@
<?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;
}
}
6 changes: 3 additions & 3 deletions question/type/multichoice/edit_multichoice_form.php
Expand Up @@ -46,17 +46,17 @@ protected function definition_inner($mform) {
);
$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));
Expand Down
3 changes: 3 additions & 0 deletions question/type/multichoice/lang/en/qtype_multichoice.php
Expand Up @@ -24,13 +24,15 @@
*/

$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., ...';
$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}';
Expand Down Expand Up @@ -65,6 +67,7 @@
$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.';
44 changes: 44 additions & 0 deletions question/type/multichoice/settings.php
@@ -0,0 +1,44 @@
<?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 ));

}

0 comments on commit 06bedaf

Please sign in to comment.