public function get_name() {
        global $DB;
        // For a course category, we return the course name if the fullname is set to '?' in the DB (empty in the category edit form)
        if (empty($this->parent) && $this->fullname == '?') {
            $course = $DB->get_record('course', array('id'=> $this->courseid));
            return format_string($course->fullname, false, array("context" => context_course::instance($this->courseid)));

        } else {
            // Grade categories can't be set up at system context (unlike scales and outcomes)
            // We therefore must have a courseid, and don't need to handle system contexts when filtering.
            return format_string($this->fullname, false, array("context" => context_course::instance($this->courseid)));
        }
    }