Enhances category system
authorMatthias Schmidt <gravatronics@live.com>
Sun, 9 Sep 2012 09:04:36 +0000 (11:04 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 9 Sep 2012 12:38:25 +0000 (14:38 +0200)
wcfsetup/install/files/lib/data/category/CategoryNode.class.php
wcfsetup/install/files/lib/data/category/CategoryNodeList.class.php
wcfsetup/install/files/lib/system/category/CategoryHandler.class.php

index 315e6c49c87b8402afd36a74e19c4eb91e9acdcd..2a74de5519984877d330ce8b51b687406536291c 100644 (file)
@@ -73,10 +73,10 @@ class CategoryNode extends DatabaseObjectDecorator implements \RecursiveIterator
         * Returns true if the given category fulfills all needed conditions to
         * be included in the list.
         * 
-        * @param       wcf\data\category\Category      $category
+        * @param       wcf\data\DatabaseObject $category
         * @return      boolean
         */
-       public function fulfillsConditions(Category $category) {
+       protected function fulfillsConditions(DatabaseObject $category) {
                return !in_array($category->categoryID, $this->excludedCategoryIDs) && ($this->includeDisabledCategories || !$category->isDisabled);
        }
        
index 31d50e2f185b6eb88af474955316873a9d9e2bea..1bbef6f19120f339de49a06c4504270cac007002 100644 (file)
@@ -24,7 +24,7 @@ class CategoryNodeList extends \RecursiveIteratorIterator implements \Countable
         * name of the category node class
         * @var string
         */
-       protected $nodeClassName = 'wcf\data\category\CategoryNode';
+       protected $nodeClassName = '';
        
        /**
         * id of the parent category
@@ -41,6 +41,13 @@ class CategoryNodeList extends \RecursiveIteratorIterator implements \Countable
         * @param       array<integer>  $excludedCategoryIDs
         */
        public function __construct($objectType, $parentCategoryID = 0, $includeDisabledCategories = false, array $excludedCategoryIDs = array()) {
+               if (empty($this->nodeClassName)) {
+                       $this->nodeClassName = str_replace('List', '', get_class($this));
+                       if (!class_exists($this->nodeClassName)) {
+                               throw new SystemException("Unknown category node class '".$this->nodeClassName."'.");
+                       }
+               }
+               
                $this->parentCategoryID = $parentCategoryID;
                
                // get parent category
index aa1354a17562249def4bd7cc2b3334621517fe21..0b10892debaa76593ac18c71b4576af61de326ba 100644 (file)
@@ -1,9 +1,12 @@
 <?php
 namespace wcf\system\category;
 use wcf\data\category\Category;
+use wcf\data\DatabaseObject;
+use wcf\data\DatabaseObjectDecorator;
 use wcf\system\SingletonFactory;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\system\cache\CacheHandler;
+use wcf\system\exception\SystemException;
 
 /**
  * Handles categories.
@@ -80,12 +83,15 @@ class CategoryHandler extends SingletonFactory {
        /**
         * Returns the child categories of the given category.
         * 
-        * @param       wcf\data\category\Category      $category
+        * @param       wcf\data\DatabaseObject         $category
         * @return      array<wcf\data\category\Category>
         */
-       public function getChildCategories(Category $category) {
-               $categories = array();
+       public function getChildCategories(DatabaseObject $category) {
+               if (!($category instanceof Category) && (!($category instanceof DatabaseObjectDecorator) || !($category->getDecoratedObject() instanceof Category))) {
+                       throw new SystemException("Invalid object given (class: ".get_class($category).")");
+               }
                
+               $categories = array();
                foreach ($this->categories as $__category) {
                        if ($__category->parentCategoryID == $category->categoryID && ($category->categoryID || $category->objectTypeID == $__category->objectTypeID)) {
                                $categories[$__category->categoryID] = $__category;