src/Repository/Beauty/Masters/BeautyMasterRepository.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Slivki\Repository\Beauty\Masters;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Slivki\Entity\BeautyMaster;
  7. use Slivki\Exception\Beauty\Master\MasterNotFoundException;
  8. final class BeautyMasterRepository extends ServiceEntityRepository implements BeautyMasterRepositoryInterface
  9. {
  10.     public function __construct(ManagerRegistry $registry)
  11.     {
  12.         parent::__construct($registryBeautyMaster::class);
  13.     }
  14.     public function getById(int $id): BeautyMaster
  15.     {
  16.         $master $this->findById($id);
  17.         if (!$master instanceof BeautyMaster) {
  18.             throw new MasterNotFoundException();
  19.         }
  20.         return $master;
  21.     }
  22.     public function findById(int $id): ?BeautyMaster
  23.     {
  24.         $queryBuilder $this->createQueryBuilder('bm');
  25.         $expr $queryBuilder->expr();
  26.         return $queryBuilder
  27.             ->andWhere($expr->eq('bm.id'':id'))
  28.             ->setParameter('id'$id)
  29.             ->getQuery()
  30.             ->getOneOrNullResult();
  31.     }
  32.     public function findByGeoLocationId(int $locationId): array
  33.     {
  34.         $qb $this->createQueryBuilder('bm');
  35.         $expr $qb->expr();
  36.         return $qb
  37.             ->innerJoin('bm.locations''l')
  38.             ->andWhere($expr->eq('l.ID'':locationId'))
  39.             ->addOrderBy($expr->asc('bm.id'))
  40.             ->setParameters([
  41.                 'locationId' => $locationId,
  42.             ])
  43.             ->getQuery()
  44.             ->getResult();
  45.     }
  46.     public function findByGeoLocationIds(array $locationIds): array
  47.     {
  48.         $qb $this->createQueryBuilder('bm');
  49.         $expr $qb->expr();
  50.         return $qb
  51.             ->innerJoin('bm.locations''l')
  52.             ->andWhere($expr->in('l.ID'':locationIds'))
  53.             ->addGroupBy('bm.id')
  54.             ->addOrderBy($expr->asc('bm.id'))
  55.             ->setParameters([
  56.                 'locationIds' => $locationIds,
  57.             ])
  58.             ->getQuery()
  59.             ->getResult();
  60.     }
  61.     public function findByCategoryId(int $categoryId): array
  62.     {
  63.         $qb $this->createQueryBuilder('bm');
  64.         $expr $qb->expr();
  65.         return $qb
  66.             ->innerJoin('bm.categories''c')
  67.             ->andWhere($expr->eq('c.ID'':categoryId'))
  68.             ->addOrderBy($expr->asc('bm.id'))
  69.             ->setParameters([
  70.                 'categoryId' => $categoryId,
  71.             ])
  72.             ->getQuery()
  73.             ->getResult();
  74.     }
  75. }