Only show label groups available in category on CategoryArticleListPage
authorMatthias Schmidt <gravatronics@live.com>
Sun, 3 Jan 2021 16:08:47 +0000 (17:08 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 3 Jan 2021 16:08:47 +0000 (17:08 +0100)
Close #3701

wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php
wcfsetup/install/files/lib/page/ArticleListPage.class.php
wcfsetup/install/files/lib/page/CategoryArticleListPage.class.php

index 8d9860f340ff9307d5e1a4e08fc7b917a23abfb4..f965e8fc05bdc52b307c371c095b828243f18b41 100644 (file)
@@ -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.
         *
index 08f46b9dcccdbf1be48dfcdc6dbe6f834ecd028a..a1d48033eb0bde22bfac9821e0c247e3c39f9c94 100644 (file)
@@ -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
         */
index 08a4ec37ad23dba8d28f579830efa70e4aa73420..3d0db47dabebe572d4c069e8d9cee23d65350a82 100644 (file)
@@ -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
         */