Small category system improvements
authorMarcel Werk <burntime@woltlab.com>
Fri, 4 Jan 2013 02:37:00 +0000 (03:37 +0100)
committerMarcel Werk <burntime@woltlab.com>
Fri, 4 Jan 2013 02:37:00 +0000 (03:37 +0100)
wcfsetup/install/files/lib/data/category/Category.class.php
wcfsetup/install/files/lib/system/category/CategoryHandler.class.php

index 7d569470fec595916034d29fda071936ec1b62a4..f0ab4b88a03bf3e51c671b3798b0006497a266d2 100644 (file)
@@ -73,6 +73,15 @@ class Category extends DatabaseObject implements IRouteController {
                return $this->categoryType;
        }
        
+       /**
+        * Returns the name of the category type of this category.
+        *
+        * @return      string
+        */
+       public function getCategoryTypeName() {
+               return CategoryHandler::getInstance()->getObjectType($this->objectTypeID)->objectType;
+       }
+       
        /**
         * @see wcf\system\request\IRouteController::getID()
         */
index 33e63f1045b1900d30c5e29f8a9e521ccd14ebca..8442e4d787e7239be2e5e59a442b71cea1b5c2c7 100644 (file)
@@ -66,6 +66,30 @@ class CategoryHandler extends SingletonFactory {
                return $categories;
        }
        
+       /**
+        * Returns a list of accessible categories.
+        *
+        * @param       string          $objectType
+        * @param       array           $permissions            filters categories by given permissions
+        * @return      array<integer>                          comma separated category ids
+        */
+       public function getAccessibleCategoryIDs($objectType, array $permissions) {
+               $categoryIDs = array();
+               foreach ($this->getCategories($objectType) as $category) {
+                       $result = true;
+                       $categoryPermissions = CategoryPermissionHandler::getInstance()->getPermissions($category);
+                       foreach ($permissions as $permission) {
+                               $result = $result && !empty($categoryPermissions[$permission]);
+                       }
+                               
+                       if ($result) {
+                               $categoryIDs[] = $category->categoryID;
+                       }
+               }
+       
+               return $categoryIDs;
+       }
+       
        /**
         * Returns the category object with the given category id.
         *