Unify the terms 'Staff' and 'Team'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / category / CategoryNode.class.php
... / ...
CommitLineData
1<?php
2
3namespace wcf\data\category;
4
5use wcf\data\DatabaseObjectDecorator;
6use wcf\data\ILinkableObject;
7use wcf\data\IObjectTreeNode;
8use wcf\data\TObjectTreeNode;
9
10/**
11 * Represents a category node.
12 *
13 * @author Matthias Schmidt
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 *
17 * @method Category getDecoratedObject()
18 * @mixin Category
19 */
20class CategoryNode extends DatabaseObjectDecorator implements IObjectTreeNode
21{
22 use TObjectTreeNode;
23
24 /**
25 * @inheritDoc
26 */
27 protected static $baseClass = Category::class;
28
29 /**
30 * Returns true if this category is visible in a nested menu item list.
31 *
32 * @since 5.2
33 */
34 public function isVisibleInNestedList(?AbstractDecoratedCategory $activeCategory = null, bool $showChildCategories = false): bool
35 {
36 if (!$this->getParentCategory()) {
37 // level 1 is always visible
38 return true;
39 }
40
41 if ($showChildCategories && !$this->getParentCategory()->getParentCategory()) {
42 return true;
43 }
44
45 if ($activeCategory) {
46 $decoratedObject = $this->getDecoratedObject();
47 if (
48 $activeCategory->categoryID == $this->categoryID
49 || (
50 $decoratedObject instanceof AbstractDecoratedCategory
51 && $activeCategory->isParentCategory($decoratedObject)
52 )
53 ) {
54 // is the active category or a parent of the active category
55 return true;
56 }
57
58 if ($this->getParentCategory()->categoryID == $activeCategory->categoryID) {
59 // is a direct child element of the active category
60 return true;
61 }
62
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.
66 return true;
67 }
68 }
69 }
70
71 return false;
72 }
73
74 /**
75 * Returns number of items in the category.
76 */
77 public function getItems(): int
78 {
79 return 0;
80 }
81
82 public function getLink(): string
83 {
84 $decoratedObject = $this->getDecoratedObject();
85 if ($decoratedObject instanceof ILinkableObject) {
86 return $decoratedObject->getLink();
87 }
88
89 return '';
90 }
91}