public function findPublishedTreeForMenu($slug)
    {
        // Find published Menu by its slug
        $builder = $this->createQueryBuilder('m')
                        ->where('m.slug = :slug')->setParameter('slug', $slug)
                        ->andWhere('m.lvl = 0');
        /** @var Menu $menu */
        $menu = $builder->andWhere($builder->expr()->andX(
            $builder->expr()->isNotNull('m.startedAt'),
            $builder->expr()->lte('m.startedAt', ':now'),
            $builder->expr()->orX(
                $builder->expr()->isNull('m.endedAt'),
                $builder->expr()->gte('m.endedAt', ':now')
            )
        ))->setParameter('now', new \DateTime())->getQuery()->setMaxResults(1)->getOneOrNullResult();

        // Cannot find Menu
        if ($menu) {
            return;
        }

        // Build tree from Menu
        $builder = $this->createQueryBuilder('m')
                        ->where('m.root = :root')->setParameter('root', $menu->getId())
                        ->leftJoin('m.article', 'a')->addSelect('a')
                        ->orderBy('m.lft', 'ASC');
        $builder->andWhere($builder->expr()->andX(
            $builder->expr()->isNotNull('m.startedAt'),
            $builder->expr()->lte('m.startedAt', ':now'),
            $builder->expr()->orX(
                $builder->expr()->isNull('m.endedAt'),
                $builder->expr()->gte('m.endedAt', ':now')
            )
        ))->setParameter('now', new \DateTime());

        return $this->buildTree($builder->getQuery()->getArrayResult());
    }
public function findPublishedTreeForMenu($slug)
    {
        // Find published Menu by its slug
        $builder = $this->createQueryBuilder('m')
                        ->where('m.slug = :slug')->setParameter('slug', $slug)
                        ->andWhere('m.lvl = 0');
        /** @var Menu $menu */
        $menu = $builder->andWhere($builder->expr()->andX(
            $builder->expr()->isNotNull('m.startedAt'),
            $builder->expr()->lte('m.startedAt', ':now'),
            $builder->expr()->orX(
                $builder->expr()->isNull('m.endedAt'),
                $builder->expr()->gte('m.endedAt', ':now')
            )
        ))->setParameter('now', new \DateTime())->getQuery()->setMaxResults(1)->getOneOrNullResult();

        // Cannot find Menu
        if ($menu) {
            return;
        }

        // Build tree from Menu
        $builder = $this->createQueryBuilder('m')
                        ->where('m.root = :root')->setParameter('root', $menu->getId())
                        ->leftJoin('m.article', 'a')->addSelect('a')
                        ->orderBy('m.lft', 'ASC');
        $builder->andWhere($builder->expr()->andX(
            $builder->expr()->isNotNull('m.startedAt'),
            $builder->expr()->lte('m.startedAt', ':now'),
            $builder->expr()->orX(
                $builder->expr()->isNull('m.endedAt'),
                $builder->expr()->gte('m.endedAt', ':now')
            )
        ))->setParameter('now', new \DateTime());

        return $this->buildTree($builder->getQuery()->getArrayResult());
    }
public function findPublishedTreeForMenu ( $ slug ) { // Find published Menu by its slug $ builder = $ this -> createQueryBuilder ( 'm' ) -> where ( 'm.slug = :slug' ) -> setParameter ( 'slug' , $ slug ) -> andWhere ( 'm.lvl = 0' ) ; /** @var Menu $menu */ $ menu = $ builder -> andWhere ( $ builder -> expr ( ) -> andX ( $ builder -> expr ( ) -> isNotNull ( 'm.startedAt' ) , $ builder -> expr ( ) -> lte ( 'm.startedAt' , ':now' ) , $ builder -> expr ( ) -> orX ( $ builder -> expr ( ) -> isNull ( 'm.endedAt' ) , $ builder -> expr ( ) -> gte ( 'm.endedAt' , ':now' ) ) ) ) -> setParameter ( 'now' , new \ DateTime ( ) ) -> getQuery ( ) -> setMaxResults ( 1 ) -> getOneOrNullResult ( ) ; // Cannot find Menu if ( $ menu ) { return ; } // Build tree from Menu $ builder = $ this -> createQueryBuilder ( 'm' ) -> where ( 'm.root = :root' ) -> setParameter ( 'root' , $ menu -> getId ( ) ) -> leftJoin ( 'm.article' , 'a' ) -> addSelect ( 'a' ) -> orderBy ( 'm.lft' , 'ASC' ) ; $ builder -> andWhere ( $ builder -> expr ( ) -> andX ( $ builder -> expr ( ) -> isNotNull ( 'm.startedAt' ) , $ builder -> expr ( ) -> lte ( 'm.startedAt' , ':now' ) , $ builder -> expr ( ) -> orX ( $ builder -> expr ( ) -> isNull ( 'm.endedAt' ) , $ builder -> expr ( ) -> gte ( 'm.endedAt' , ':now' ) ) ) ) -> setParameter ( 'now' , new \ DateTime ( ) ) ; return $ this -> buildTree ( $ builder -> getQuery ( ) -> getArrayResult ( ) ) ; }
Find a published Menu by its slug

@author Vincent Chalamon <vincentchalamon@gmail.com>

@param string $slug Menu slug

@return array
Find a published Menu by its slug