3 namespace wcf\data\category
;
5 use wcf\data\DatabaseObjectDecorator
;
6 use wcf\system\category\CategoryHandler
;
7 use wcf\system\exception\PermissionDeniedException
;
10 * Abstract implementation of a decorated category.
12 * @author Matthias Schmidt
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\Data\Category
17 * @method Category getDecoratedObject()
20 abstract class AbstractDecoratedCategory
extends DatabaseObjectDecorator
23 * list of child categories of this category
26 protected $childCategories;
29 * list of all child categories of this category
32 protected $allChildCategories;
35 * list of all parent category generations of this category
36 * @var AbstractDecoratedCategory[]
38 protected $parentCategories;
41 * parent category of this category
42 * @var AbstractDecoratedCategory
44 protected $parentCategory;
49 protected static $baseClass = Category
::class;
54 public function checkPermissions(array $permissions)
56 foreach ($permissions as $permission) {
57 if (!$this->getPermission($permission)) {
58 throw new PermissionDeniedException();
66 public function getChildCategories()
68 if ($this->childCategories
=== null) {
69 $this->childCategories
= [];
70 foreach ($this->getDecoratedObject()->getChildCategories() as $category) {
71 $this->childCategories
[$category->categoryID
] = new static($category);
75 return $this->childCategories
;
81 public function getAllChildCategories()
83 if ($this->allChildCategories
=== null) {
84 $this->allChildCategories
= [];
85 foreach ($this->getDecoratedObject()->getAllChildCategories() as $category) {
86 $this->allChildCategories
[$category->categoryID
] = new static($category);
90 return $this->allChildCategories
;
96 public function getParentCategories()
98 if ($this->parentCategories
=== null) {
99 $this->parentCategories
= [];
100 foreach ($this->getDecoratedObject()->getParentCategories() as $category) {
101 $this->parentCategories
[$category->categoryID
] = new static($category);
105 return $this->parentCategories
;
111 public function getParentCategory()
113 if ($this->parentCategoryID
&& $this->parentCategory
=== null) {
114 $this->parentCategory
= new static($this->getDecoratedObject()->getParentCategory());
117 return $this->parentCategory
;
123 public function isParentCategory(self
$category)
125 return $this->getDecoratedObject()->isParentCategory($category->getDecoratedObject());
129 * Returns the decorated category with the given id or `null` if no such
132 * @param int $categoryID
133 * @return AbstractDecoratedCategory|null
135 public static function getCategory($categoryID)
137 $category = CategoryHandler
::getInstance()->getCategory($categoryID);
139 return new static($category);