addCategory() public method

public addCategory ( Category $category )
$category Category
Example #1
0
 /**
  * @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;
 }
Example #2
0
 /**
  * @param CategoryList $categoryList
  * @param WidgetConfig[] $widgetConfigs
  */
 private function createMissingCategoriesAndSubcategories($categoryList, $widgetConfigs)
 {
     // move reports into categories/subcategories and create missing ones if needed
     foreach ($widgetConfigs as $widgetConfig) {
         $categoryId = $widgetConfig->getCategoryId();
         $subcategoryId = $widgetConfig->getSubcategoryId();
         if (!$categoryId) {
             continue;
         }
         if ($widgetConfig instanceof WidgetContainerConfig && !$widgetConfig->getWidgetConfigs()) {
             // if a container does not contain any widgets, ignore it
             continue;
         }
         if (!$categoryList->hasCategory($categoryId)) {
             $categoryList->addCategory($this->createCategory($categoryId));
         }
         if (!$subcategoryId) {
             continue;
         }
         $category = $categoryList->getCategory($categoryId);
         if (!$category->hasSubcategory($subcategoryId)) {
             $category->addSubcategory($this->createSubcategory($categoryId, $subcategoryId));
         }
     }
 }