3 namespace wcf\data\category
;
5 use wcf\data\DatabaseObjectDecorator
;
6 use wcf\data\ILinkableObject
;
7 use wcf\data\IObjectTreeNode
;
8 use wcf\data\TObjectTreeNode
;
11 * Represents a category node.
13 * @author Matthias Schmidt
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @method Category getDecoratedObject()
20 class CategoryNode
extends DatabaseObjectDecorator
implements IObjectTreeNode
27 protected static $baseClass = Category
::class;
30 * Returns true if this category is visible in a nested menu item list.
34 public function isVisibleInNestedList(?AbstractDecoratedCategory
$activeCategory = null, bool $showChildCategories = false): bool
36 if (!$this->getParentCategory()) {
37 // level 1 is always visible
41 if ($showChildCategories && !$this->getParentCategory()->getParentCategory()) {
45 if ($activeCategory) {
46 $decoratedObject = $this->getDecoratedObject();
48 $activeCategory->categoryID
== $this->categoryID
50 $decoratedObject instanceof AbstractDecoratedCategory
51 && $activeCategory->isParentCategory($decoratedObject)
54 // is the active category or a parent of the active category
58 if ($this->getParentCategory()->categoryID
== $activeCategory->categoryID
) {
59 // is a direct child element of the active category
63 foreach ($activeCategory->getParentCategories() as $parentCategory) {
64 if ($this->getParentCategory()->categoryID
== $parentCategory->categoryID
) {
65 // This is a child element of a parent category of the active category.
75 * Returns number of items in the category.
77 public function getItems(): int
82 public function getLink(): string
84 $decoratedObject = $this->getDecoratedObject();
85 if ($decoratedObject instanceof ILinkableObject
) {
86 return $decoratedObject->getLink();