]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20184 more efficient and accurate detection of missing nodes in xml tree when...
authorgbateson <gbateson>
Tue, 1 Sep 2009 01:05:41 +0000 (01:05 +0000)
committergbateson <gbateson>
Tue, 1 Sep 2009 01:05:41 +0000 (01:05 +0000)
question/format/hotpot/format.php

index 83f0a5bd50990a75fe039aa40f54e1064bbf9e66..8464ccfb5b6cf6682488602b64c990d68b9cda10 100644 (file)
@@ -522,8 +522,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)) {