MDL-50642 qformat_xml: fix import of tags in Cloze questions

This commit is contained in:
Eoin Campbell 2015-08-05 19:11:11 +01:00
parent 032a4fe51c
commit dcd4464ea3
2 changed files with 51 additions and 9 deletions

View file

@ -198,7 +198,7 @@ class qformat_xml extends qformat_default {
* @return object question object
*/
public function import_headers($question) {
global $CFG, $USER;
global $USER;
// This routine initialises the question object.
$qo = $this->defaultquestion();
@ -255,14 +255,7 @@ class qformat_xml extends qformat_default {
}
// Read the question tags.
if (!empty($CFG->usetags) && array_key_exists('tags', $question['#'])
&& !empty($question['#']['tags'][0]['#']['tag'])) {
require_once($CFG->dirroot.'/tag/lib.php');
$qo->tags = array();
foreach ($question['#']['tags'][0]['#']['tag'] as $tagdata) {
$qo->tags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true);
}
}
$this->import_question_tags($qo, $question);
return $qo;
}
@ -380,6 +373,26 @@ class qformat_xml extends qformat_default {
}
}
/**
* Import all the question tags
*
* @param object $qo the question data that is being constructed.
* @param array $questionxml The xml representing the question.
* @return array of objects representing the tags in the file.
*/
public function import_question_tags($qo, $questionxml) {
global $CFG;
if (!empty($CFG->usetags) && array_key_exists('tags', $questionxml['#'])
&& !empty($questionxml['#']['tags'][0]['#']['tag'])) {
require_once($CFG->dirroot.'/tag/lib.php');
$qo->tags = array();
foreach ($questionxml['#']['tags'][0]['#']['tag'] as $tagdata) {
$qo->tags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true);
}
}
}
/**
* Import files from a node in the XML.
* @param array $xml an array of <file> nodes from the the parsed XML.
@ -505,6 +518,7 @@ class qformat_xml extends qformat_default {
}
$this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat));
$this->import_question_tags($qo, $question);
return $qo;
}