From d75bc0b272db06ec112c68f2e05f595358dbdd31 Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Fri, 24 Dec 2004 11:16:43 +0000 Subject: [PATCH] Now supports shortanswer import. Cleaned up the CDATA import too. --- mod/quiz/format/xml/format.php | 41 ++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/mod/quiz/format/xml/format.php b/mod/quiz/format/xml/format.php index 5971397a2e..dff3d3867c 100755 --- a/mod/quiz/format/xml/format.php +++ b/mod/quiz/format/xml/format.php @@ -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 "

Question type $question_type not currently supported for xml import

"; $qo = null; @@ -449,10 +474,12 @@ function writequestion( $question ) { case SHORTANSWER: foreach($question->answers as $answer) { $percent = 100 * $answer->fraction; - $expout .= "\n"; - $expout .= $this->writetext( $answer->answer ); - $expout .= "".$this->writetext( $answer->feedback )."\n"; - $expout .= "\n"; + $expout .= " \n"; + $expout .= $this->writetext( $answer->answer,3,false ); + $expout .= " \n"; + $expout .= $this->writetext( $answer->feedback,4,false ); + $expout .= " \n"; + $expout .= " \n"; } break; case NUMERICAL: -- 2.39.5