public function findNextSubcategory($subcategory)
    {
        $qb = $this->getQueryBuilder()
            ->select('c')
            ->where('c.id > :id')
            ->andWhere('c.parentCategory = :parentCategory')
            ->orderBy('c.id', 'asc')
            ->setMaxResults(1)
            ->setParameter('id', $subcategory->getId())
            ->setParameter('parentCategory', $subcategory->getParentCategory());

        // get the first subcategory when there is no next
        if (0 == count($qb->getQuery()->getResult())) {
            $qb->where('c.id < :id')
                ->andWhere('c.parentCategory = :parentCategory')
                ->setParameter('id', $subcategory->getId())
                ->setParameter('parentCategory', $subcategory->getParentCategory());

            if (0 == count($qb->getQuery()->getResult())) {
                return null;
            }
        }

        return $qb->getQuery()
            ->getSingleResult();
    }
public function findNextSubcategory($subcategory)
    {
        $qb = $this->getQueryBuilder()
            ->select('c')
            ->where('c.id > :id')
            ->andWhere('c.parentCategory = :parentCategory')
            ->orderBy('c.id', 'asc')
            ->setMaxResults(1)
            ->setParameter('id', $subcategory->getId())
            ->setParameter('parentCategory', $subcategory->getParentCategory());

        // get the first subcategory when there is no next
        if (0 == count($qb->getQuery()->getResult())) {
            $qb->where('c.id < :id')
                ->andWhere('c.parentCategory = :parentCategory')
                ->setParameter('id', $subcategory->getId())
                ->setParameter('parentCategory', $subcategory->getParentCategory());

            if (0 == count($qb->getQuery()->getResult())) {
                return null;
            }
        }

        return $qb->getQuery()
            ->getSingleResult();
    }
public function findNextSubcategory ( $ subcategory ) { $ qb = $ this -> getQueryBuilder ( ) -> select ( 'c' ) -> where ( 'c.id > :id' ) -> andWhere ( 'c.parentCategory = :parentCategory' ) -> orderBy ( 'c.id' , 'asc' ) -> setMaxResults ( 1 ) -> setParameter ( 'id' , $ subcategory -> getId ( ) ) -> setParameter ( 'parentCategory' , $ subcategory -> getParentCategory ( ) ) ; // get the first subcategory when there is no next if ( 0 == count ( $ qb -> getQuery ( ) -> getResult ( ) ) ) { $ qb -> where ( 'c.id < :id' ) -> andWhere ( 'c.parentCategory = :parentCategory' ) -> setParameter ( 'id' , $ subcategory -> getId ( ) ) -> setParameter ( 'parentCategory' , $ subcategory -> getParentCategory ( ) ) ; if ( 0 == count ( $ qb -> getQuery ( ) -> getResult ( ) ) ) { return null ; } } return $ qb -> getQuery ( ) -> getSingleResult ( ) ; }
Find the next subcategory, or the first one if none is found

@param Category $subcategory

@return Category|null
Find the next subcategory or the first one if none is found