]> git.mjollnir.org Git - moodle.git/commitdiff
Added support for matching questions. Bug #3901
authorthepurpleblob <thepurpleblob>
Thu, 23 Mar 2006 11:13:50 +0000 (11:13 +0000)
committerthepurpleblob <thepurpleblob>
Thu, 23 Mar 2006 11:13:50 +0000 (11:13 +0000)
question/format/xml/format.php

index bbeaceaa3e7c6413425ad725275b00f13e29c936..e3b94ebdf0169e50d490932776ebd4479b4a99ab 100755 (executable)
@@ -81,7 +81,7 @@ class qformat_xml extends qformat_default {
         $image = $question['#']['image'][0]['#'];
         $penalty = $question['#']['penalty'][0]['#'];
 
-        $qo = null;
+        $qo = $this->defaultquestion();
         $qo->name = $name;
         $qo->questiontext = $qtext;
         $qo->questiontextformat = $this->trans_format( $qformat );
@@ -223,6 +223,32 @@ class qformat_xml extends qformat_default {
         return $qo;
     }
 
+    function import_matching( $question ) {
+        // import matching question
+
+        // get common parts
+        $qo = $this->import_headers( $question );
+
+        // header parts particular to matching
+        $qo->qtype = MATCH;
+        $qo->shuffleanswers = $question['#']['shuffleanswers'][0]['#'];
+
+        // get subquestions
+        $subquestions = $question['#']['subquestion'];
+        $qo->subquestions = array();
+        $qo->subanswers = array();
+
+        // run through subquestions
+        foreach ($subquestions as $subquestion) {
+            $qtext = $subquestion['#']['text'][0]['#'];
+            $atext = $subquestion['#']['answer'][0]['#']['text'][0]['#'];
+            $qo->subquestions[] = $qtext;
+            $qo->subanswers[] = $atext;
+        }
+//echo "<pre>"; print_r( $qo ); die;
+        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
@@ -258,6 +284,9 @@ class qformat_xml extends qformat_default {
             elseif ($question_type=='numerical') {
                 $qo = $this->import_numerical( $question );
             }
+            elseif ($question_type=='matching') {
+                $qo = $this->import_matching( $question );
+            }
             else {
                 $notsupported = get_string( 'xmlnotsupported','quiz',$question_type );
                 echo "<p>$notsupported</p>";
@@ -492,6 +521,7 @@ class qformat_xml extends qformat_default {
         $expout .= "    <image>".$question->image."</image>\n";
         $expout .= "    <penalty>{$question->penalty}</penalty>\n";
         $expout .= "    <hidden>{$question->hidden}</hidden>\n";
+        $expout .= "    <shuffleanswers>{$question->options->shuffleanswers}</shuffleanswers>\n";
 
         // output depends on question type
         switch($question->qtype) {