From 75e496f73d7624ca24c1b1cc4aa1eaf568ac0e86 Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Mon, 20 Dec 2004 14:34:07 +0000 Subject: [PATCH] Fixed a couple of bugs in the xml formatting. Issue with Markdown text still to resolve. --- mod/quiz/format/xml/format.php | 62 +++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/mod/quiz/format/xml/format.php b/mod/quiz/format/xml/format.php index 0172323e97..5971397a2e 100755 --- a/mod/quiz/format/xml/format.php +++ b/mod/quiz/format/xml/format.php @@ -110,7 +110,7 @@ function import_multichoice( $question ) { // run through the answers // $qo->answer = array(); - $answers = $question['#']['answers'][0]['#']['answer']; + $answers = $question['#']['answer']; $a_count = 0; foreach ($answers as $answer) { $ans = $this->import_answer( $answer ); @@ -360,13 +360,23 @@ function get_single( $id ) { return $name; } -function writetext( $raw ) { +function writetext( $raw, $ilev=0, $short=true) { // generates tags, processing raw text therein + // $ilev is the current indent level + // $short=true sticks it on one line + $indent = str_repeat( " ",$ilev ); // encode the text to 'disguise' HTML content $raw = htmlspecialchars( $raw ); - return "$raw\n"; + if ($short) { + $xml = "$indent$raw\n"; + } + else { + $xml = "$indent\n$raw\n$indent\n"; + } + + return $xml; } function presave_process( $content ) { @@ -395,10 +405,12 @@ function writequestion( $question ) { $name_text = $this->writetext( $question->name ); $qtformat = $this->get_format($question->questiontextformat); $question_text = $this->writetext( $question->questiontext ); - $expout .= "\n"; - $expout .= "".$this->writetext($name_text)."\n"; - $expout .= "".$this->writetext($question_text)."\n"; - $expout .= "".$question->image."\n"; + $expout .= " \n"; + $expout .= " $name_text\n"; + $expout .= " \n"; + $expout .= $question_text; + $expout .= " \n"; + $expout .= " ".$question->image."\n"; // output depends on question type switch($question->qtype) { @@ -406,29 +418,33 @@ function writequestion( $question ) { $true_percent = round( $question->trueanswer->fraction * 100 ); $false_percent = round( $question->falseanswer->fraction * 100 ); // true answer - $expout .= "\n"; - $expout .= $this->writetext("true")."\n"; - $expout .= "".$this->writetext( $question->trueanswer->feedback )."\n"; - $expout .= "\n"; + $expout .= " \n"; + $expout .= $this->writetext("true",3)."\n"; + $expout .= " \n"; + $expout .= $this->writetext( $question->trueanswer->feedback,4,false ); + $expout .= " \n"; + $expout .= " \n"; // false answer - $expout .= "\n"; + $expout .= " \n"; $expout .= $this->writetext("false")."\n"; - $expout .= "".$this->writetext( $question->falseanswer->feedback )."\n"; - $expout .= "\n"; + $expout .= " \n"; + $expout .= $this->writetext( $question->falseanswer->feedback,4,false ); + $expout .= " \n"; + $expout .= " \n"; break; case MULTICHOICE: - $expout .= "".$this->get_single($question->single)."\n"; - $expout .= "\n"; + $expout .= " ".$this->get_single($question->single)."\n"; foreach($question->answers as $answer) { $percent = $answer->fraction * 100; - $expout .= "\n"; - $expout .= $this->writetext( $answer->answer ); - $expout .= "".$this->writetext( $answer->feedback )."\n"; - $expout .= "\n"; + $expout .= " \n"; + $expout .= $this->writetext( $answer->answer,4,false ); + $expout .= " \n"; + $expout .= $this->writetext( $answer->feedback,4,false ); + $expout .= " \n"; + $expout .= " \n"; } - $expout .= "\n"; break; case SHORTANSWER: foreach($question->answers as $answer) { @@ -465,9 +481,9 @@ function writequestion( $question ) { $expout .= "\n"; // run through xml tidy function - $tidy_expout = $this->indent_xhtml( $expout, ' ' ) . "\n\n"; + // $tidy_expout = $this->indent_xhtml( $expout, ' ' ) . "\n\n"; - return $tidy_expout; + return $expout; } } -- 2.39.5