MDL-10210 new parameter in grade_tree constructor to force category grade item as last child

This commit is contained in:
skodak 2007-07-04 16:16:39 +00:00
parent 6e1d5e046c
commit 225e707187

View file

@ -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
* &param 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
*/