Enhances ViewableCategory-classes
authorMatthias Schmidt <gravatronics@live.com>
Mon, 31 Dec 2012 16:41:56 +0000 (17:41 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 31 Dec 2012 16:41:56 +0000 (17:41 +0100)
wcfsetup/install/files/lib/data/category/ViewableCategory.class.php
wcfsetup/install/files/lib/data/category/ViewableCategoryNode.class.php
wcfsetup/install/files/lib/data/category/ViewableCategoryNodeList.class.php

index c0aad1b526d752c8e7bf1770333a676b5f1396c1..691faa9e4cc8a110c6e22a262391266f9924a0ee 100644 (file)
@@ -15,6 +15,18 @@ use wcf\system\exception\PermissionDeniedException;
  * @category   Community Framework
  */
 class ViewableCategory extends DatabaseObjectDecorator {
+       /**
+        * list of all parent category generations of this category
+        * @var array<wcf\data\category\ViewableCategory>
+        */
+       protected $parentCategories = null;
+       
+       /**
+        * parent category of this category
+        * @var wcf\data\category\ViewableCategory
+        */
+       protected $parentCategory = null;
+       
        /**
         * @see wcf\data\DatabaseObjectDecorator::$baseClass
         */
@@ -40,6 +52,35 @@ class ViewableCategory extends DatabaseObjectDecorator {
                }
        }
        
+       /**
+        * @see wcf\data\category\Category::getParentCategories()
+        */
+       public function getParentCategories() {
+               if ($this->parentCategories === null) {
+                       $this->parentCategories = array();
+                       $className = get_class($this);
+                       
+                       foreach ($this->getDecoratedObject()->getParentCategories() as $category) {
+                               $this->parentCategories[$category->categoryID] = new $className($category);
+                       }
+               }
+               
+               return $this->parentCategories;
+       }
+       
+       /**
+        * @see wcf\data\category\Category::getParentCategory()
+        */
+       public function getParentCategory() {
+               if ($this->parentCategoryID && $this->parentCategory === null) {
+                       $className = get_class($this);
+                       
+                       $this->parentCategory = new $className($this->getDecoratedObject()->getParentCategory());
+               }
+               
+               return $this->parentCategory;
+       }
+       
        /**
         * Returns the acl permission value of the given permission for the active
         * user and of this category.
index a4fbbc9643ccd0d494724b06e953e4f89572e2e7..072761163503c0042852a50ed91d02189236c254 100644 (file)
@@ -1,9 +1,10 @@
 <?php
 namespace wcf\data\category;
+use wcf\data\DatabaseObject;
 
 /**
  * Represents a viewable category node.
- *
+ * 
  * @author     Matthias Schmidt
  * @copyright  2001-2012 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
@@ -12,10 +13,19 @@ namespace wcf\data\category;
  * @category   Community Framework
  */
 class ViewableCategoryNode extends CategoryNode {
+       /**
+        * @see wcf\data\DatabaseObjectDecorator::$baseClass
+        */
+       protected static $baseClass = 'wcf\data\category\ViewableCategory';
+       
        /**
         * @see wcf\data\DatabaseObjectDecorator::__construct()
         */
        public function __construct(DatabaseObject $object, $includeDisabledCategories = false, array $excludedCategoryIDs = array()) {
-               parent::__construct(new ViewableCategory($object), $includeDisabledCategories, $excludedCategoryIDs);
+               if (!($object instanceof static::$baseClass)) {
+                       $object = new static::$baseClass($object);
+               }
+               
+               parent::__construct($object, $includeDisabledCategories, $excludedCategoryIDs);
        }
 }
index 9c389ac94d139925899299f2a349b0e122ac199c..06499496d88b8e1fa1ca8ef36ae5cae7e991822a 100644 (file)
@@ -11,9 +11,4 @@ namespace wcf\data\category;
  * @subpackage data.category
  * @category   Community Framework
  */
-class ViewableCategoryNodeList extends CategoryNodeList {
-       /**
-        * @see wcf\data\category\CategoryNodeList::$nodeClassName
-        */
-       protected $nodeClassName = 'wcf\data\category\ViewableCategoryNode';
-}
+class ViewableCategoryNodeList extends CategoryNodeList { }