MDL-20184 more efficient and accurate detection of missing nodes in xml tree when importing Hot Potatoes XML files to Moodle question bank / quiz module

This commit is contained in:
gbateson
2009-09-01 01:04:18 +00:00
parent aeb4bd9ce5
commit 10369c9c5b
+35 -5
View File
@@ -222,10 +222,19 @@ class qformat_hotpot extends qformat_default {
$q++;
} // end while $text
// define total grade for this exercise
$question->defaultgrade = $gap_count * $defaultgrade;
if ($q) {
// define total grade for this exercise
$question->defaultgrade = $gap_count * $defaultgrade;
// add this cloze as a single question object
$questions[] = $question;
} else {
// no gaps found in this text so don't add this question
// import will fail and error message will be displayed:
// "There are no questions in the import file"
unset($question);
}
$questions[] = $question;
$x++;
} // end while $exercise
}
@@ -553,8 +562,29 @@ class hotpot_xml_tree {
}
function xml_value($tags, $more_tags="[0]['#']") {
$tags = empty($tags) ? '' : "['".str_replace(",", "'][0]['#']['", $tags)."']";
eval('$value = &$this->xml'.$this->xml_root.$tags.$more_tags.';');
$value = null;
if (isset($this->xml) && is_array($this->xml)) {
$all_tags = $this->xml_root;
if ($tags) {
$all_tags .= "['".str_replace(",", "'][0]['#']['", $tags)."']";
}
$all_tags .= $more_tags;
$pos = strrpos($all_tags, '[');
if ($pos===false) {
$most_tags = ''; // shouldn't happen !!
} else {
$most_tags = substr($all_tags, 0, $pos);
}
eval('if (isset($this->xml'.$most_tags.') && is_array($this->xml'.$most_tags.') && isset($this->xml'.$all_tags.')) {'
.'$value = &$this->xml'.$all_tags.';'
.'} else {'
.'$value = null;'
.'}'
);
}
if (is_string($value)) {