From: Marcel Werk Date: Thu, 17 Dec 2020 15:20:13 +0000 (+0100) Subject: Improved detection of empty option categories X-Git-Tag: 5.3.2~36^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9d0eeb31e71206ae5ea79fd0ce0d96d8656335ed;p=GitHub%2FWoltLab%2FWCF.git Improved detection of empty option categories --- 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 */