vendor/sulu/sulu/src/Sulu/Bundle/RouteBundle/Entity/RouteRepository.php line 36

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\RouteBundle\Entity;
  11. use Doctrine\ORM\NoResultException;
  12. use Sulu\Bundle\RouteBundle\Model\RouteInterface;
  13. use Sulu\Component\Persistence\Repository\ORM\EntityRepository;
  14. /**
  15.  * Contains special queries to find routes.
  16.  *
  17.  * @extends EntityRepository<RouteInterface>
  18.  */
  19. class RouteRepository extends EntityRepository implements RouteRepositoryInterface
  20. {
  21.     public function findByPath($path$locale)
  22.     {
  23.         $query $this->createQueryBuilder('entity')
  24.             ->addSelect('target')
  25.             ->leftJoin('entity.target''target')
  26.             ->andWhere('entity.path = :path')
  27.             ->andWhere('entity.locale = :locale')
  28.             ->getQuery()
  29.             ->setParameters(['path' => $path'locale' => $locale]);
  30.         try {
  31.             return $query->getSingleResult();
  32.         } catch (NoResultException $e) {
  33.             return;
  34.         }
  35.     }
  36.     public function findByEntity($entityClass$entityId$locale)
  37.     {
  38.         $query $this->createQueryBuilder('entity')
  39.             ->andWhere('entity.entityClass = :entityClass')
  40.             ->andWhere('entity.entityId = :entityId')
  41.             ->andWhere('entity.locale = :locale')
  42.             ->andWhere('entity.history = false')
  43.             ->getQuery()
  44.             ->setParameters(['entityClass' => $entityClass'entityId' => $entityId'locale' => $locale]);
  45.         try {
  46.             return $query->getSingleResult();
  47.         } catch (NoResultException $e) {
  48.             return;
  49.         }
  50.     }
  51.     public function findHistoryByEntity($entityClass$entityId$locale)
  52.     {
  53.         $query $this->createQueryBuilder('entity')
  54.             ->andWhere('entity.entityClass = :entityClass')
  55.             ->andWhere('entity.entityId = :entityId')
  56.             ->andWhere('entity.locale = :locale')
  57.             ->andWhere('entity.history = true')
  58.             ->getQuery()
  59.             ->setParameters(['entityClass' => $entityClass'entityId' => $entityId'locale' => $locale]);
  60.         return $query->getResult();
  61.     }
  62.     public function findAllByEntity($entityClass$entityId$locale null)
  63.     {
  64.         $queryBuilder $this->createQueryBuilder('entity')
  65.             ->andWhere('entity.entityClass = :entityClass')
  66.             ->andWhere('entity.entityId = :entityId')
  67.             ->setParameters(['entityClass' => $entityClass'entityId' => $entityId]);
  68.         if ($locale) {
  69.             $queryBuilder
  70.                 ->andWhere('entity.locale = :locale')
  71.                 ->setParameter('locale'$locale);
  72.         }
  73.         return $queryBuilder->getQuery()->getResult();
  74.     }
  75.     public function persist(RouteInterface $route)
  76.     {
  77.         $this->getEntityManager()->persist($route);
  78.     }
  79.     public function remove(RouteInterface $route)
  80.     {
  81.         $this->getEntityManager()->remove($route);
  82.     }
  83. }