From: skodak Date: Wed, 4 Jul 2007 16:16:39 +0000 (+0000) Subject: MDL-10210 new parameter in grade_tree constructor to force category grade item as... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=225e707187a09402fdb74db303f42de15c5791d0;p=moodle.git MDL-10210 new parameter in grade_tree constructor to force category grade item as last child --- diff --git a/lib/grade/grade_tree.php b/lib/grade/grade_tree.php index 593b01995d..94ecd406b1 100644 --- a/lib/grade/grade_tree.php +++ b/lib/grade/grade_tree.php @@ -64,8 +64,9 @@ class grade_tree { * @param boolean $fillers include fillers and colspans, make the levels var "rectabgular" * @param boolean $include_grades * @param boolean $include_cagegory_items inclute the items for categories in the tree + * ¶m boolean $category_grade_last category grade item is the last child */ - function grade_tree($courseid, $fillers=true, $include_grades=false) { + function grade_tree($courseid, $fillers=true, $include_grades=false, $category_grade_last=false) { global $USER; $this->courseid = $courseid; @@ -76,6 +77,10 @@ class grade_tree { // get course grade tree $this->top_element =& grade_category::fetch_course_tree($courseid, $include_grades, true); + if ($category_grade_last) { + grade_tree::category_grade_last($this->top_element); + } + if ($fillers) { // inject fake categories == fillers grade_tree::inject_fillers($this->top_element, 0); @@ -87,6 +92,25 @@ class grade_tree { } + /** + * Static recursive helper - makes the grade_item for category the last children + */ + function category_grade_last(&$element) { + if (empty($element['children'])) { + return; + } + if (count($element['children']) < 2) { + return; + } + $category_item = reset($element['children']); + $order = key($element['children']); + unset($element['children'][$order]); + $element['children'][$order] =& $category_item; + foreach ($element['children'] as $sortorder=>$child) { + grade_tree::category_grade_last($element['children'][$sortorder]); + } + } + /** * Static recursive helper - fills the levels array, useful when accessing tree elements of one level */