Piwik\Category\CategoryList::getCategory PHP Метод

getCategory() публичный Метод

Get the category having the given id, if possible.
public getCategory ( string $categoryId ) : Category | null
$categoryId string
Результат Category | null
    public function getCategory($categoryId)
    {
        if ($this->hasCategory($categoryId)) {
            return $this->categories[$categoryId];
        }
    }

Usage 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;
 }
All Usage Examples Of Piwik\Category\CategoryList::getCategory