From 9d0eeb31e71206ae5ea79fd0ce0d96d8656335ed Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Thu, 17 Dec 2020 16:20:13 +0100 Subject: [PATCH] Improved detection of empty option categories --- .../lib/system/menu/user/UserMenu.class.php | 2 +- .../lib/system/option/OptionHandler.class.php | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php b/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php index 4a49f30bf8..9a5c31b16d 100644 --- a/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php @@ -44,7 +44,7 @@ class UserMenu extends TreeMenu { // Hide links to user option categories without accessible options. if (strpos($item->menuItem, 'wcf.user.option.category.') === 0) { $categoryName = str_replace('wcf.user.option.category.', '', $item->menuItem); - if (empty($this->optionHandler->getOptionTree($categoryName))) { + if (!$this->optionHandler->countCategoryOptions($categoryName)) { return false; } } diff --git a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php index 24f3d6c6bd..817a35587b 100644 --- a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php @@ -246,6 +246,35 @@ class OptionHandler implements IOptionHandler { return $children; } + /** + * Counts the number of options in a specific option category. + * + * @param string $categoryName + * @param bool $inherit + * @return int + */ + public function countCategoryOptions($categoryName = '', $inherit = true) { + $count = 0; + + if ($inherit && isset($this->cachedCategoryStructure[$categoryName])) { + foreach ($this->cachedCategoryStructure[$categoryName] as $subCategoryName) { + $count += $this->countCategoryOptions($subCategoryName); + } + } + + if ($categoryName !== '') { + if (isset($this->cachedOptionToCategories[$categoryName])) { + foreach ($this->cachedOptionToCategories[$categoryName] as $optionName) { + if (isset($this->options[$optionName]) && $this->checkOption($this->options[$optionName])) { + $count++; + } + } + } + } + + return $count; + } + /** * @inheritDoc */ -- 2.20.1