question XML import/export MDL-18916 Fix import of questions with images exported from Moodle 1.9.
Thanks again to Patrick Pollet
This commit is contained in:
+1
-5
@@ -880,12 +880,8 @@ class qformat_default {
|
||||
if ($file->is_directory()) {
|
||||
continue;
|
||||
}
|
||||
$string .= '<file ';
|
||||
$string .= ('name="' . $file->get_filename() . '"');
|
||||
$string .= (' encoding="' . $encoding . '"');
|
||||
$string .= '>';
|
||||
$string .= '<file name="' . $file->get_filename() . '" encoding="' . $encoding . '">';
|
||||
$string .= base64_encode($file->get_content());
|
||||
//$string .= 'base64';
|
||||
$string .= '</file>';
|
||||
}
|
||||
return $string;
|
||||
|
||||
@@ -158,11 +158,6 @@ class qformat_xml extends qformat_default {
|
||||
$qo->questiontext = $this->getpath($question, array('#','questiontext',0,'#','text',0,'#'), '', true );
|
||||
$qo->questiontextformat = $this->trans_format(
|
||||
$this->getpath($question, array('#','questiontext',0,'@','format'), 'moodle_auto_format'));
|
||||
$qo->image = $this->getpath($question, array('#','image',0,'#'), $qo->image );
|
||||
$image_base64 = $this->getpath( $question, array('#','image_base64','0','#'),'' );
|
||||
if (!empty($image_base64)) {
|
||||
$qo->image = $this->importimagefile($qo->image, $image_base64);
|
||||
}
|
||||
|
||||
$qo->questiontextfiles = array();
|
||||
|
||||
@@ -176,6 +171,18 @@ class qformat_xml extends qformat_default {
|
||||
$qo->questiontextfiles[] = $data;
|
||||
}
|
||||
|
||||
// Backwards compatibility, deal with the old image tag.
|
||||
$filedata = $this->getpath($question, array('#', 'image_base64', '0', '#'), null, false);
|
||||
$filename = $this->getpath($question, array('#', 'image', '0', '#'), null, false);
|
||||
if ($filedata && $filename) {
|
||||
$data = new stdclass;
|
||||
$data->content = $filedata;
|
||||
$data->encoding = 'base64';
|
||||
$data->name = $filename;
|
||||
$qo->questiontextfiles[] = $data;
|
||||
$qo->questiontext .= ' <img src="@@PLUGINFILE@@/' . $filename . '" />';
|
||||
}
|
||||
|
||||
// restore files in generalfeedback
|
||||
$qo->generalfeedback = $this->getpath($question, array('#','generalfeedback',0,'#','text',0,'#'), $qo->generalfeedback, true);
|
||||
$qo->generalfeedbackfiles = array();
|
||||
|
||||
Reference in New Issue
Block a user