]> git.mjollnir.org Git - moodle.git/commitdiff
Now supports shortanswer import. Cleaned up the CDATA import too.
authorthepurpleblob <thepurpleblob>
Fri, 24 Dec 2004 11:16:43 +0000 (11:16 +0000)
committerthepurpleblob <thepurpleblob>
Fri, 24 Dec 2004 11:16:43 +0000 (11:16 +0000)
mod/quiz/format/xml/format.php

index 5971397a2e0115e4b7afe0310ccdbc78802541a6..dff3d3867c417e66728b1ec715585cb9e6e98850 100755 (executable)
@@ -109,12 +109,10 @@ function import_multichoice( $question ) {
   $qo->single = $this->trans_single( $single );
 
   // run through the answers
-  // $qo->answer = array();
   $answers = $question['#']['answer'];  
   $a_count = 0;
   foreach ($answers as $answer) {
      $ans = $this->import_answer( $answer );
-     // $qo->answer[] = $ans;
      $qo->answer[$a_count] = $ans->answer;
      $qo->fraction[$a_count] = $ans->fraction;
      $qo->feedback[$a_count] = $ans->feedback;
@@ -155,6 +153,29 @@ function import_truefalse( $question ) {
   return $qo;
 }
 
+function import_shortanswer( $question ) {
+  // import short answer question
+
+  // get common parts
+  $qo = $this->import_headers( $question );
+
+  // header parts particular to shortanswer
+  $qo->qtype = SHORTANSWER;
+
+  // run through the answers
+  $answers = $question['#']['answer'];  
+  $a_count = 0;
+  foreach ($answers as $answer) {
+     $ans = $this->import_answer( $answer );
+     $qo->answer[$a_count] = $ans->answer;
+     $qo->fraction[$a_count] = $ans->fraction;
+     $qo->feedback[$a_count] = $ans->feedback;
+     ++$a_count;
+  }
+
+  return $qo;
+}
+
 function readquestions($lines) {
   // parse the array of lines into an array of questions
   // this *could* burn memory - but it won't happen that much
@@ -165,8 +186,9 @@ function readquestions($lines) {
   unset( $lines );
 
   // this converts xml to big nasty data structure
+  // the 0 means keep white space as it is (important for markdown format)
   // print_r it if you want to see what it looks like!
-  $xml = xmlize( $text ); 
+  $xml = xmlize( $text, 0 ); 
 
   // set up array to hold all our questions
   $questions = array();
@@ -182,6 +204,9 @@ function readquestions($lines) {
     elseif ($question_type=='truefalse') {
       $qo = $this->import_truefalse( $question );
     }
+    elseif ($question_type=='shortanswer') {
+      $qo = $this->import_shortanswer( $question );
+    }
     else {
       echo "<p>Question type $question_type not currently supported for xml import</p>";
       $qo = null;
@@ -449,10 +474,12 @@ function writequestion( $question ) {
     case SHORTANSWER:
         foreach($question->answers as $answer) {
             $percent = 100 * $answer->fraction;
-            $expout .= "<answer fraction=\"$percent\">\n";
-            $expout .= $this->writetext( $answer->answer );
-            $expout .= "<feedback>".$this->writetext( $answer->feedback )."</feedback>\n";
-            $expout .= "</answer>\n";
+            $expout .= "    <answer fraction=\"$percent\">\n";
+            $expout .= $this->writetext( $answer->answer,3,false );
+            $expout .= "      <feedback>\n";
+            $expout .= $this->writetext( $answer->feedback,4,false );
+            $expout .= "      </feedback>\n";
+            $expout .= "    </answer>\n";
         }
         break;
     case NUMERICAL: