Made depth of calendar categories more flexible
authorMarcel Werk <burntime@woltlab.com>
Tue, 9 Apr 2019 17:34:47 +0000 (19:34 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 9 Apr 2019 17:34:47 +0000 (19:34 +0200)
Closes #2886

com.woltlab.wcf/templates/boxArticleCategories.tpl
wcfsetup/install/files/lib/data/category/CategoryNode.class.php
wcfsetup/install/files/lib/system/box/ArticleCategoriesBoxController.class.php
wcfsetup/install/files/lib/system/category/ArticleCategoryType.class.php

index e33050c36f4fed1b242571c36dbf2b70e13eecba..15610df93971c13412ac78a225ae9c002d7ee142 100644 (file)
@@ -1,37 +1,13 @@
 <ol class="boxMenu">
        {foreach from=$categoryList item=categoryItem}
-               <li{if $activeCategory && $activeCategory->categoryID == $categoryItem->categoryID} class="active"{/if} data-category-id="{@$categoryItem->categoryID}">
-                       <a href="{@$categoryItem->getLink()}" class="boxMenuLink">
-                               <span class="boxMenuLinkTitle">{$categoryItem->getTitle()}</span>
-                               <span class="badge">{#$categoryItem->getArticles()}</span>
-                       </a>
-                       
-                       {if $categoryItem->hasChildren() && (!$categoryItem->parentCategoryID || ($activeCategory->categoryID == $categoryItem->categoryID || $activeCategory->isParentCategory($categoryItem->getDecoratedObject())))}
-                               <ol class="boxMenuDepth1">
-                                       {foreach from=$categoryItem item=subCategoryItem}
-                                               <li{if $activeCategory && $activeCategory->categoryID == $subCategoryItem->categoryID} class="active"{/if} data-category-id="{@$subCategoryItem->categoryID}">
-                                                       <a href="{@$subCategoryItem->getLink()}" class="boxMenuLink">
-                                                               <span class="boxMenuLinkTitle">{$subCategoryItem->getTitle()}</span>
-                                                               <span class="badge">{#$subCategoryItem->getArticles()}</span>
-                                                       </a>
-                                                       
-                                                       {if $activeCategory && ($activeCategory->categoryID == $subCategoryItem->categoryID || $activeCategory->parentCategoryID == $subCategoryItem->categoryID) && $subCategoryItem->hasChildren()}
-                                                               <ol class="boxMenuDepth2">
-                                                                       {foreach from=$subCategoryItem item=subSubCategoryItem}
-                                                                               <li{if $activeCategory && $activeCategory->categoryID == $subSubCategoryItem->categoryID} class="active"{/if} data-category-id="{@$subSubCategoryItem->categoryID}">
-                                                                                       <a href="{@$subSubCategoryItem->getLink()}" class="boxMenuLink">
-                                                                                               <span class="boxMenuLinkTitle">{$subSubCategoryItem->getTitle()}</span>
-                                                                                               <span class="badge">{#$subSubCategoryItem->getArticles()}</span>
-                                                                                       </a>
-                                                                               </li>
-                                                                       {/foreach}
-                                                               </ol>
-                                                       {/if}
-                                               </li>
-                                       {/foreach}
-                               </ol>
-                       {/if}
-               </li>
+               {if $categoryItem->isVisibleInNestedList($activeCategory)}
+                       <li class="boxMenuItem boxMenuItemDepth{@$categoryItem->getDepth()}{if $activeCategory && $activeCategory->categoryID == $categoryItem->categoryID} active{/if}" data-category-id="{@$categoryItem->categoryID}">
+                               <a href="{@$categoryItem->getLink()}" class="boxMenuLink">
+                                       <span class="boxMenuLinkTitle">{$categoryItem->getTitle()}</span>
+                                       <span class="badge">{#$categoryItem->getArticles()}</span>
+                               </a>
+                       </li>
+               {/if}
        {/foreach}
        
        {if $activeCategory}
index 60eaf8dee3e78f752d4a5eee5c33fb1753af2f8e..1dab61ee36ce92befcb08e69056bf3df978aefe1 100644 (file)
@@ -160,4 +160,32 @@ class CategoryNode extends DatabaseObjectDecorator implements \RecursiveIterator
        public function valid() {
                return isset($this->children[$this->index]);
        }
+       
+       /**
+        * Returns true if this category is visible in a nested menu item list.
+        *
+        * @param       AbstractDecoratedCategory        $activeCategory
+        * @return      boolean
+        * @since       5.2
+        */
+       public function isVisibleInNestedList(AbstractDecoratedCategory $activeCategory = null) {
+               if (!$this->getParentCategory()) {
+                       // level 1 is always visible
+                       return true;
+               }
+               
+               if ($activeCategory) {
+                       if ($activeCategory->categoryID == $this->categoryID || $activeCategory->getDecoratedObject()->isParentCategory($this->getDecoratedObject())) {
+                               // is the active category or a parent of the active category
+                               return true;
+                       }
+                       
+                       if ($this->getParentCategory()->categoryID == $activeCategory->categoryID) {
+                               // is a direct child element of the active category
+                               return true;
+                       }
+               }
+               
+               return false;
+       }
 }
index 8cedb11902b5bc4b7432b9a1cf03c8355a1917c5..e4a262b0b061b8bbceeeec67fa213417ee3d8259 100644 (file)
@@ -28,7 +28,6 @@ class ArticleCategoriesBoxController extends AbstractBoxController {
                // get categories
                $categoryTree = new ArticleCategoryNodeTree('com.woltlab.wcf.article.category');
                $categoryList = $categoryTree->getIterator();
-               $categoryList->setMaxDepth(0);
                
                if (iterator_count($categoryList)) {
                        // get active category
index 779afc2148bbe0f603bc56f1df15190c25202eee..6431c4f47127948f9ebeaa0d28a803a07f0204f8 100644 (file)
@@ -25,7 +25,7 @@ class ArticleCategoryType extends AbstractCategoryType {
        /**
         * @inheritDoc
         */
-       protected $maximumNestingLevel = 2;
+       protected $maximumNestingLevel = 9;
        
        /**
         * @inheritDoc