MDL-7928 - Numerical question type should use * for the match anything answer. Merged...
authortjhunt <tjhunt>
Fri, 15 Dec 2006 18:30:39 +0000 (18:30 +0000)
committertjhunt <tjhunt>
Fri, 15 Dec 2006 18:30:39 +0000 (18:30 +0000)
lang/en_utf8/help/quiz/numerical.html
question/format/xml/format.php
question/type/numerical/db/upgrade.php
question/type/numerical/questiontype.php
question/type/numerical/version.php

index 81636c3..18e90b8 100644 (file)
@@ -10,4 +10,7 @@ then any number between 25 and 35 will be accepted as correct.</p>
 
 <p>Like with short answer questions, different answers, or the same
 answer with different precisions can be given. In this case, the first
-matching answer is used to determine the score and the feedback.<p>
\ No newline at end of file
+matching answer is used to determine the score and the feedback.<p>
+
+<p>To provide feedback for responses that do not match any of the answers 
+you entered, provide some feedback with a '*' in the answer box.</p>
\ No newline at end of file
index f7c6425..e3ec77e 100755 (executable)
@@ -326,7 +326,12 @@ class qformat_xml extends qformat_default {
         $qo->fraction = array();
         $qo->tolerance = array();
         foreach ($answers as $answer) {
-            $qo->answer[] = $answer['#'][0];
+            $answertext = trim($answer['#'][0]);
+            if ($answertext == '') {
+                $qo->answer[] = '*';
+            } else {
+                $qo->answer[] = $answertext;
+            }
             $qo->feedback[] = $this->import_text( $answer['#']['feedback'][0]['#']['text'] );
             $qo->fraction[] = $answer['#']['fraction'][0]['#'];
             $qo->tolerance[] = $answer['#']['tolerance'][0]['#'];
index 6102a8f..05dab09 100644 (file)
@@ -23,14 +23,12 @@ function xmldb_qtype_numerical_upgrade($oldversion=0) {
 
     $result = true;
 
-/// And upgrade begins here. For each one, you'll need one 
-/// block of code similar to the next one. Please, delete 
-/// this comment lines once this file start handling proper
-/// upgrade code.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-///     $result = result of "/lib/ddllib.php" function calls
-/// }
+    // In numerical questions, we are changing the 'match anything' answer
+    // from the empty string to *, to be like short answer questions.
+    if ($result && $oldversion < 2006121500) {
+        $result = set_field_select('question_answers', 'answer', '*',
+                "answer = '' AND question IN (SELECT id FROM {$CFG->prefix}question WHERE qtype = '" . NUMERICAL . "')");
+    }
 
     return $result;
 }
index 5f33688..476ab96 100644 (file)
@@ -117,8 +117,8 @@ class question_numerical_qtype extends question_shortanswer_qtype {
             if ($dataanswer != '' || trim($question->feedback[$key])) {
                 $answer = new stdClass;
                 $answer->question = $question->id;
-                if (trim($dataanswer) == '') {
-                    $answer->answer = '';
+                if (trim($dataanswer) == '*') {
+                    $answer->answer = '*';
                 } else {
                     $answer->answer = $this->apply_unit($dataanswer, $units);
                     if ($answer->answer === false) {
@@ -269,8 +269,9 @@ class question_numerical_qtype extends question_shortanswer_qtype {
      * answer, false if it doesn't.
      */
     function test_response(&$question, &$state, $answer) {
-        if ($answer->answer == '') {
-            return true; // Blank answer matches anything.
+        // Deal with the match anything answer.
+        if ($answer->answer == '*') {
+            return true;
         }
 
         $response = $this->apply_unit(stripslashes($state->responses['']), $question->options->units);
@@ -297,7 +298,7 @@ class question_numerical_qtype extends question_shortanswer_qtype {
 
     function get_correct_responses(&$question, &$state) {
         $correct = parent::get_correct_responses($question, $state);
-        if ($unit = $this->get_default_numerical_unit($question)) {
+        if ($correct[''] != '*' && $unit = $this->get_default_numerical_unit($question)) {
             $correct[''] .= ' '.$unit->unit;
         }
         return $correct;
@@ -314,8 +315,8 @@ class question_numerical_qtype extends question_shortanswer_qtype {
                 $r->answer = $answer->answer;
                 $r->credit = $answer->fraction;
                 $this->get_tolerance_interval($answer);
-                if ($unit) {
-                    $r->answer .= ' '.$unit->unit;
+                if ($r->answer != '*' && $unit) {
+                    $r->answer .= ' ' . $unit->unit;
                 }
                 if ($answer->max != $answer->min) {
                     $max = "$answer->max"; //format_float($answer->max, 2);
@@ -465,9 +466,12 @@ class question_numerical_qtype extends question_shortanswer_qtype {
             $numerical = new stdClass;
             $numerical->question = $new_question_id;
             $numerical->answer = backup_todb($num_info['#']['ANSWER']['0']['#']);
+            if ($numerical->answer = '') {
+                $numerical->answer = '*';
+            }
             $numerical->tolerance = backup_todb($num_info['#']['TOLERANCE']['0']['#']);
 
-            ////We have to recode the answer field
+            //We have to recode the answer field
             $answer = backup_getid($restore->backup_unique_code,"question_answers",$numerical->answer);
             if ($answer) {
                 $numerical->answer = $answer->new_id;
index 2d2a8d9..e708d3d 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP // $Id$
 
-$plugin->version  = 2006032200;
+$plugin->version  = 2006121500;
 $plugin->requires = 2006032200;
 
 ?>