[eluser]Gaz[/eluser]
Hi all,
I'm trying to do a recursive search and replace on an MPTT tree.
The code I'm using is as follows
Code:
function parse($nodes) {
foreach($nodes as &$node) {
// Replace node?
if($node['type'] == 'ReferenceNode') {
$n = $this->site->get_node_where('id', $node['node_ref']);
// Replace node with node pointed to by reference
if($n) {
$node = $this->site->get_node_where('object_id', $n['object_id']);
// Get children
$children = $this->site->get_descendants($node['lft'], $node['rgt']);
if(!empty($children)) {
$node['children'] = $this->parse($children);
}
}
}
}
return $nodes;
}
Basically the code hangs when I run it, although it looks like it should work. If I comment out
Code:
$node['children'] = $this->parse($children);
The code works fine, but obviously doesn't deal with child nodes.
Cheers,
Gaz.