public function set_parent($parentid, $updateaggregationfields = true) {
        if ($this->is_course_item() or $this->is_category_item()) {
            print_error('cannotsetparentforcatoritem');
        }

        if ($this->categoryid == $parentid) {
            return true;
        }

        // find parent and check course id
        if (!$parent_category = grade_category::fetch(array('id'=>$parentid, 'courseid'=>$this->courseid))) {
            return false;
        }

        $currentparent = $this->load_parent_category();

        if ($updateaggregationfields) {
            $this->set_aggregation_fields_for_aggregation($currentparent->aggregation, $parent_category->aggregation);
        }

        $this->force_regrading();

        // set new parent
        $this->categoryid = $parent_category->id;
        $this->parent_category =& $parent_category;

        return $this->update();
    }