public function add_category(category $cat) {
        $name = $cat->name;
        if (isset($this->categories[$name])) {
            throw new \coding_exception("Category name $name already used");
        }
        $this->categories[$cat->name] = $cat;
    }