public function addCategory(Category $category)
{
$categoryId = $category->getId();
if ($this->hasCategory($categoryId)) {
throw new \Exception(sprintf('Category %s already exists', $categoryId));
}
$this->categories[$categoryId] = $category;
}
/** * @return CategoryList */ public static function get() { $list = new CategoryList(); $categories = StaticContainer::get('Piwik\\Plugin\\Categories'); foreach ($categories->getAllCategories() as $category) { $list->addCategory($category); } // move subcategories into categories foreach ($categories->getAllSubcategories() as $subcategory) { $categoryId = $subcategory->getCategoryId(); if (!$categoryId) { continue; } if ($list->hasCategory($categoryId)) { $category = $list->getCategory($categoryId); } else { $category = new Category(); $category->setId($categoryId); $list->addCategory($category); } $category->addSubcategory($subcategory); } return $list; }