/** * Returns a list with category ids of accessible news categories. * * @param array $permissions * @return array<integer> */ public static function getAccessibleCategoryIDs(array $permissions = array('canViewCategory')) { $categoryIDs = array(); foreach (CategoryHandler::getInstance()->getCategories('de.voolia.news.category') as $category) { $result = true; $category = new NewsCategory($category); foreach ($permissions as $permission) { $result = $result && $category->getPermission($permission); } if ($result) { $categoryIDs[] = $category->categoryID; } } return $categoryIDs; }
/** * Validates the tags. */ protected function validateTags() { // check whether the user can/must set tags because of the category selection. $canSetTags = true; $canCreateNewsWithoutTags = true; foreach ($this->categoryIDs as $categoryID) { $category = CategoryHandler::getInstance()->getCategory($categoryID); $category = new NewsCategory($category); // check permissions if (!$category->getPermission('canSetTags')) { $canSetTags = false; } if (!$category->getPermission('canCreateNewsWithoutTags')) { $canCreateNewsWithoutTags = false; } // we have everything we need :-) if (!$canSetTags && !$canCreateNewsWithoutTags) { break; } } if (empty($this->tags)) { if ($canSetTags && !$canCreateNewsWithoutTags) { throw new UserInputException('tags', 'empty'); } } else { if (!$canSetTags) { // user can't set tags => ignore them $this->tags = array(); } } }