MDL-9342 - Let the question author choose how the options are numbered in Multiple choices questions.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<h1>Shuffle answers</h1>
|
||||
<h1>Shuffle the choices</h1>
|
||||
|
||||
<p>If you enable this option, then the order of answers within
|
||||
<p>If you enable this option, then the order of choices within
|
||||
each question will be randomly shuffled each time a student
|
||||
attempts this quiz.</p>
|
||||
|
||||
<p>Of course, this only applies to questions that have multiple
|
||||
answers displayed, such as Multiple Choice or Matching Questions.</p>
|
||||
options displayed, such as multiple choice or matching questions.</p>
|
||||
|
||||
<p>The intention is simply to make it a little harder for students
|
||||
to copy from each other.</p>
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
<?PHP // $Id$
|
||||
// qtype_multichoice.php - created with Moodle 1.7 beta + (2006101003)
|
||||
|
||||
|
||||
$string['answerhowmany'] = 'One or multiple answers?';
|
||||
$string['addmorechoiceblanks'] = 'Blanks for {no} More Choices';
|
||||
$string['answerhowmany'] = 'One or multiple answers?';
|
||||
$string['answernumbering'] = 'Number the choices?';
|
||||
$string['answernumberingabc'] = 'a., b., c., ...';
|
||||
$string['answernumberingABC'] = 'A., B., C., ...';
|
||||
$string['answernumbering123'] = '1., 2., 3., ...';
|
||||
$string['answernumberingnone'] = 'No numbering';
|
||||
$string['answersingleno'] = 'Multiple answers allowed';
|
||||
$string['answersingleyes'] = 'One answer only';
|
||||
$string['choiceno'] = 'Choice $a';
|
||||
$string['choices'] = 'Available choices';
|
||||
$string['clozeaid'] = 'Enter missing word';
|
||||
$string['correctfeedback'] = 'For any correct answer';
|
||||
$string['correctfeedback'] = 'For any correct response';
|
||||
$string['editingmultichoice'] = 'Editing a Multiple Choice question';
|
||||
$string['errfractionsaddwrong'] = 'The positive grades you have chosen do not add up to 100%%<br />Instead, they add up to $a%%';
|
||||
$string['errfractionsnomax'] = 'One of the answers should be 100%%, so that it is<br />possible to get a full grade for this question.';
|
||||
$string['errfractionsnomax'] = 'One of the choices should be 100%%, so that it is<br />possible to get a full grade for this question.';
|
||||
$string['feedback'] = 'Feedback';
|
||||
$string['fillouttwochoices'] = 'You must fill out at least two choices. Choices left blank will not be used.';
|
||||
$string['fractionsaddwrong'] = 'The positive grades you have chosen do not add up to 100%%<br />Instead, they add up to $a%%<br />Do you want to go back and fix this question?';
|
||||
$string['fractionsnomax'] = 'One of the answers should be 100%%, so that it is<br />possible to get a full grade for this question.<br />Do you want to go back and fix this question?';
|
||||
$string['incorrectfeedback'] = 'For any incorrect answer';
|
||||
$string['notenoughanswers'] = 'This type of question requires at least $a answers';
|
||||
$string['fractionsnomax'] = 'One of the choices should be 100%%, so that it is<br />possible to get a full grade for this question.<br />Do you want to go back and fix this question?';
|
||||
$string['incorrectfeedback'] = 'For any incorrect response';
|
||||
$string['notenoughanswers'] = 'This type of question requires at least $a choices';
|
||||
$string['overallfeedback'] = 'Overall Feedback';
|
||||
$string['overallcorrectfeedback'] = 'Feedback for any correct answer';
|
||||
$string['overallincorrectfeedback'] = 'Feedback for any incorrect answer';
|
||||
$string['overallpartiallycorrectfeedback'] = 'Feedback for any partially correct answer';
|
||||
$string['partiallycorrectfeedback'] = 'For any partially correct answer';
|
||||
$string['shuffleanswers'] = 'Shuffle answers';
|
||||
$string['overallcorrectfeedback'] = 'Feedback for any correct response';
|
||||
$string['overallincorrectfeedback'] = 'Feedback for any incorrect response';
|
||||
$string['overallpartiallycorrectfeedback'] = 'Feedback for any partially correct response';
|
||||
$string['partiallycorrectfeedback'] = 'For any partially correct response';
|
||||
$string['shuffleanswers'] = 'Shuffle the choices?';
|
||||
$string['singleanswer'] = 'Choose one answer.';
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="question/type/multichoice/db" VERSION="20060824" COMMENT="XMLDB file for Moodle question/type/multichoice">
|
||||
<XMLDB PATH="question/type/multichoice/db" VERSION="20070413" COMMENT="XMLDB file for Moodle question/type/multichoice"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
<TABLES>
|
||||
<TABLE NAME="question_multichoice" COMMENT="Options for multiple choice questions">
|
||||
<FIELDS>
|
||||
@@ -11,7 +14,8 @@
|
||||
<FIELD NAME="shuffleanswers" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="single" NEXT="correctfeedback"/>
|
||||
<FIELD NAME="correctfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="shuffleanswers" NEXT="partiallycorrectfeedback"/>
|
||||
<FIELD NAME="partiallycorrectfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="correctfeedback" NEXT="incorrectfeedback"/>
|
||||
<FIELD NAME="incorrectfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="partiallycorrectfeedback"/>
|
||||
<FIELD NAME="incorrectfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="partiallycorrectfeedback" NEXT="answernumbering"/>
|
||||
<FIELD NAME="answernumbering" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="abc" SEQUENCE="false" ENUM="true" ENUMVALUES="'abc', 'ABC', '123', 'none'" COMMENT="Indicates how and whether the choices should be numbered." PREVIOUS="incorrectfeedback"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for question_multichoice" NEXT="question"/>
|
||||
|
||||
@@ -34,6 +34,15 @@ function xmldb_qtype_multichoice_upgrade($oldversion=0) {
|
||||
'qtype', DESCRIPTION, 'defaultgrade', 1);
|
||||
}
|
||||
|
||||
// Add a field so that question authors can choose whether and how the
|
||||
// Choices are numbered.
|
||||
if ($result && $oldversion < 2007041300) {
|
||||
$table = new XMLDBTable('question_multichoice');
|
||||
$field = new XMLDBField('answernumbering');
|
||||
$field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('abc', 'ABC', '123', 'none'), 'abc', 'incorrectfeedback');
|
||||
$result = $result && add_field($table, $field);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ class question_edit_multichoice_form extends question_edit_form {
|
||||
* @param object $mform the form being built.
|
||||
*/
|
||||
function definition_inner(&$mform) {
|
||||
global $QTYPES;
|
||||
|
||||
$menu = array(get_string('answersingleno', 'qtype_multichoice'), get_string('answersingleyes', 'qtype_multichoice'));
|
||||
$mform->addElement('select', 'single', get_string('answerhowmany', 'qtype_multichoice'), $menu);
|
||||
$mform->setDefault('single', 1);
|
||||
@@ -27,6 +29,14 @@ class question_edit_multichoice_form extends question_edit_form {
|
||||
$mform->setHelpButton('shuffleanswers', array('multichoiceshuffle', get_string('shuffleanswers','qtype_multichoice'), 'quiz'));
|
||||
$mform->setDefault('shuffleanswers', 1);
|
||||
|
||||
$numberingoptions = $QTYPES[$this->qtype()]->get_numbering_styles();
|
||||
$menu = array();
|
||||
foreach ($numberingoptions as $numberingoption) {
|
||||
$menu[$numberingoption] = get_string('answernumbering' . $numberingoption, 'qtype_multichoice');
|
||||
}
|
||||
$mform->addElement('select', 'answernumbering', get_string('answernumbering', 'qtype_multichoice'), $menu);
|
||||
$mform->setDefault('answernumbering', 'abc');
|
||||
|
||||
/* $mform->addElement('static', 'answersinstruct', get_string('choices', 'qtype_multichoice'), get_string('fillouttwochoices', 'qtype_multichoice'));
|
||||
$mform->closeHeaderBefore('answersinstruct');
|
||||
*/
|
||||
@@ -76,6 +86,7 @@ class question_edit_multichoice_form extends question_edit_form {
|
||||
}
|
||||
}
|
||||
$default_values['single'] = $question->options->single;
|
||||
$default_values['answernumbering'] = $question->options->answernumbering;
|
||||
$default_values['shuffleanswers'] = $question->options->shuffleanswers;
|
||||
$default_values['correctfeedback'] = $question->options->correctfeedback;
|
||||
$default_values['partiallycorrectfeedback'] = $question->options->partiallycorrectfeedback;
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////
|
||||
/// MULTICHOICE ///
|
||||
///////////////////
|
||||
|
||||
/// QUESTION TYPE CLASS //////////////////
|
||||
|
||||
///
|
||||
/// This class contains some special features in order to make the
|
||||
/// question type embeddable within a multianswer (cloze) question
|
||||
///
|
||||
/**
|
||||
* The questiontype class for the multiple choice question type.
|
||||
*
|
||||
* Note, This class contains some special features in order to make the
|
||||
* question type embeddable within a multianswer (cloze) question
|
||||
*
|
||||
* @package questionbank
|
||||
* @subpackage questiontypes
|
||||
*/
|
||||
|
||||
*/
|
||||
class question_multichoice_qtype extends default_questiontype {
|
||||
|
||||
function name() {
|
||||
@@ -107,6 +100,7 @@ class question_multichoice_qtype extends default_questiontype {
|
||||
}
|
||||
$options->answers = implode(",",$answers);
|
||||
$options->single = $question->single;
|
||||
$options->answernumbering = $question->answernumbering;
|
||||
$options->shuffleanswers = $question->shuffleanswers;
|
||||
$options->correctfeedback = trim($question->correctfeedback);
|
||||
$options->partiallycorrectfeedback = trim($question->partiallycorrectfeedback);
|
||||
@@ -285,7 +279,6 @@ class question_multichoice_qtype extends default_questiontype {
|
||||
// Print each answer in a separate row
|
||||
foreach ($state->options->order as $key => $aid) {
|
||||
$answer = &$answers[$aid];
|
||||
$qnumchar = chr(ord('a') + $key);
|
||||
$checked = '';
|
||||
$chosen = false;
|
||||
|
||||
@@ -322,7 +315,8 @@ class question_multichoice_qtype extends default_questiontype {
|
||||
}
|
||||
|
||||
// Print the answer text
|
||||
$a->text = format_text("$qnumchar. $answer->answer", FORMAT_MOODLE, $formatoptions, $cmoptions->course);
|
||||
$a->text = format_text($this->number_in_style($key, $question->options->answernumbering) . $answer->answer,
|
||||
FORMAT_MOODLE, $formatoptions, $cmoptions->course);
|
||||
|
||||
// Print feedback if feedback is on
|
||||
if (($options->feedback || $options->correct_responses) && $checked) {
|
||||
@@ -555,11 +549,37 @@ class question_multichoice_qtype extends default_questiontype {
|
||||
return implode(',', $order).':'.implode(',', $responses);
|
||||
}
|
||||
|
||||
}
|
||||
//// END OF CLASS ////
|
||||
/**
|
||||
* @return array of the numbering styles supported. For each one, there
|
||||
* should be a lang string answernumberingxxx in teh qtype_multichoice
|
||||
* language file, and a case in the switch statement in number_in_style,
|
||||
* and it should be listed in the definition of this column in install.xml.
|
||||
*/
|
||||
function get_numbering_styles() {
|
||||
return array('abc', 'ABC', '123', 'none');
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//// INITIATION - Without this line the question type is not in use... ///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @param int $num The number, starting at 0.
|
||||
* @param string $style The style to render the number in. One of the ones returned by $numberingoptions.
|
||||
* @return string the number $num in the requested style.
|
||||
*/
|
||||
function number_in_style($num, $style) {
|
||||
switch($style) {
|
||||
case 'abc':
|
||||
return chr(ord('a') + $num) . '. ';
|
||||
case 'ABC':
|
||||
return chr(ord('A') + $num) . '. ';
|
||||
case '123':
|
||||
return ($num + 1) . '. ';
|
||||
case 'none':
|
||||
return '';
|
||||
default:
|
||||
return 'ERR';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register this question type with the question bank.
|
||||
question_register_questiontype(new question_multichoice_qtype());
|
||||
?>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
$plugin->version = 2006121500;
|
||||
$plugin->version = 2007041300;
|
||||
$plugin->requires = 2006032200;
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user