Add EmailLogListPage
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / category / AbstractDecoratedCategory.class.php
1 <?php
2
3 namespace wcf\data\category;
4
5 use wcf\data\DatabaseObjectDecorator;
6 use wcf\system\category\CategoryHandler;
7 use wcf\system\exception\PermissionDeniedException;
8
9 /**
10 * Abstract implementation of a decorated category.
11 *
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
16 *
17 * @method Category getDecoratedObject()
18 * @mixin Category
19 */
20 abstract class AbstractDecoratedCategory extends DatabaseObjectDecorator
21 {
22 /**
23 * list of child categories of this category
24 * @var Category[]
25 */
26 protected $childCategories;
27
28 /**
29 * list of all child categories of this category
30 * @var Category[]
31 */
32 protected $allChildCategories;
33
34 /**
35 * list of all parent category generations of this category
36 * @var AbstractDecoratedCategory[]
37 */
38 protected $parentCategories;
39
40 /**
41 * parent category of this category
42 * @var AbstractDecoratedCategory
43 */
44 protected $parentCategory;
45
46 /**
47 * @inheritDoc
48 */
49 protected static $baseClass = Category::class;
50
51 /**
52 * @inheritDoc
53 */
54 public function checkPermissions(array $permissions)
55 {
56 foreach ($permissions as $permission) {
57 if (!$this->getPermission($permission)) {
58 throw new PermissionDeniedException();
59 }
60 }
61 }
62
63 /**
64 * @inheritDoc
65 */
66 public function getChildCategories()
67 {
68 if ($this->childCategories === null) {
69 $this->childCategories = [];
70 foreach ($this->getDecoratedObject()->getChildCategories() as $category) {
71 $this->childCategories[$category->categoryID] = new static($category);
72 }
73 }
74
75 return $this->childCategories;
76 }
77
78 /**
79 * @inheritDoc
80 */
81 public function getAllChildCategories()
82 {
83 if ($this->allChildCategories === null) {
84 $this->allChildCategories = [];
85 foreach ($this->getDecoratedObject()->getAllChildCategories() as $category) {
86 $this->allChildCategories[$category->categoryID] = new static($category);
87 }
88 }
89
90 return $this->allChildCategories;
91 }
92
93 /**
94 * @inheritDoc
95 */
96 public function getParentCategories()
97 {
98 if ($this->parentCategories === null) {
99 $this->parentCategories = [];
100 foreach ($this->getDecoratedObject()->getParentCategories() as $category) {
101 $this->parentCategories[$category->categoryID] = new static($category);
102 }
103 }
104
105 return $this->parentCategories;
106 }
107
108 /**
109 * @inheritDoc
110 */
111 public function getParentCategory()
112 {
113 if ($this->parentCategoryID && $this->parentCategory === null) {
114 $this->parentCategory = new static($this->getDecoratedObject()->getParentCategory());
115 }
116
117 return $this->parentCategory;
118 }
119
120 /**
121 * @inheritDoc
122 */
123 public function isParentCategory(self $category)
124 {
125 return $this->getDecoratedObject()->isParentCategory($category->getDecoratedObject());
126 }
127
128 /**
129 * Returns the decorated category with the given id or `null` if no such
130 * category exists.
131 *
132 * @param int $categoryID
133 * @return AbstractDecoratedCategory|null
134 */
135 public static function getCategory($categoryID)
136 {
137 $category = CategoryHandler::getInstance()->getCategory($categoryID);
138 if ($category) {
139 return new static($category);
140 }
141 }
142 }