From 42fd7c776d553379a40dfc03e74403a5cd272675 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 31 Dec 2012 17:41:56 +0100 Subject: [PATCH] Enhances ViewableCategory-classes --- .../data/category/ViewableCategory.class.php | 41 +++++++++++++++++++ .../category/ViewableCategoryNode.class.php | 14 ++++++- .../ViewableCategoryNodeList.class.php | 7 +--- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/lib/data/category/ViewableCategory.class.php b/wcfsetup/install/files/lib/data/category/ViewableCategory.class.php index c0aad1b526..691faa9e4c 100644 --- a/wcfsetup/install/files/lib/data/category/ViewableCategory.class.php +++ b/wcfsetup/install/files/lib/data/category/ViewableCategory.class.php @@ -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 + */ + 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. diff --git a/wcfsetup/install/files/lib/data/category/ViewableCategoryNode.class.php b/wcfsetup/install/files/lib/data/category/ViewableCategoryNode.class.php index a4fbbc9643..0727611635 100644 --- a/wcfsetup/install/files/lib/data/category/ViewableCategoryNode.class.php +++ b/wcfsetup/install/files/lib/data/category/ViewableCategoryNode.class.php @@ -1,9 +1,10 @@ @@ -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); } } diff --git a/wcfsetup/install/files/lib/data/category/ViewableCategoryNodeList.class.php b/wcfsetup/install/files/lib/data/category/ViewableCategoryNodeList.class.php index 9c389ac94d..06499496d8 100644 --- a/wcfsetup/install/files/lib/data/category/ViewableCategoryNodeList.class.php +++ b/wcfsetup/install/files/lib/data/category/ViewableCategoryNodeList.class.php @@ -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 { } -- 2.20.1