From 43abc02d6aae96a3d08e30c9a96f8c1431bbbff4 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 9 Apr 2019 19:34:47 +0200 Subject: [PATCH] Made depth of calendar categories more flexible Closes #2886 --- .../templates/boxArticleCategories.tpl | 40 ++++--------------- .../lib/data/category/CategoryNode.class.php | 28 +++++++++++++ .../ArticleCategoriesBoxController.class.php | 1 - .../category/ArticleCategoryType.class.php | 2 +- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/com.woltlab.wcf/templates/boxArticleCategories.tpl b/com.woltlab.wcf/templates/boxArticleCategories.tpl index e33050c36f..15610df939 100644 --- a/com.woltlab.wcf/templates/boxArticleCategories.tpl +++ b/com.woltlab.wcf/templates/boxArticleCategories.tpl @@ -1,37 +1,13 @@
    {foreach from=$categoryList item=categoryItem} - categoryID == $categoryItem->categoryID} class="active"{/if} data-category-id="{@$categoryItem->categoryID}"> - - {$categoryItem->getTitle()} - {#$categoryItem->getArticles()} - - - {if $categoryItem->hasChildren() && (!$categoryItem->parentCategoryID || ($activeCategory->categoryID == $categoryItem->categoryID || $activeCategory->isParentCategory($categoryItem->getDecoratedObject())))} -
      - {foreach from=$categoryItem item=subCategoryItem} - categoryID == $subCategoryItem->categoryID} class="active"{/if} data-category-id="{@$subCategoryItem->categoryID}"> - - {$subCategoryItem->getTitle()} - {#$subCategoryItem->getArticles()} - - - {if $activeCategory && ($activeCategory->categoryID == $subCategoryItem->categoryID || $activeCategory->parentCategoryID == $subCategoryItem->categoryID) && $subCategoryItem->hasChildren()} -
        - {foreach from=$subCategoryItem item=subSubCategoryItem} - categoryID == $subSubCategoryItem->categoryID} class="active"{/if} data-category-id="{@$subSubCategoryItem->categoryID}"> - - {$subSubCategoryItem->getTitle()} - {#$subSubCategoryItem->getArticles()} - - - {/foreach} -
      - {/if} - - {/foreach} -
    - {/if} - + {if $categoryItem->isVisibleInNestedList($activeCategory)} +
  1. + + {$categoryItem->getTitle()} + {#$categoryItem->getArticles()} + +
  2. + {/if} {/foreach} {if $activeCategory} diff --git a/wcfsetup/install/files/lib/data/category/CategoryNode.class.php b/wcfsetup/install/files/lib/data/category/CategoryNode.class.php index 60eaf8dee3..1dab61ee36 100644 --- a/wcfsetup/install/files/lib/data/category/CategoryNode.class.php +++ b/wcfsetup/install/files/lib/data/category/CategoryNode.class.php @@ -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; + } } diff --git a/wcfsetup/install/files/lib/system/box/ArticleCategoriesBoxController.class.php b/wcfsetup/install/files/lib/system/box/ArticleCategoriesBoxController.class.php index 8cedb11902..e4a262b0b0 100644 --- a/wcfsetup/install/files/lib/system/box/ArticleCategoriesBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/ArticleCategoriesBoxController.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/category/ArticleCategoryType.class.php b/wcfsetup/install/files/lib/system/category/ArticleCategoryType.class.php index 779afc2148..6431c4f471 100644 --- a/wcfsetup/install/files/lib/system/category/ArticleCategoryType.class.php +++ b/wcfsetup/install/files/lib/system/category/ArticleCategoryType.class.php @@ -25,7 +25,7 @@ class ArticleCategoryType extends AbstractCategoryType { /** * @inheritDoc */ - protected $maximumNestingLevel = 2; + protected $maximumNestingLevel = 9; /** * @inheritDoc -- 2.20.1