From 285cea7702126481e67f62098fe50637236c82aa Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 3 Jan 2021 17:08:47 +0100 Subject: [PATCH] Only show label groups available in category on CategoryArticleListPage Close #3701 --- .../article/category/ArticleCategory.class.php | 17 +++++++++++++++++ .../files/lib/page/ArticleListPage.class.php | 12 +++++++++++- .../lib/page/CategoryArticleListPage.class.php | 8 ++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php b/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php index 8d9860f340..f965e8fc05 100644 --- a/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php +++ b/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php @@ -153,6 +153,23 @@ class ArticleCategory extends AbstractDecoratedCategory implements IAccessibleOb return LabelHandler::getInstance()->getLabelGroups(array_unique($groupIDs), true, $permission); } + /** + * Returns the label groups for this category. + * + * @param string $permission + * @return ViewableLabelGroup[] + * @since 5.4 + */ + public function getLabelGroups(string $permission = 'canSetLabel'): array { + $labelGroupsToCategories = ArticleCategoryLabelCacheBuilder::getInstance()->getData(); + + if (isset($labelGroupsToCategories[$this->categoryID])) { + return LabelHandler::getInstance()->getLabelGroups($labelGroupsToCategories[$this->categoryID], true, $permission); + } + + return []; + } + /** * Returns true if the active user has subscribed to this category. * diff --git a/wcfsetup/install/files/lib/page/ArticleListPage.class.php b/wcfsetup/install/files/lib/page/ArticleListPage.class.php index 08f46b9dcc..a1d48033eb 100644 --- a/wcfsetup/install/files/lib/page/ArticleListPage.class.php +++ b/wcfsetup/install/files/lib/page/ArticleListPage.class.php @@ -107,7 +107,7 @@ class ArticleListPage extends SortablePage { if (!empty($_REQUEST['showArticleAddDialog'])) $this->showArticleAddDialog = 1; // read available label groups - $this->labelGroups = ArticleCategory::getAccessibleLabelGroups('canViewLabel'); + $this->labelGroups = $this->getLabelGroups(); if (!empty($this->labelGroups) && isset($_REQUEST['labelIDs']) && is_array($_REQUEST['labelIDs'])) { $this->labelIDs = $_REQUEST['labelIDs']; @@ -151,6 +151,16 @@ class ArticleListPage extends SortablePage { $this->canonicalURL = LinkHandler::getInstance()->getLink('ArticleList', $this->controllerParameters, ($this->pageNo > 1 ? 'pageNo=' . $this->pageNo : '')); } + /** + * Returns the label groups shown on this page. + * + * @return ViewableLabelGroup[] + * @since 5.4 + */ + protected function getLabelGroups(): array { + return ArticleCategory::getAccessibleLabelGroups('canViewLabel'); + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/page/CategoryArticleListPage.class.php b/wcfsetup/install/files/lib/page/CategoryArticleListPage.class.php index 08a4ec37ad..3d0db47dab 100644 --- a/wcfsetup/install/files/lib/page/CategoryArticleListPage.class.php +++ b/wcfsetup/install/files/lib/page/CategoryArticleListPage.class.php @@ -2,6 +2,7 @@ namespace wcf\page; use wcf\data\article\category\ArticleCategory; use wcf\data\article\CategoryArticleList; +use wcf\data\label\group\ViewableLabelGroup; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\PermissionDeniedException; use wcf\system\page\PageLocationManager; @@ -63,6 +64,13 @@ class CategoryArticleListPage extends ArticleListPage { } } + /** + * @inerhitDoc + */ + protected function getLabelGroups(): array { + return $this->category->getLabelGroups('canViewLabel'); + } + /** * @inheritDoc */ -- 2.20.1