From 484c3c70f733eedf28e63502eb431c3f5808cbe9 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Sun, 20 Nov 2011 11:49:41 +0000 Subject: [PATCH] MDL-29060 q export: writefiles should be public write_files & belongs to XML format. Conflicts: question/format/xml/format.php --- question/format.php | 22 ----------------- question/format/xml/format.php | 45 +++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/question/format.php b/question/format.php index dc3db4aadce..081b68b36a3 100644 --- a/question/format.php +++ b/question/format.php @@ -876,26 +876,4 @@ class qformat_default { return html_to_text(format_text($question->questiontext, $question->questiontextformat, $formatoptions), 0, false); } - - /** - * convert files into text output in the given format. - * @param array - * @param string encoding method - * @return string $string - */ - protected function writefiles($files, $encoding='base64') { - if (empty($files)) { - return ''; - } - $string = ''; - foreach ($files as $file) { - if ($file->is_directory()) { - continue; - } - $string .= ''; - $string .= base64_encode($file->get_content()); - $string .= ''; - } - return $string; - } } diff --git a/question/format/xml/format.php b/question/format/xml/format.php index c7a768cb7ef..9f2c1130d9a 100644 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -1051,6 +1051,27 @@ class qformat_xml extends qformat_default { return $xml; } + /** + * Generte the XML to represent some files. + * @param array of store array of stored_file objects. + * @return string $string the XML. + */ + public function write_files($files) { + if (empty($files)) { + return ''; + } + $string = ''; + foreach ($files as $file) { + if ($file->is_directory()) { + continue; + } + $string .= ''; + $string .= base64_encode($file->get_content()); + $string .= ''; + } + return $string; + } + protected function presave_process($content) { // Override to allow us to add xml headers and footers return ' @@ -1110,11 +1131,11 @@ class qformat_xml extends qformat_default { $expout .= " \n"; $expout .= " format($question->questiontextformat)}>\n"; $expout .= $this->writetext($question->questiontext, 3); - $expout .= $this->writefiles($question->questiontextfiles); + $expout .= $this->write_files($question->questiontextfiles); $expout .= " \n"; $expout .= " format($question->generalfeedbackformat)}>\n"; $expout .= $this->writetext($question->generalfeedback, 3); - $expout .= $this->writefiles($question->generalfeedbackfiles); + $expout .= $this->write_files($question->generalfeedbackfiles); $expout .= " \n"; if ($question->qtype != 'multianswer') { $expout .= " {$question->defaultmark}\n"; @@ -1191,7 +1212,7 @@ class qformat_xml extends qformat_default { $expout .= " format($question->options->instructionsformat) . ">\n"; $expout .= $this->writetext($question->options->instructions, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; } break; @@ -1207,7 +1228,7 @@ class qformat_xml extends qformat_default { $expout .= " format($subquestion->questiontextformat) . ">\n"; $expout .= $this->writetext($subquestion->questiontext, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; $expout .= $this->writetext($subquestion->answertext, 4); $expout .= " \n"; @@ -1235,7 +1256,7 @@ class qformat_xml extends qformat_default { $expout .= " format($question->options->graderinfoformat) . ">\n"; $expout .= $this->writetext($question->options->graderinfo, 3); - $expout .= $this->writefiles($fs->get_area_files($contextid, 'qtype_essay', + $expout .= $this->write_files($fs->get_area_files($contextid, 'qtype_essay', 'graderinfo', $question->id)); $expout .= " \n"; break; @@ -1255,21 +1276,21 @@ class qformat_xml extends qformat_default { 'correctfeedback', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->correctfeedback, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; $files = $fs->get_area_files($contextid, $component, 'partiallycorrectfeedback', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->partiallycorrectfeedback, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; $files = $fs->get_area_files($contextid, $component, 'incorrectfeedback', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->incorrectfeedback, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; foreach ($question->options->answers as $answer) { @@ -1287,7 +1308,7 @@ class qformat_xml extends qformat_default { $files = $fs->get_area_files($contextid, $component, 'instruction', $question->id); $expout .= $this->writetext($answer->feedback); - $expout .= $this->writefiles($answer->feedbackfiles); + $expout .= $this->write_files($answer->feedbackfiles); $expout .= " \n"; $expout .= "\n"; } @@ -1312,7 +1333,7 @@ class qformat_xml extends qformat_default { $expout .= " format($question->options->instructionsformat) . ">\n"; $expout .= $this->writetext($question->options->instructions, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; } @@ -1418,10 +1439,10 @@ class qformat_xml extends qformat_default { $output = ''; $output .= " format($answer->answerformat)}>\n"; $output .= $this->writetext($answer->answer, 3); - $output .= $this->writefiles($answer->answerfiles); + $output .= $this->write_files($answer->answerfiles); $output .= " format($answer->feedbackformat)}>\n"; $output .= $this->writetext($answer->feedback, 4); - $output .= $this->writefiles($answer->feedbackfiles); + $output .= $this->write_files($answer->feedbackfiles); $output .= " \n"; $output .= $extra; $output .= " \n";