public function findByLevels($levels = 1, $ids = array())
    {
        $query = $this->createQueryBuilder('c');

        if ($levels > 0) {
            $selects = ['c'];
            for ($i = 1; $i <= $levels; ++$i) {
                $selects[] = 'c'.$i;
            }

            $query->select($selects);

            for ($i = 1; $i <= $levels; ++$i) {
                $previous = ($i - 1 == 0) ? '' : ($i - 1);
                $query->leftJoin('c'.$previous.'.children', 'c'.$i, 'WITH', 'c'.$i.'.active = :active AND c'.$i.'.showInNavigation = :show');
            }
        }

        if ($ids) {
            $query->andWhere('c.id IN (:ids)')->setParameter('ids', $ids);
        } else {
            $query->andWhere('c.parent IS NULL');
        }

        $query->andWhere('c.active = :active')->setParameter('active', true);
        $query->andWhere('c.layout = :layout')->setParameter('layout', false);
        $query->andWhere('c.showInNavigation = :show')->setParameter('show', true);

        return $query->getQuery()->getResult();
    }
public function findByLevels($levels = 1, $ids = array())
    {
        $query = $this->createQueryBuilder('c');

        if ($levels > 0) {
            $selects = ['c'];
            for ($i = 1; $i <= $levels; ++$i) {
                $selects[] = 'c'.$i;
            }

            $query->select($selects);

            for ($i = 1; $i <= $levels; ++$i) {
                $previous = ($i - 1 == 0) ? '' : ($i - 1);
                $query->leftJoin('c'.$previous.'.children', 'c'.$i, 'WITH', 'c'.$i.'.active = :active AND c'.$i.'.showInNavigation = :show');
            }
        }

        if ($ids) {
            $query->andWhere('c.id IN (:ids)')->setParameter('ids', $ids);
        } else {
            $query->andWhere('c.parent IS NULL');
        }

        $query->andWhere('c.active = :active')->setParameter('active', true);
        $query->andWhere('c.layout = :layout')->setParameter('layout', false);
        $query->andWhere('c.showInNavigation = :show')->setParameter('show', true);

        return $query->getQuery()->getResult();
    }
public function findByLevels ( $ levels = 1 , $ ids = array ( ) ) { $ query = $ this -> createQueryBuilder ( 'c' ) ; if ( $ levels > 0 ) { $ selects = [ 'c' ] ; for ( $ i = 1 ; $ i <= $ levels ; ++ $ i ) { $ selects [ ] = 'c' . $ i ; } $ query -> select ( $ selects ) ; for ( $ i = 1 ; $ i <= $ levels ; ++ $ i ) { $ previous = ( $ i - 1 == 0 ) ? '' : ( $ i - 1 ) ; $ query -> leftJoin ( 'c' . $ previous . '.children' , 'c' . $ i , 'WITH' , 'c' . $ i . '.active = :active AND c' . $ i . '.showInNavigation = :show' ) ; } } if ( $ ids ) { $ query -> andWhere ( 'c.id IN (:ids)' ) -> setParameter ( 'ids' , $ ids ) ; } else { $ query -> andWhere ( 'c.parent IS NULL' ) ; } $ query -> andWhere ( 'c.active = :active' ) -> setParameter ( 'active' , true ) ; $ query -> andWhere ( 'c.layout = :layout' ) -> setParameter ( 'layout' , false ) ; $ query -> andWhere ( 'c.showInNavigation = :show' ) -> setParameter ( 'show' , true ) ; return $ query -> getQuery ( ) -> getResult ( ) ; }
Joins and selects the toplevel content items and its children recursively.

@param int $levels

@return array
Joins and selects the toplevel content items and its children recursively .