From 3e0647ffaf2c81224b6f7d2ed24d5188888fcfb5 Mon Sep 17 00:00:00 2001
From: tjhunt
Date: Fri, 13 Apr 2007 21:16:04 +0000
Subject: [PATCH] MDL-9342 - Let the question author choose how the options are
numbered in Multiple choices questions.
---
lang/en_utf8/help/quiz/shuffleanswers.html | 6 +-
lang/en_utf8/qtype_multichoice.php | 28 +++++----
question/type/multichoice/db/install.xml | 8 ++-
question/type/multichoice/db/upgrade.php | 9 +++
.../multichoice/edit_multichoice_form.php | 11 ++++
question/type/multichoice/questiontype.php | 58 +++++++++++++------
question/type/multichoice/version.php | 2 +-
7 files changed, 85 insertions(+), 37 deletions(-)
diff --git a/lang/en_utf8/help/quiz/shuffleanswers.html b/lang/en_utf8/help/quiz/shuffleanswers.html
index 77ae452381..90affd5a12 100644
--- a/lang/en_utf8/help/quiz/shuffleanswers.html
+++ b/lang/en_utf8/help/quiz/shuffleanswers.html
@@ -1,11 +1,11 @@
-Shuffle answers
+Shuffle the choices
-If you enable this option, then the order of answers within
+
If you enable this option, then the order of choices within
each question will be randomly shuffled each time a student
attempts this quiz.
Of course, this only applies to questions that have multiple
- answers displayed, such as Multiple Choice or Matching Questions.
+ options displayed, such as multiple choice or matching questions.
The intention is simply to make it a little harder for students
to copy from each other.
diff --git a/lang/en_utf8/qtype_multichoice.php b/lang/en_utf8/qtype_multichoice.php
index ff25aea1ec..8cecea59f5 100644
--- a/lang/en_utf8/qtype_multichoice.php
+++ b/lang/en_utf8/qtype_multichoice.php
@@ -1,30 +1,34 @@
Instead, they add up to $a%%';
-$string['errfractionsnomax'] = 'One of the answers should be 100%%, so that it is
possible to get a full grade for this question.';
+$string['errfractionsnomax'] = 'One of the choices should be 100%%, so that it is
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%%
Instead, they add up to $a%%
Do you want to go back and fix this question?';
-$string['fractionsnomax'] = 'One of the answers should be 100%%, so that it is
possible to get a full grade for this question.
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
possible to get a full grade for this question.
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.';
-
?>
diff --git a/question/type/multichoice/db/install.xml b/question/type/multichoice/db/install.xml
index 73202e2b00..d6b39f76bf 100644
--- a/question/type/multichoice/db/install.xml
+++ b/question/type/multichoice/db/install.xml
@@ -1,5 +1,8 @@
-
+
@@ -11,7 +14,8 @@
-
+
+
diff --git a/question/type/multichoice/db/upgrade.php b/question/type/multichoice/db/upgrade.php
index 46015de1e7..87157f3cc3 100644
--- a/question/type/multichoice/db/upgrade.php
+++ b/question/type/multichoice/db/upgrade.php
@@ -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;
}
diff --git a/question/type/multichoice/edit_multichoice_form.php b/question/type/multichoice/edit_multichoice_form.php
index 1040217dd8..cd0540e24f 100644
--- a/question/type/multichoice/edit_multichoice_form.php
+++ b/question/type/multichoice/edit_multichoice_form.php
@@ -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;
diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php
index 18f15d5765..a10c7d12fa 100644
--- a/question/type/multichoice/questiontype.php
+++ b/question/type/multichoice/questiontype.php
@@ -1,20 +1,13 @@
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);
}
+ /**
+ * @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');
+ }
+
+ /**
+ * @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';
+ }
+ }
}
-//// END OF CLASS ////
-//////////////////////////////////////////////////////////////////////////
-//// INITIATION - Without this line the question type is not in use... ///
-//////////////////////////////////////////////////////////////////////////
+// Register this question type with the question bank.
question_register_questiontype(new question_multichoice_qtype());
?>
diff --git a/question/type/multichoice/version.php b/question/type/multichoice/version.php
index e708d3dffc..8ef7fd364d 100644
--- a/question/type/multichoice/version.php
+++ b/question/type/multichoice/version.php
@@ -1,6 +1,6 @@
version = 2006121500;
+$plugin->version = 2007041300;
$plugin->requires = 2006032200;
?>
--
2.39.5