Controller/NodeController.php
private function getTreeQueryAsArray(\Doctrine\ORM\Query $query)
    {
        $items = array();
        $index = array();

        $nodes = $query->getResult();
        $count = count($nodes);

        for($i = 0; $i < $count; $i++)
        {
            $node = $nodes[$i];

            $newItem = array(
                'id'     => $node->getId(),
                'name'   => $node->getName(),
                'slug'   => $node->getSlug()
            );
            if($i == 0)
            {
                //for first item - parent of the subtree - add tree_ params
                $newItem = array_merge($this->getParentTreeParams($node), $newItem);
            }
            foreach ($node->getNodeAttributes() as $attribute) {
                $newItem[$attribute->getName()] = $attribute->getValue();
            }

            if(($node->getParent()) && isset($index[$node->getParent()->getId()]))
            {
                $_path = $index[$node->getParent()->getId()];
                eval('$parent = &$items' . $_path . ';');
                if(!isset($parent['items']))
                {
                    $parent['items'] = array();
                }
                //copy tree_ params
                foreach ($parent as $paramKey => $paramValue)
                {
                    if(substr($paramKey, 0, 5) == 'tree_')
                    {
                        $newItem[$paramKey] = $paramValue;
                    }
                }
                $index[$node->getId()] = $_path . '["items"][' . count($parent['items']) . ']';
                $parent['items'][] = $newItem;
            }
            else
            {
                $index[$node->getId()] = '[' . count($items) . ']';
                $items[] = $newItem;
            }
        }

        return $items;
    }
private function getTreeQueryAsArray(\Doctrine\ORM\Query $query)
    {
        $items = array();
        $index = array();

        $nodes = $query->getResult();
        $count = count($nodes);

        for($i = 0; $i < $count; $i++)
        {
            $node = $nodes[$i];

            $newItem = array(
                'id'     => $node->getId(),
                'name'   => $node->getName(),
                'slug'   => $node->getSlug()
            );
            if($i == 0)
            {
                //for first item - parent of the subtree - add tree_ params
                $newItem = array_merge($this->getParentTreeParams($node), $newItem);
            }
            foreach ($node->getNodeAttributes() as $attribute) {
                $newItem[$attribute->getName()] = $attribute->getValue();
            }

            if(($node->getParent()) && isset($index[$node->getParent()->getId()]))
            {
                $_path = $index[$node->getParent()->getId()];
                eval('$parent = &$items' . $_path . ';');
                if(!isset($parent['items']))
                {
                    $parent['items'] = array();
                }
                //copy tree_ params
                foreach ($parent as $paramKey => $paramValue)
                {
                    if(substr($paramKey, 0, 5) == 'tree_')
                    {
                        $newItem[$paramKey] = $paramValue;
                    }
                }
                $index[$node->getId()] = $_path . '["items"][' . count($parent['items']) . ']';
                $parent['items'][] = $newItem;
            }
            else
            {
                $index[$node->getId()] = '[' . count($items) . ']';
                $items[] = $newItem;
            }
        }

        return $items;
    }
private function getTreeQueryAsArray ( \ Doctrine \ ORM \ Query $ query ) { $ items = array ( ) ; $ index = array ( ) ; $ nodes = $ query -> getResult ( ) ; $ count = count ( $ nodes ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ node = $ nodes [ $ i ] ; $ newItem = array ( 'id' => $ node -> getId ( ) , 'name' => $ node -> getName ( ) , 'slug' => $ node -> getSlug ( ) ) ; if ( $ i == 0 ) { //for first item - parent of the subtree - add tree_ params $ newItem = array_merge ( $ this -> getParentTreeParams ( $ node ) , $ newItem ) ; } foreach ( $ node -> getNodeAttributes ( ) as $ attribute ) { $ newItem [ $ attribute -> getName ( ) ] = $ attribute -> getValue ( ) ; } if ( ( $ node -> getParent ( ) ) && isset ( $ index [ $ node -> getParent ( ) -> getId ( ) ] ) ) { $ _path = $ index [ $ node -> getParent ( ) -> getId ( ) ] ; eval ( '$parent = &$items' . $ _path . ';' ) ; if ( ! isset ( $ parent [ 'items' ] ) ) { $ parent [ 'items' ] = array ( ) ; } //copy tree_ params foreach ( $ parent as $ paramKey => $ paramValue ) { if ( substr ( $ paramKey , 0 , 5 ) == 'tree_' ) { $ newItem [ $ paramKey ] = $ paramValue ; } } $ index [ $ node -> getId ( ) ] = $ _path . '["items"][' . count ( $ parent [ 'items' ] ) . ']' ; $ parent [ 'items' ] [ ] = $ newItem ; } else { $ index [ $ node -> getId ( ) ] = '[' . count ( $ items ) . ']' ; $ items [ ] = $ newItem ; } } return $ items ; }
Returns doctrine query nested set as an array for json

@param  DoctrineORMQuery $query Nested set tree query
@return array                   Result as array for json
Returns doctrine query nested set as an array for json