src/Kunstmaan/NodeBundle/Repository/NodeTranslationRepository.php
private function getNodeTranslationForSlugPart(
        NodeTranslation $parentNode = null,
        $slugPart = ''
    ) {
        $qb = $this->createQueryBuilder('t')
            ->select('t', 'v', 'n')
            ->innerJoin('t.node', 'n', 'WITH', 't.node = n.id')
            ->leftJoin(
                't.publicNodeVersion',
                'v',
                'WITH',
                't.publicNodeVersion = v.id'
            )
            ->where('n.deleted != 1')
            ->setFirstResult(0)
            ->setMaxResults(1);

        if ($parentNode !== null) {
            $qb->andWhere('t.slug = :slug')
                ->andWhere('n.parent = :parent')
                ->setParameter('slug', $slugPart)
                ->setParameter('parent', $parentNode->getNode()->getId());
        } else {
            /* if parent is null we should look for slugs that have no parent */
            $qb->andWhere('n.parent IS NULL');
            if (empty($slugPart)) {
                $qb->andWhere('t.slug is NULL');
            } else {
                $qb->andWhere('t.slug = :slug');
                $qb->setParameter('slug', $slugPart);
            }
        }

        return $qb->getQuery()->getOneOrNullResult();
    }
private function getNodeTranslationForSlugPart(
        NodeTranslation $parentNode = null,
        $slugPart = ''
    ) {
        $qb = $this->createQueryBuilder('t')
            ->select('t', 'v', 'n')
            ->innerJoin('t.node', 'n', 'WITH', 't.node = n.id')
            ->leftJoin(
                't.publicNodeVersion',
                'v',
                'WITH',
                't.publicNodeVersion = v.id'
            )
            ->where('n.deleted != 1')
            ->setFirstResult(0)
            ->setMaxResults(1);

        if ($parentNode !== null) {
            $qb->andWhere('t.slug = :slug')
                ->andWhere('n.parent = :parent')
                ->setParameter('slug', $slugPart)
                ->setParameter('parent', $parentNode->getNode()->getId());
        } else {
            /* if parent is null we should look for slugs that have no parent */
            $qb->andWhere('n.parent IS NULL');
            if (empty($slugPart)) {
                $qb->andWhere('t.slug is NULL');
            } else {
                $qb->andWhere('t.slug = :slug');
                $qb->setParameter('slug', $slugPart);
            }
        }

        return $qb->getQuery()->getOneOrNullResult();
    }
private function getNodeTranslationForSlugPart ( NodeTranslation $ parentNode = null , $ slugPart = '' ) { $ qb = $ this -> createQueryBuilder ( 't' ) -> select ( 't' , 'v' , 'n' ) -> innerJoin ( 't.node' , 'n' , 'WITH' , 't.node = n.id' ) -> leftJoin ( 't.publicNodeVersion' , 'v' , 'WITH' , 't.publicNodeVersion = v.id' ) -> where ( 'n.deleted != 1' ) -> setFirstResult ( 0 ) -> setMaxResults ( 1 ) ; if ( $ parentNode !== null ) { $ qb -> andWhere ( 't.slug = :slug' ) -> andWhere ( 'n.parent = :parent' ) -> setParameter ( 'slug' , $ slugPart ) -> setParameter ( 'parent' , $ parentNode -> getNode ( ) -> getId ( ) ) ; } else { /* if parent is null we should look for slugs that have no parent */ $ qb -> andWhere ( 'n.parent IS NULL' ) ; if ( empty ( $ slugPart ) ) { $ qb -> andWhere ( 't.slug is NULL' ) ; } else { $ qb -> andWhere ( 't.slug = :slug' ) ; $ qb -> setParameter ( 'slug' , $ slugPart ) ; } } return $ qb -> getQuery ( ) -> getOneOrNullResult ( ) ; }
Returns the node translation for a given slug

@param NodeTranslation|null $parentNode The parentNode
@param string               $slugPart   The slug part

@return NodeTranslation|null
Returns the node translation for a given slug