* @category Community Framework
*/
class CategoryNodeTree implements \IteratorAggregate {
+ /**
+ * maximum depth considered when building the node tree.
+ *
+ * @var integer
+ */
+ protected $maxDepth = -1;
+
/**
* name of the category node class
* @var string
}
}
+ /**
+ * Sets the maximum depth considered when building the node tree, defaults
+ * to -1 which equals infinite.
+ *
+ * @param integer $maxDepth
+ */
+ public function setMaxDepth($maxDepth) {
+ $this->maxDepth = $maxDepth;
+ }
+
/**
* Builds the category node tree.
*/
protected function buildTree() {
$this->parentNode = $this->getNode($this->parentCategoryID);
- $this->buildTreeLevel($this->parentNode);
+ $this->buildTreeLevel($this->parentNode, $this->maxDepth);
}
/**
* Builds a certain level of the tree.
*
* @param \wcf\data\category\CategoryNode $parentNode
+ * @param integer $depth
*/
- protected function buildTreeLevel(CategoryNode $parentNode) {
+ protected function buildTreeLevel(CategoryNode $parentNode, $depth = 0) {
+ if ($this->maxDepth != -1 && $depth < 0) {
+ return;
+ }
+
foreach ($this->getChildCategories($parentNode) as $childCategory) {
$childNode = $this->getNode($childCategory->categoryID);