Commit | Line | Data |
---|---|---|
13d8b49b | 1 | <?php |
a9229942 | 2 | |
13d8b49b | 3 | namespace wcf\data\category; |
a9229942 | 4 | |
bcb9c1bf | 5 | use wcf\data\DatabaseObjectDecorator; |
755d49f0 MS |
6 | use wcf\data\IObjectTreeNode; |
7 | use wcf\data\TObjectTreeNode; | |
13d8b49b MS |
8 | |
9 | /** | |
10 | * Represents a category node. | |
a9229942 TD |
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 | |
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 | * | |
32 | * @param AbstractDecoratedCategory $activeCategory | |
33 | * @return bool | |
34 | * @since 5.2 | |
35 | */ | |
36 | public function isVisibleInNestedList(?AbstractDecoratedCategory $activeCategory = null) | |
37 | { | |
38 | if (!$this->getParentCategory() || !$this->getParentCategory()->getParentCategory()) { | |
39 | // level 1 & 2 are always visible | |
40 | return true; | |
41 | } | |
42 | ||
43 | if ($activeCategory) { | |
44 | if ( | |
45 | $activeCategory->categoryID == $this->categoryID | |
46 | || $activeCategory->isParentCategory($this->getDecoratedObject()) | |
47 | ) { | |
48 | // is the active category or a parent of the active category | |
49 | return true; | |
50 | } | |
51 | ||
52 | if ($this->getParentCategory()->categoryID == $activeCategory->categoryID) { | |
53 | // is a direct child element of the active category | |
54 | return true; | |
55 | } | |
56 | } | |
57 | ||
58 | return false; | |
59 | } | |
13d8b49b | 60 | } |