Gradebook preference/user report problems

Gradebook formatting problem when categories hidden - FIXED

by Steve Copley -
Number of replies: 0
Hi

I have a solution to this issue.

You need to edit a core Moodle file, but it's an easy patch...

  1. Open Moodle --> grade --> report --> user --> lib.php
  2. Find the function inject_rowspans() around line 128
  3. Add the following lines at the start of this function (just below the function name):
        $type = $element['type'];
        $grade_object = $element['object'];
    
        // If this is a hidden grade category, do not increase the parent rowspan - return 0
        if ($type == 'category' && $grade_object->is_hidden() && !$this->canviewhidden && 
            ($this->showhiddenitems == 0 || 
            ($this->showhiddenitems == 1 && !$grade_object->is_hiddenuntil()))) {
            return 0;
        }
    

This should mean that your inject_rowspans() function should look like:

    function inject_rowspans(&$element) {

        $type = $element['type'];
        $grade_object = $element['object'];

        // If this is a hidden grade category, do not increase the parent rowspan - return 0
        if ($type == 'category' && $grade_object->is_hidden() && !$this->canviewhidden && 
            ($this->showhiddenitems == 0 || 
            ($this->showhiddenitems == 1 && !$grade_object->is_hiddenuntil()))) {
            return 0;
        }

        if ($element['depth'] > $this->maxdepth) {
            $this->maxdepth = $element['depth'];
        }
        if (empty($element['children'])) {
            return 1;
        }
        $count = 1;
        foreach ($element['children'] as $key=>$child) {
            $count += $this->inject_rowspans($element['children'][$key]);
        }
        $element['rowspan'] = $count;
        return $count;
    }

I hope that fixes things for you all. I've added a bug to the Tracker along with this fix.

All the best

Steve C.