Welcome Guest, Not a member yet? Register   Sign In
MPTT recursive search and replace problem
#1

[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.


Messages In This Thread
MPTT recursive search and replace problem - by El Forum - 07-02-2009, 07:18 AM
MPTT recursive search and replace problem - by El Forum - 07-04-2009, 03:50 AM
MPTT recursive search and replace problem - by El Forum - 07-14-2009, 09:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB