Skip to content
Browse files

Merge branch 'MDL-29060_21' of git://github.com/timhunt/moodle into M…

…OODLE_21_STABLE
  • Loading branch information...
2 parents 8ed1782 + 484c3c7 commit 9e2c51dbf2b38d8a6fc0d2ec16f8a17154e0d8b1 @stronk7 stronk7 committed Nov 23, 2011
Showing with 33 additions and 34 deletions.
  1. +0 −22 question/format.php
  2. +33 −12 question/format/xml/format.php
View
22 question/format.php
@@ -876,26 +876,4 @@ protected function format_question_text($question) {
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 .= '<file name="' . $file->get_filename() . '" encoding="' . $encoding . '">';
- $string .= base64_encode($file->get_content());
- $string .= '</file>';
- }
- return $string;
- }
}
View
45 question/format/xml/format.php
@@ -1051,6 +1051,27 @@ public function writetext($raw, $indent = 0, $short = true) {
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 .= '<file name="' . $file->get_filename() . '" encoding="base64">';
+ $string .= base64_encode($file->get_content());
+ $string .= '</file>';
+ }
+ return $string;
+ }
+
protected function presave_process($content) {
// Override to allow us to add xml headers and footers
return '<?xml version="1.0" encoding="UTF-8"?>
@@ -1110,11 +1131,11 @@ public function writequestion($question) {
$expout .= " </name>\n";
$expout .= " <questiontext {$this->format($question->questiontextformat)}>\n";
$expout .= $this->writetext($question->questiontext, 3);
- $expout .= $this->writefiles($question->questiontextfiles);
+ $expout .= $this->write_files($question->questiontextfiles);
$expout .= " </questiontext>\n";
$expout .= " <generalfeedback {$this->format($question->generalfeedbackformat)}>\n";
$expout .= $this->writetext($question->generalfeedback, 3);
- $expout .= $this->writefiles($question->generalfeedbackfiles);
+ $expout .= $this->write_files($question->generalfeedbackfiles);
$expout .= " </generalfeedback>\n";
if ($question->qtype != 'multianswer') {
$expout .= " <defaultgrade>{$question->defaultmark}</defaultgrade>\n";
@@ -1191,7 +1212,7 @@ public function writequestion($question) {
$expout .= " <instructions " .
$this->format($question->options->instructionsformat) . ">\n";
$expout .= $this->writetext($question->options->instructions, 3);
- $expout .= $this->writefiles($files);
+ $expout .= $this->write_files($files);
$expout .= " </instructions>\n";
}
break;
@@ -1207,7 +1228,7 @@ public function writequestion($question) {
$expout .= " <subquestion " .
$this->format($subquestion->questiontextformat) . ">\n";
$expout .= $this->writetext($subquestion->questiontext, 3);
- $expout .= $this->writefiles($files);
+ $expout .= $this->write_files($files);
$expout .= " <answer>\n";
$expout .= $this->writetext($subquestion->answertext, 4);
$expout .= " </answer>\n";
@@ -1235,7 +1256,7 @@ public function writequestion($question) {
$expout .= " <graderinfo " .
$this->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 .= " </graderinfo>\n";
break;
@@ -1255,21 +1276,21 @@ public function writequestion($question) {
'correctfeedback', $question->id);
$expout .= " <correctfeedback>\n";
$expout .= $this->writetext($question->options->correctfeedback, 3);
- $expout .= $this->writefiles($files);
+ $expout .= $this->write_files($files);
$expout .= " </correctfeedback>\n";
$files = $fs->get_area_files($contextid, $component,
'partiallycorrectfeedback', $question->id);
$expout .= " <partiallycorrectfeedback>\n";
$expout .= $this->writetext($question->options->partiallycorrectfeedback, 3);
- $expout .= $this->writefiles($files);
+ $expout .= $this->write_files($files);
$expout .= " </partiallycorrectfeedback>\n";
$files = $fs->get_area_files($contextid, $component,
'incorrectfeedback', $question->id);
$expout .= " <incorrectfeedback>\n";
$expout .= $this->writetext($question->options->incorrectfeedback, 3);
- $expout .= $this->writefiles($files);
+ $expout .= $this->write_files($files);
$expout .= " </incorrectfeedback>\n";
foreach ($question->options->answers as $answer) {
@@ -1287,7 +1308,7 @@ public function writequestion($question) {
$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 .= " </feedback>\n";
$expout .= "</answer>\n";
}
@@ -1312,7 +1333,7 @@ public function writequestion($question) {
$expout .= " <instructions " .
$this->format($question->options->instructionsformat) . ">\n";
$expout .= $this->writetext($question->options->instructions, 3);
- $expout .= $this->writefiles($files);
+ $expout .= $this->write_files($files);
$expout .= " </instructions>\n";
}
@@ -1418,10 +1439,10 @@ public function write_answer($answer, $extra = '') {
$output = '';
$output .= " <answer fraction=\"$percent\" {$this->format($answer->answerformat)}>\n";
$output .= $this->writetext($answer->answer, 3);
- $output .= $this->writefiles($answer->answerfiles);
+ $output .= $this->write_files($answer->answerfiles);
$output .= " <feedback {$this->format($answer->feedbackformat)}>\n";
$output .= $this->writetext($answer->feedback, 4);
- $output .= $this->writefiles($answer->feedbackfiles);
+ $output .= $this->write_files($answer->feedbackfiles);
$output .= " </feedback>\n";
$output .= $extra;
$output .= " </answer>\n";

0 comments on commit 9e2c51d

Please sign in to comment.
Something went wrong with that request. Please try again.