output-custommenu MDL-25447 Fixed up the processing of the custom menu removing the...
authorSam Hemelryk <sam@moodle.com>
Thu, 2 Dec 2010 06:11:27 +0000 (06:11 +0000)
committerSam Hemelryk <sam@moodle.com>
Thu, 2 Dec 2010 06:11:27 +0000 (06:11 +0000)
lib/outputcomponents.php

index fd0dfb3..4cbd05c 100644 (file)
@@ -2342,9 +2342,13 @@ class custom_menu extends custom_menu_item {
             if (preg_match('/^(\-*)/', $line, $match) && $lastchild != null && $lastdepth !== null) {
                 $depth = strlen($match[1]);
                 if ($depth < $lastdepth) {
-                    if ($lastdepth > 1) {
-                        $depth = $lastdepth - 1;
-                        $lastchild = $lastchild->get_parent()->get_parent()->add($bits[0], $bits[1], $bits[2], $bits[3]);
+                    $difference = $lastdepth - $depth;
+                    if ($lastdepth > 1 && $lastdepth != $difference) {
+                        $tempchild = $lastchild->get_parent();
+                        for ($i =0; $i < $difference; $i++) {
+                            $tempchild = $tempchild->get_parent();
+                        }
+                        $lastchild = $tempchild->add($bits[0], $bits[1], $bits[2], $bits[3]);
                     } else {
                         $depth = 0;
                         $lastchild = new custom_menu_item($bits[0], $bits[1], $bits[2], $bits[3]);