protected function calculate_category_path($categoryid) {

        if (!array_key_exists($categoryid, $this->categoryparent)) {
            throw new moodle1_convert_exception('gradebook_unknown_categoryid', null, $categoryid);
        }

        $path = array($categoryid);
        $parent = $this->categoryparent[$categoryid];
        while (!is_null($parent)) {
            array_unshift($path, $parent);
            $parent = $this->categoryparent[$parent];
            if (in_array($parent, $path)) {
                throw new moodle1_convert_exception('circular_reference_in_categories_tree');
            }
        }

        return $path;
    }