From 55c548682f33b7155d95b879d3172abe37b8d258 Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Mon, 12 Mar 2007 16:32:52 +0000 Subject: [PATCH] MDL-8857 Make numerical and essay question formats more consistent. --- question/format/xml/format.php | 46 ++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/question/format/xml/format.php b/question/format/xml/format.php index de91b20bd5..86a298f29a 100755 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -244,7 +244,7 @@ class qformat_xml extends qformat_default { if ($warning) { $a = new stdClass; - $a->questiontext = stripslashes($qo->questiontext); + $a->questiontext = $qo->questiontext; $a->answer = get_string($qo->answer ? 'true' : 'false', 'quiz'); notify(get_string('truefalseimporterror', 'quiz', $a)); } @@ -342,15 +342,28 @@ class qformat_xml extends qformat_default { $qo->fraction = array(); $qo->tolerance = array(); foreach ($answers as $answer) { - $answertext = trim($answer['#'][0]); + // answer outside of is deprecated + if (!empty( $answer['#']['text'] )) { + $answertext = $this->import_text( $answer['#']['text'] ); + } + else { + $answertext = trim($answer['#'][0]); + } if ($answertext == '') { $qo->answer[] = '*'; } else { $qo->answer[] = $answertext; } $qo->feedback[] = $this->import_text( $answer['#']['feedback'][0]['#']['text'] ); - $qo->fraction[] = $answer['#']['fraction'][0]['#']; $qo->tolerance[] = $answer['#']['tolerance'][0]['#']; + + // fraction as a tag is deprecated + if (!empty($answer['#']['fraction'][0]['#'])) { + $qo->fraction[] = $answer['#']['fraction'][0]['#']; + } + else { + $qo->fraction[] = $answer['@']['fraction'] / 100; + } } // get units array @@ -413,8 +426,16 @@ class qformat_xml extends qformat_default { // get feedback $qo->feedback = $this->import_text( $question['#']['answer'][0]['#']['feedback'][0]['#']['text'] ); - // get fraction - $qo->fraction = $question['#']['answer'][0]['#']['fraction'][0]['#']; + // handle answer + $answer = $question['#']['answer'][0]; + + // get fraction - tag is deprecated + if (!empty($answer['#']['fraction'][0]['#'])) { + $qo->fraction = $answer['#']['fraction'][0]['#']; + } + else { + $qo->fraction = $answer['@']['fraction'] / 100; + } return $qo; } @@ -783,11 +804,14 @@ class qformat_xml extends qformat_default { case NUMERICAL: foreach ($question->options->answers as $answer) { $tolerance = $answer->tolerance; - $expout .= "\n"; - $expout .= " {$answer->answer}\n"; + $percent = 100 * $answer->fraction; + $expout .= "\n"; + // tags are an added feature, old filed won't have them + $expout .= " {$answer->answer}\n"; $expout .= " $tolerance\n"; $expout .= " ".$this->writetext( $answer->feedback )."\n"; - $expout .= " {$answer->fraction}\n"; + // fraction tag is deprecated + // $expout .= " {$answer->fraction}\n"; $expout .= "\n"; } @@ -825,9 +849,11 @@ class qformat_xml extends qformat_default { break; case ESSAY: foreach ($question->options->answers as $answer) { - $expout .= "\n"; + $percent = 100 * $answer->fraction; + $expout .= "\n"; $expout .= " ".$this->writetext( $answer->feedback )."\n"; - $expout .= " {$answer->fraction}\n"; + // fraction tag is deprecated + // $expout .= " {$answer->fraction}\n"; $expout .= "\n"; } -- 2.39.5