protected static function get_collapsed_preferences($courseid) {
        if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories'.$courseid)) {
            return json_decode($collapsed, true);
        }

        // Try looking for old location of user setting that used to store all courses in one serialized user preference.
        if (($oldcollapsedpref = get_user_preferences('grade_report_grader_collapsed_categories')) !== null) {
            if ($collapsedall = unserialize_array($oldcollapsedpref)) {
                // We found the old-style preference, filter out only categories that belong to this course and update the prefs.
                $collapsed = static::filter_collapsed_categories($courseid, $collapsedall);
                if (!empty($collapsed['aggregatesonly']) || !empty($collapsed['gradesonly'])) {
                    static::set_collapsed_preferences($courseid, $collapsed);
                    $collapsedall['aggregatesonly'] = array_diff($collapsedall['aggregatesonly'], $collapsed['aggregatesonly']);
                    $collapsedall['gradesonly'] = array_diff($collapsedall['gradesonly'], $collapsed['gradesonly']);
                    if (!empty($collapsedall['aggregatesonly']) || !empty($collapsedall['gradesonly'])) {
                        set_user_preference('grade_report_grader_collapsed_categories', serialize($collapsedall));
                    } else {
                        unset_user_preference('grade_report_grader_collapsed_categories');
                    }
                }
            } else {
                // We found the old-style preference, but it is unreadable, discard it.
                unset_user_preference('grade_report_grader_collapsed_categories');
            }
        } else {
            $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array());
        }
        return $collapsed;
    }