Allow multiple categories in CategoryArticleList as first parameter
authorJoshua Rüsweg <josh@bastelstu.be>
Wed, 29 Aug 2018 09:32:08 +0000 (11:32 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Wed, 29 Aug 2018 09:32:18 +0000 (11:32 +0200)
See #2642

wcfsetup/install/files/lib/data/article/CategoryArticleList.class.php

index c4332b3105880441a79ad288b2a06f1efc12f9ba..c81f480f90583e4702d9b50fa9b81f5160552734 100644 (file)
@@ -17,22 +17,30 @@ class CategoryArticleList extends AccessibleArticleList {
        /**
         * Creates a new CategoryArticleList object.
         *
-        * @param       integer         $categoryID
+        * @param       integer[]       $categoryID
         * @param       boolean         $includeChildCategories
         * @throws      \InvalidArgumentException
         */
        public function __construct($categoryID, $includeChildCategories = false) {
                ViewableArticleList::__construct();
                
-               $categoryIDs = [$categoryID];
+               if (!is_array($categoryID)) {
+                       $categoryIDs = $fetchChildCategories = [$categoryID];
+               }
+               else {
+                       $categoryIDs = $fetchChildCategories = $categoryID;
+               }
+               
                if ($includeChildCategories) {
-                       $category = ArticleCategory::getCategory($categoryID);
-                       if ($category === null) {
-                               throw new \InvalidArgumentException("invalid category id '".$categoryID."' given");
-                       }
-                       foreach ($category->getAllChildCategories() as $category) {
-                               if ($category->isAccessible()) {
-                                       $categoryIDs[] = $category->categoryID;
+                       foreach ($fetchChildCategories as $categoryID) {
+                               $category = ArticleCategory::getCategory($categoryID);
+                               if ($category === null) {
+                                       throw new \InvalidArgumentException("invalid category id '".$categoryID."' given");
+                               }
+                               foreach ($category->getAllChildCategories() as $category) {
+                                       if ($category->isAccessible()) {
+                                               $categoryIDs[] = $category->categoryID;
+                                       }
                                }
                        }
                }