// 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;
}
}
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
*/