mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-10210 new parameter in grade_tree constructor to force category grade item as last child
This commit is contained in:
parent
6e1d5e046c
commit
225e707187
1 changed files with 25 additions and 1 deletions
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue