Merge branch 'MDL-38880' of git://github.com/jmvedrine/moodle

This commit is contained in:
Dan Poltawski 2013-04-15 16:25:06 +01:00
commit 9aae7551ec
3 changed files with 144 additions and 15 deletions

View file

@ -448,37 +448,43 @@ class qformat_xml extends qformat_default {
* @return object question object * @return object question object
*/ */
public function import_multianswer($question) { public function import_multianswer($question) {
global $USER;
question_bank::get_qtype('multianswer'); question_bank::get_qtype('multianswer');
$questiontext['text'] = $this->import_text($question['#']['questiontext'][0]['#']['text']); $questiontext = $this->import_text_with_files($question,
$questiontext['format'] = FORMAT_HTML; array('#', 'questiontext', 0));
$questiontext['itemid'] = '';
$qo = qtype_multianswer_extract_question($questiontext); $qo = qtype_multianswer_extract_question($questiontext);
// 'header' parts particular to multianswer // 'header' parts particular to multianswer
$qo->qtype = 'multianswer'; $qo->qtype = 'multianswer';
$qo->course = $this->course; $qo->course = $this->course;
$qo->generalfeedback = '';
$qo->name = $this->clean_question_name($this->import_text($question['#']['name'][0]['#']['text'])); $qo->name = $this->clean_question_name($this->import_text($question['#']['name'][0]['#']['text']));
$qo->questiontextformat = $questiontext['format']; $qo->questiontextformat = $questiontext['format'];
$qo->questiontext = $qo->questiontext['text']; $qo->questiontext = $qo->questiontext['text'];
$itemid = $this->import_files($this->getpath($question, if (!empty($questiontext['itemid'])) {
array('#', 'questiontext', 0, '#', 'file'), array(), false)); $qo->questiontextitemid = $questiontext['itemid'];
if (!empty($itemid)) {
$qo->questiontextitemid = $itemid;
} }
// Backwards compatibility, deal with the old image tag. // Backwards compatibility, deal with the old image tag.
$filedata = $this->getpath($question, array('#', 'image_base64', '0', '#'), null, false); $filedata = $this->getpath($question, array('#', 'image_base64', '0', '#'), null, false);
$filename = $this->getpath($question, array('#', 'image', '0', '#'), null, false); $filename = $this->getpath($question, array('#', 'image', '0', '#'), null, false);
if ($filedata && $filename) { if ($filedata && $filename) {
$data = new stdClass(); $fs = get_file_storage();
$data->content = $filedata; if (empty($qo->questiontextitemid)) {
$data->encoding = 'base64'; $qo->questiontextitemid = file_get_unused_draft_itemid();
// Question file areas don't support subdirs, so convert path to filename if necessary. }
$data->name = clean_param(str_replace('/', '_', $filename), PARAM_FILE); $filename = clean_param(str_replace('/', '_', $filename), PARAM_FILE);
$qo->questiontextfiles[] = $data; $filerecord = array(
$qo->questiontext .= ' <img src="@@PLUGINFILE@@/' . $data->name . '" />'; 'contextid' => context_user::instance($USER->id)->id,
'component' => 'user',
'filearea' => 'draft',
'itemid' => $qo->questiontextitemid,
'filepath' => '/',
'filename' => $filename,
);
$fs->create_file_from_string($filerecord, base64_decode($filedata));
$qo->questiontext .= ' <img src="@@PLUGINFILE@@/' . $filename . '" />';
} }
// restore files in generalfeedback // restore files in generalfeedback

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Default for Test images in backup</text>
</category>
</question>
<!-- question: 5 -->
<question type="cloze">
<name><text>cloze question with image</text>
</name>
<questiontext>
<text><![CDATA[This is a multianswer question with an image in the old &quot;image&quot; field that was used in moodle 1.9.<br />Match the following cities with the correct state:<br />* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}<br />* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}<br />* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}<br />* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}<br />The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!<br />~%50%Marseille#No, that is the second largest city in France (after<br />Paris).~*#Wrong answer. The capital of France is Paris, of course.}.<br />]]></text>
</questiontext>
<image>moodle.png</image>
<image_base64>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAHzSURBVDhPxZFbSJNhGIDXERsVGbKawWJaoyAYGeqNYgdl6zenrhhUlB0I6iJEbUl0WF1UUK2DYhDkGghu7Z+HraisPLAsu+0ygi66kCioqwg2t6f///YhzAVBXfTc/HzP9/J8L/wG/pG8QDw+TE+Xn/O+dva07MW5vZayys3yNp/ZwPPRBPuOHqGisordDc00Ki42bqhAjQ3Jid8jAvoL9vIt4qs463G73VRtrcFiseDvuSYG+TwB7y/zfdzHpzeDWachAjeuXyWkPqZ21zZ2Nrioa/JQarOjlK8jes7Eh/s18GwHRMxkgka+3lvEi1ubcgM63Zea6W5v5ESLB4fDwRVvNam+eRBey3TAxqObNl76rXwLFvAlsIyhC2W5gZ+JJmYixQS9q8RZZzpghwEr/R2LpYGPIYWZqJnYSWNugCkPPDDx1JddTyeZqCetasMdS6WB9OQB7Xet5kmbITeQntoP/YWEfSZxFoy5SA2YCXeukAJ+vD5MMl7Cw9YF2UAkGhIXmYSbZLgI9WKxOOukx52kVAvq6eXS6HOHyAyuRz0lN5hlwg19hcTOWqXQ0FxaXZPnGC4V7s+BsToRUM8YpdA2eHswG/DO2eDV7WpGWg30dpZIA5Nddkba5nP3+Epp4F2vwqh3CXeOLZyzwV/wvwPwC58bSNEdAkhaAAAAAElFTkSuQmCC
</image_base64>
<generalfeedback>
<text></text>
</generalfeedback>
<shuffleanswers>0</shuffleanswers>
</question>
<!-- question: 4 -->
<question type="multichoice">
<name><text>mcq with image</text>
</name>
<questiontext format="html">
<text><![CDATA[This is a multichoice question with an image in the old &quot;image&quot; field that was used in Moodle 1.9]]></text>
</questiontext>
<image>moodle.png</image>
<image_base64>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAHzSURBVDhPxZFbSJNhGIDXERsVGbKawWJaoyAYGeqNYgdl6zenrhhUlB0I6iJEbUl0WF1UUK2DYhDkGghu7Z+HraisPLAsu+0ygi66kCioqwg2t6f///YhzAVBXfTc/HzP9/J8L/wG/pG8QDw+TE+Xn/O+dva07MW5vZayys3yNp/ZwPPRBPuOHqGisordDc00Ki42bqhAjQ3Jid8jAvoL9vIt4qs463G73VRtrcFiseDvuSYG+TwB7y/zfdzHpzeDWachAjeuXyWkPqZ21zZ2Nrioa/JQarOjlK8jes7Eh/s18GwHRMxkgka+3lvEi1ubcgM63Zea6W5v5ESLB4fDwRVvNam+eRBey3TAxqObNl76rXwLFvAlsIyhC2W5gZ+JJmYixQS9q8RZZzpghwEr/R2LpYGPIYWZqJnYSWNugCkPPDDx1JddTyeZqCetasMdS6WB9OQB7Xet5kmbITeQntoP/YWEfSZxFoy5SA2YCXeukAJ+vD5MMl7Cw9YF2UAkGhIXmYSbZLgI9WKxOOukx52kVAvq6eXS6HOHyAyuRz0lN5hlwg19hcTOWqXQ0FxaXZPnGC4V7s+BsToRUM8YpdA2eHswG/DO2eDV7WpGWg30dpZIA5Nddkba5nP3+Epp4F2vwqh3CXeOLZyzwV/wvwPwC58bSNEdAkhaAAAAAElFTkSuQmCC
</image_base64>
<generalfeedback>
<text></text>
</generalfeedback>
<defaultgrade>1</defaultgrade>
<penalty>0.1</penalty>
<hidden>0</hidden>
<shuffleanswers>1</shuffleanswers>
<single>true</single>
<shuffleanswers>true</shuffleanswers>
<correctfeedback> <text></text>
</correctfeedback>
<partiallycorrectfeedback> <text></text>
</partiallycorrectfeedback>
<incorrectfeedback> <text></text>
</incorrectfeedback>
<answernumbering>abc</answernumbering>
<answer fraction="0">
<text>
wrong answer
</text>
<feedback>
<text>
</text>
</feedback>
</answer>
<answer fraction="0">
<text>
another wrong answer
</text>
<feedback>
<text>
</text>
</feedback>
</answer>
<answer fraction="100">
<text>
right answer
</text>
<feedback>
<text>
</text>
</feedback>
</answer>
</question>
</quiz>