Hi all.
I have a headscratcher - that I just cannot finish. An overview:
I have root tree object that could potentially could have many number of child objects, (a tree view) and need to generate a tree from this structure as a view onto the model.
I have an object called an $Entity that has a method getChildren() which returns a $Collection (which is basically an object that encapsulates an array of child Entities and provides convenience methods al la java to iterate over them.
I also have Node objects that are used to generate the view onto this tree, basically we create Node objects for every Entity object, and then use Node->addSubnode($Entity->getId(),$Entity->getName()) where we have deemed to have a child Entity of an Entity.
My attempt so far uses recursion, but will only generate a tree one level deep! Can anyone have a look and see where i may be going wrong?
function addChildrenToTreeAgain($EntityIn,$treenode=null){
//create a tree node based on the current entity
if($treenode==null)
{
$treenode = new NtNode($EntityIn->getId(), '', $EntityIn->getDisplayName(), 'folder', '');
//$this->rootnode &= $treenode;
}
$ChildCollection = $EntityIn->getChildren();
//iterate throught the child entities
while($ChildCollection->hasNext()==true)
{
$ChildEntity = $ChildCollection->next();
$childNode = new NtNode($ChildEntity->getId(), '', $ChildEntity->getDisplayName(), 'folder', '');
$treenode->addSubnode($childNode);
$this->addChildrenToTreeAgain($ChildEntity,$childNode);
}
}