Improved detection of empty option categories
authorMarcel Werk <burntime@woltlab.com>
Thu, 17 Dec 2020 15:20:13 +0000 (16:20 +0100)
committerMarcel Werk <burntime@woltlab.com>
Thu, 17 Dec 2020 15:20:13 +0000 (16:20 +0100)
wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php
wcfsetup/install/files/lib/system/option/OptionHandler.class.php

index 4a49f30bf80024bf2f25c9ca583d26a3a4a9e834..9a5c31b16dcb32770b1e2c8632b228b108e52c7d 100644 (file)
@@ -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;
                        }
                }
index 24f3d6c6bdf8ee5594e19f69255b76bf3135c4ac..817a35587b27ca45da394b3bbba17322d2c0855a 100644 (file)
@@ -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
         */