Commit | Line | Data |
---|---|---|
13d8b49b | 1 | <?php |
a9229942 | 2 | |
13d8b49b | 3 | namespace wcf\data\category; |
a9229942 | 4 | |
bcb9c1bf | 5 | use wcf\data\DatabaseObjectDecorator; |
2107b320 | 6 | use wcf\data\ILinkableObject; |
755d49f0 MS |
7 | use wcf\data\IObjectTreeNode; |
8 | use wcf\data\TObjectTreeNode; | |
13d8b49b MS |
9 | |
10 | /** | |
11 | * Represents a category node. | |
a9229942 TD |
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> | |
a9229942 TD |
16 | * |
17 | * @method Category getDecoratedObject() | |
18 | * @mixin Category | |
13d8b49b | 19 | */ |
a9229942 TD |
20 | class 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 | * | |
a9229942 TD |
32 | * @since 5.2 |
33 | */ | |
53555321 | 34 | public function isVisibleInNestedList(?AbstractDecoratedCategory $activeCategory = null, bool $showChildCategories = false): bool |
a9229942 | 35 | { |
53555321 MW |
36 | if (!$this->getParentCategory()) { |
37 | // level 1 is always visible | |
38 | return true; | |
39 | } | |
40 | ||
41 | if ($showChildCategories && !$this->getParentCategory()->getParentCategory()) { | |
a9229942 TD |
42 | return true; |
43 | } | |
44 | ||
45 | if ($activeCategory) { | |
2107b320 | 46 | $decoratedObject = $this->getDecoratedObject(); |
a9229942 TD |
47 | if ( |
48 | $activeCategory->categoryID == $this->categoryID | |
27454d07 TD |
49 | || ( |
50 | $decoratedObject instanceof AbstractDecoratedCategory | |
2107b320 MW |
51 | && $activeCategory->isParentCategory($decoratedObject) |
52 | ) | |
a9229942 TD |
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 | } | |
41f53872 MW |
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 | } | |
a9229942 TD |
69 | } |
70 | ||
71 | return false; | |
72 | } | |
2107b320 MW |
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 | } | |
13d8b49b | 91 | } |