public function fetchTreeAsArray($rootId=null, $depth=null)
    {
        $config = $this->getConfiguration();
        $lftField = $config->getLeftFieldName();
        $rgtField = $config->getRightFieldName();
        $rootField = $config->getRootFieldName();
        $hasManyRoots = $config->hasManyRoots();

        if($rootId === null && $rootField !== null)
        {
            throw new \InvalidArgumentException('Must provide root id');
        }

        if($depth === 0)
        {
            return array();
        }

        $qb = $config->getBaseQueryBuilder();
        $alias = $config->getQueryBuilderAlias();

        $qb->andWhere("$alias.$lftField >= :lowerbound")
            ->setParameter('lowerbound', 1)
            ->orderBy("$alias.$lftField", "ASC");

        if($hasManyRoots)
        {
            $qb->andWhere("$alias.$rootField = :rootid")
                ->setParameter('rootid', $rootId);
        }
		
		$q = $qb->getQuery();
		if ($this->config->isQueryHintSet()){
			$q = $this->addHintToQuery($q);
		}
        $nodes = $q->execute();
		
        if(empty($nodes))
        {
            return array();
        }

        // TODO: Filter depth using a cross join instead of this
        if($depth !== null)
        {
            $nodes = $this->filterNodeDepth($nodes, $depth);
        }

        $wrappers = array();
        foreach($nodes as $node)
        {
            $wrappers[] = $this->wrapNode($node);
        }

        $this->buildTree($wrappers);

        return $wrappers;
    }
public function fetchTreeAsArray($rootId=null, $depth=null)
    {
        $config = $this->getConfiguration();
        $lftField = $config->getLeftFieldName();
        $rgtField = $config->getRightFieldName();
        $rootField = $config->getRootFieldName();
        $hasManyRoots = $config->hasManyRoots();

        if($rootId === null && $rootField !== null)
        {
            throw new \InvalidArgumentException('Must provide root id');
        }

        if($depth === 0)
        {
            return array();
        }

        $qb = $config->getBaseQueryBuilder();
        $alias = $config->getQueryBuilderAlias();

        $qb->andWhere("$alias.$lftField >= :lowerbound")
            ->setParameter('lowerbound', 1)
            ->orderBy("$alias.$lftField", "ASC");

        if($hasManyRoots)
        {
            $qb->andWhere("$alias.$rootField = :rootid")
                ->setParameter('rootid', $rootId);
        }
		
		$q = $qb->getQuery();
		if ($this->config->isQueryHintSet()){
			$q = $this->addHintToQuery($q);
		}
        $nodes = $q->execute();
		
        if(empty($nodes))
        {
            return array();
        }

        // TODO: Filter depth using a cross join instead of this
        if($depth !== null)
        {
            $nodes = $this->filterNodeDepth($nodes, $depth);
        }

        $wrappers = array();
        foreach($nodes as $node)
        {
            $wrappers[] = $this->wrapNode($node);
        }

        $this->buildTree($wrappers);

        return $wrappers;
    }
public function fetchTreeAsArray ( $ rootId = null , $ depth = null ) { $ config = $ this -> getConfiguration ( ) ; $ lftField = $ config -> getLeftFieldName ( ) ; $ rgtField = $ config -> getRightFieldName ( ) ; $ rootField = $ config -> getRootFieldName ( ) ; $ hasManyRoots = $ config -> hasManyRoots ( ) ; if ( $ rootId === null && $ rootField !== null ) { throw new \ InvalidArgumentException ( 'Must provide root id' ) ; } if ( $ depth === 0 ) { return array ( ) ; } $ qb = $ config -> getBaseQueryBuilder ( ) ; $ alias = $ config -> getQueryBuilderAlias ( ) ; $ qb -> andWhere ( "$alias.$lftField >= :lowerbound" ) -> setParameter ( 'lowerbound' , 1 ) -> orderBy ( "$alias.$lftField" , "ASC" ) ; if ( $ hasManyRoots ) { $ qb -> andWhere ( "$alias.$rootField = :rootid" ) -> setParameter ( 'rootid' , $ rootId ) ; } $ q = $ qb -> getQuery ( ) ; if ( $ this -> config -> isQueryHintSet ( ) ) { $ q = $ this -> addHintToQuery ( $ q ) ; } $ nodes = $ q -> execute ( ) ; if ( empty ( $ nodes ) ) { return array ( ) ; } // TODO: Filter depth using a cross join instead of this if ( $ depth !== null ) { $ nodes = $ this -> filterNodeDepth ( $ nodes , $ depth ) ; } $ wrappers = array ( ) ; foreach ( $ nodes as $ node ) { $ wrappers [ ] = $ this -> wrapNode ( $ node ) ; } $ this -> buildTree ( $ wrappers ) ; return $ wrappers ; }
Fetches the complete tree, returning a flat array of node wrappers with
parent, children, ancestors and descendants pre-populated.

@param mixed $rootId the root id of the tree (or null if model doesn't
support multiple trees
@param int $depth the depth to retrieve or null for unlimited

@return array
Fetches the complete tree returning a flat array of node wrappers with parent children ancestors and descendants pre - populated .