]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9342 - Let the question author choose how the options are numbered in Multiple...
authortjhunt <tjhunt>
Fri, 13 Apr 2007 21:16:04 +0000 (21:16 +0000)
committertjhunt <tjhunt>
Fri, 13 Apr 2007 21:16:04 +0000 (21:16 +0000)
lang/en_utf8/help/quiz/shuffleanswers.html
lang/en_utf8/qtype_multichoice.php
question/type/multichoice/db/install.xml
question/type/multichoice/db/upgrade.php
question/type/multichoice/edit_multichoice_form.php
question/type/multichoice/questiontype.php
question/type/multichoice/version.php

index 77ae4523816f381aa62c97316356761e7f0f3096..90affd5a1272ccb99bf8a91998a0cf7e7771989e 100644 (file)
@@ -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>
index ff25aea1ec338fd39fb896d553c0e5c4826be5da..8cecea59f5e2568b214bf87a2440a5b0bc2b8bdc 100644 (file)
@@ -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.';
-
 ?>
index 73202e2b00c9f19e6abe4113c7300e86f3b16449..d6b39f76bfc26cca2cdc55122f46da6b17922bb7 100644 (file)
@@ -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"/>
index 46015de1e79ee03b8013969f431709822bb958d0..87157f3cc349052289b1bebafcf174bc0e8f3c79 100644 (file)
@@ -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;
 }
 
index 1040217dd881ed38af4fd213d7ecabb427b5a11e..cd0540e24fed3eb16cdc4df8d9b4ae3ebd0b6116 100644 (file)
@@ -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;
index 18f15d5765f57a9a3755cb39cab47cd4070da1ba..a10c7d12fa7084794002472e4e8464da5c90ea19 100644 (file)
@@ -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);
     }
 
+    /**
+     * @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());
 ?>
index e708d3dffc5fef75e6882f44b8fc5da6120e23b7..8ef7fd364d85fb08132381fda445b8bd0a6a0fb9 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP // $Id$
 
-$plugin->version  = 2006121500;
+$plugin->version  = 2007041300;
 $plugin->requires = 2006032200;
 
 ?>