mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-38880' of git://github.com/jmvedrine/moodle
This commit is contained in:
commit
9aae7551ec
3 changed files with 144 additions and 15 deletions
|
@ -448,37 +448,43 @@ class qformat_xml extends qformat_default {
|
|||
* @return object question object
|
||||
*/
|
||||
public function import_multianswer($question) {
|
||||
global $USER;
|
||||
question_bank::get_qtype('multianswer');
|
||||
|
||||
$questiontext['text'] = $this->import_text($question['#']['questiontext'][0]['#']['text']);
|
||||
$questiontext['format'] = FORMAT_HTML;
|
||||
$questiontext['itemid'] = '';
|
||||
$questiontext = $this->import_text_with_files($question,
|
||||
array('#', 'questiontext', 0));
|
||||
$qo = qtype_multianswer_extract_question($questiontext);
|
||||
|
||||
// 'header' parts particular to multianswer
|
||||
$qo->qtype = 'multianswer';
|
||||
$qo->course = $this->course;
|
||||
$qo->generalfeedback = '';
|
||||
|
||||
$qo->name = $this->clean_question_name($this->import_text($question['#']['name'][0]['#']['text']));
|
||||
$qo->questiontextformat = $questiontext['format'];
|
||||
$qo->questiontext = $qo->questiontext['text'];
|
||||
$itemid = $this->import_files($this->getpath($question,
|
||||
array('#', 'questiontext', 0, '#', 'file'), array(), false));
|
||||
if (!empty($itemid)) {
|
||||
$qo->questiontextitemid = $itemid;
|
||||
if (!empty($questiontext['itemid'])) {
|
||||
$qo->questiontextitemid = $questiontext['itemid'];
|
||||
}
|
||||
|
||||
// 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';
|
||||
// Question file areas don't support subdirs, so convert path to filename if necessary.
|
||||
$data->name = clean_param(str_replace('/', '_', $filename), PARAM_FILE);
|
||||
$qo->questiontextfiles[] = $data;
|
||||
$qo->questiontext .= ' <img src="@@PLUGINFILE@@/' . $data->name . '" />';
|
||||
$fs = get_file_storage();
|
||||
if (empty($qo->questiontextitemid)) {
|
||||
$qo->questiontextitemid = file_get_unused_draft_itemid();
|
||||
}
|
||||
$filename = clean_param(str_replace('/', '_', $filename), PARAM_FILE);
|
||||
$filerecord = array(
|
||||
'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
|
||||
|
|
27
question/format/xml/tests/fixtures/multianswer.xml
vendored
Normal file
27
question/format/xml/tests/fixtures/multianswer.xml
vendored
Normal file
File diff suppressed because one or more lines are too long
96
question/format/xml/tests/fixtures/sample_questions_with_old_image_tag.xml
vendored
Normal file
96
question/format/xml/tests/fixtures/sample_questions_with_old_image_tag.xml
vendored
Normal 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 "image" 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 "image" 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>
|
Loading…
Add table
Add a link
Reference in a new issue