]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8857
authorthepurpleblob <thepurpleblob>
Mon, 12 Mar 2007 16:32:52 +0000 (16:32 +0000)
committerthepurpleblob <thepurpleblob>
Mon, 12 Mar 2007 16:32:52 +0000 (16:32 +0000)
Make numerical and essay question formats more consistent.

question/format/xml/format.php

index de91b20bd5e3b5bb66f119d8130fc59379d64a50..86a298f29a96a5fd1ebeeae0252af6e47a04a72a 100755 (executable)
@@ -244,7 +244,7 @@ class qformat_xml extends qformat_default {
 
         if ($warning) {
             $a = new stdClass;
-            $a->questiontext = stripslashes($qo->questiontext);
+            $a->questiontext = $qo->questiontext;
             $a->answer = get_string($qo->answer ? 'true' : 'false', 'quiz');
             notify(get_string('truefalseimporterror', 'quiz', $a));
         }
@@ -342,15 +342,28 @@ class qformat_xml extends qformat_default {
         $qo->fraction = array();
         $qo->tolerance = array();
         foreach ($answers as $answer) {
-            $answertext = trim($answer['#'][0]);
+            // answer outside of <text> is deprecated
+            if (!empty( $answer['#']['text'] )) {
+                $answertext = $this->import_text( $answer['#']['text'] );
+            }
+            else {
+                $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]['#'];
+
+            // fraction as a tag is deprecated
+            if (!empty($answer['#']['fraction'][0]['#'])) {
+                $qo->fraction[] = $answer['#']['fraction'][0]['#'];
+            }
+            else {
+                $qo->fraction[] = $answer['@']['fraction'] / 100;
+            }
         }
 
         // get units array
@@ -413,8 +426,16 @@ class qformat_xml extends qformat_default {
         // get feedback
         $qo->feedback = $this->import_text( $question['#']['answer'][0]['#']['feedback'][0]['#']['text'] );        
 
-        // get fraction
-        $qo->fraction = $question['#']['answer'][0]['#']['fraction'][0]['#'];
+        // handle answer
+        $answer = $question['#']['answer'][0];
+
+        // get fraction - <fraction> tag is deprecated
+        if (!empty($answer['#']['fraction'][0]['#'])) {
+            $qo->fraction = $answer['#']['fraction'][0]['#'];
+        }
+        else {
+            $qo->fraction = $answer['@']['fraction'] / 100;
+        }
 
         return $qo;
     }
@@ -783,11 +804,14 @@ class qformat_xml extends qformat_default {
         case NUMERICAL:
             foreach ($question->options->answers as $answer) {
                 $tolerance = $answer->tolerance;
-                $expout .= "<answer>\n";
-                $expout .= "    {$answer->answer}\n";
+                $percent = 100 * $answer->fraction;
+                $expout .= "<answer fraction=\"$percent\">\n";
+                // <text> tags are an added feature, old filed won't have them
+                $expout .= "    <text>{$answer->answer}</text>\n";
                 $expout .= "    <tolerance>$tolerance</tolerance>\n";
                 $expout .= "    <feedback>".$this->writetext( $answer->feedback )."</feedback>\n";
-                $expout .= "    <fraction>{$answer->fraction}</fraction>\n";
+                // fraction tag is deprecated
+                // $expout .= "    <fraction>{$answer->fraction}</fraction>\n";
                 $expout .= "</answer>\n";
             }
 
@@ -825,9 +849,11 @@ class qformat_xml extends qformat_default {
         break;
         case ESSAY:
             foreach ($question->options->answers as $answer) {
-                $expout .= "<answer>\n";
+                $percent = 100 * $answer->fraction;
+                $expout .= "<answer fraction=\"$percent\">\n";
                 $expout .= "    <feedback>".$this->writetext( $answer->feedback )."</feedback>\n";
-                $expout .= "    <fraction>{$answer->fraction}</fraction>\n";
+                // fraction tag is deprecated
+                // $expout .= "    <fraction>{$answer->fraction}</fraction>\n";
                 $expout .= "</answer>\n";
             }