From: thepurpleblob Date: Thu, 23 Mar 2006 11:13:50 +0000 (+0000) Subject: Added support for matching questions. Bug #3901 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=51bcdf28b302e863a7109ad6b9a0dcf47161b94a;p=moodle.git Added support for matching questions. Bug #3901 --- diff --git a/question/format/xml/format.php b/question/format/xml/format.php index bbeaceaa3e..e3b94ebdf0 100755 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -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 "
"; 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 "

$notsupported

"; @@ -492,6 +521,7 @@ class qformat_xml extends qformat_default { $expout .= " ".$question->image."\n"; $expout .= " {$question->penalty}\n"; $expout .= " {$question->hidden}\n"; + $expout .= " {$question->options->shuffleanswers}\n"; // output depends on question type switch($question->qtype) {