if ($category === null) {
throw new \InvalidArgumentException("invalid category id '".$categoryID."' given");
}
- foreach ($category->getChildCategories() as $category) {
+ foreach ($category->getAllChildCategories() as $category) {
if ($category->isAccessible()) {
$categoryIDs[] = $category->categoryID;
}
* @since 3.0
*
* @method ArticleCategory[] getChildCategories()
+ * @method ArticleCategory[] getAllChildCategories()
* @method ArticleCategory getParentCategory()
* @method ArticleCategory[] getParentCategories()
* @method static ArticleCategory|null getCategory($categoryID)
*/
abstract class AbstractDecoratedCategory extends DatabaseObjectDecorator {
/**
- * list of all child categories of this category
+ * list of child categories of this category
* @var Category[]
*/
protected $childCategories = null;
+ /**
+ * list of all child categories of this category
+ * @var Category[]
+ */
+ protected $allChildCategories = null;
+
/**
* list of all parent category generations of this category
* @var AbstractDecoratedCategory[]
return $this->childCategories;
}
+ /**
+ * @inheritDoc
+ */
+ public function getAllChildCategories() {
+ if ($this->allChildCategories === null) {
+ $this->allChildCategories = [];
+ foreach ($this->getDecoratedObject()->getAllChildCategories() as $category) {
+ $this->allChildCategories[$category->categoryID] = new static($category);
+ }
+ }
+
+ return $this->allChildCategories;
+ }
+
/**
* @inheritDoc
*/
*/
class Category extends ProcessibleDatabaseObject implements IPermissionObject, IRouteController {
/**
- * list of all child categories of this category
+ * list of child categories of this category
* @var Category[]
*/
protected $childCategories = null;
+ /**
+ * list of all child categories of this category
+ * @var Category[]
+ */
+ protected $allChildCategories = null;
+
/**
* list of all parent category generations of this category
* @var Category[]
}
/**
- * Returns the child categories of this category.
+ * Returns the direct child categories of this category.
*
* @return Category[]
*/
return $this->childCategories;
}
+ /**
+ * Returns the child categories of this category recursively.
+ *
+ * @return Category[]
+ */
+ public function getAllChildCategories() {
+ if ($this->allChildCategories === null) {
+ $directChildCategories = CategoryHandler::getInstance()->getChildCategories($this->categoryID);
+ $childCategories = [];
+ foreach ($directChildCategories as $childCategory) {
+ $childCategories = array_replace($childCategories, $childCategory->getAllChildCategories());
+ }
+
+ $this->allChildCategories = array_replace($directChildCategories, $childCategories);
+ }
+
+ return $this->allChildCategories;
+ }
+
/**
* Returns the parent category of the category or `null` if the category has no parent category.
*
* @package WoltLabSuite\Core\Data\Smiley\Category
*
* @method SmileyCategory[] getChildCategories()
+ * @method SmileyCategory[] getAllChildCategories()
* @method SmileyCategory getParentCategory()
* @method SmileyCategory[] getParentCategories()
* @method static SmileyCategory|null getCategory($categoryID)