/** * Loads all children of the given tree item list recursively. * * @param TreeItem[] $treeItems A list of tree items to load it's children. * @param array $compositions The compositions list to load the children from. * @param string $compositionName The name of the relation. * @param TreeItem $parentItem The parent TreeItem. * @param int $maxDepth The maximum depth of the tree. * @param int $depth The actual depth of the tree. * * @return TreeItem[] A list of tree items of the actual node. * * @author Nicolas Pecher * @version * Version 0.1. 23.04.2012 */ protected function loadChildTreeItems(array $treeItems, array $compositions, $compositionName, TreeItem $parentItem, $maxDepth, $depth = 0) { $layer = []; if ($maxDepth === 0 || $depth <= $maxDepth) { foreach ($treeItems as $treeItem) { foreach ($compositions as $composition) { if ($composition[$this->relationTable[$compositionName]['TargetID']] === $treeItem->getObjectId() && $composition[$this->relationTable[$compositionName]['SourceID']] === $parentItem->getObjectId()) { $cDepth = $depth + 1; $childItems = $this->loadChildTreeItems($treeItems, $compositions, $compositionName, $treeItem, $maxDepth, $cDepth); $treeItem->setParentItem($parentItem); $treeItem->addChildren($childItems); $layer[] = $treeItem; break; } } } } return $layer; }