src/Paginator/Beauty/Master/MasterPaginator.php line 48

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Slivki\Paginator\Beauty\Master;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Knp\Component\Pager\Pagination\PaginationInterface;
  6. use Knp\Component\Pager\PaginatorInterface;
  7. use Slivki\Entity\BeautyMaster;
  8. use Slivki\Entity\GeoLocation;
  9. use Slivki\Message\Query\Beauty\Category\GetMastersWithFilterQuery as GetMastersWithFilterQueryForCategory;
  10. use Slivki\Message\Query\Beauty\Offer\GetMastersWithFilterQuery as GetMastersWithFilterQueryForOffer;
  11. final class MasterPaginator implements MasterPaginatorInterface
  12. {
  13.     private EntityManagerInterface $entityManager;
  14.     private PaginatorInterface $paginator;
  15.     public function __construct(
  16.         EntityManagerInterface $entityManager,
  17.         PaginatorInterface $paginator
  18.     ) {
  19.         $this->entityManager $entityManager;
  20.         $this->paginator $paginator;
  21.     }
  22.     public function findAllMasterForOfferQueryByFilter(GetMastersWithFilterQueryForOffer $query): PaginationInterface
  23.     {
  24.         $queryBuilder $this->entityManager->createQueryBuilder();
  25.         $expr $queryBuilder->expr();
  26.         $locationIdsSubQuery $this->entityManager->createQueryBuilder()
  27.             ->addSelect('gl.ID')
  28.             ->from(GeoLocation::class, 'gl')
  29.             ->innerJoin('gl.offers''o')
  30.             ->andWhere($expr->eq('o.ID'':offerId'));
  31.         $queryBuilder
  32.             ->addSelect('bm')
  33.             ->from(BeautyMaster::class, 'bm')
  34.             ->innerJoin('bm.locations''l')
  35.             ->andWhere($expr->in('l.ID'$locationIdsSubQuery->getDQL()))
  36.             ->addGroupBy('bm.id')
  37.             ->addOrderBy($expr->asc('bm.id'))
  38.             ->setParameter('offerId'$query->getOfferId());
  39.         return $this->paginator->paginate($queryBuilder->getQuery(), $query->getPage(), $query->getPerPage());
  40.     }
  41.     public function findAllMasterForCategoryQueryByFilter(GetMastersWithFilterQueryForCategory $query): PaginationInterface
  42.     {
  43.         $queryBuilder $this->entityManager->createQueryBuilder();
  44.         $expr $queryBuilder->expr();
  45.         $queryBuilder
  46.             ->addSelect('bm')
  47.             ->from(BeautyMaster::class, 'bm')
  48.             ->innerJoin('bm.categories''c')
  49.             ->innerJoin('bm.locations''l')
  50.             ->innerJoin('l.offers''o')
  51.             ->andWhere($expr->eq('c.ID'':categoryId'))
  52.             ->andWhere($expr->eq('o.active'':offerActive'))
  53.             ->andWhere($expr->eq('o.hidden'':offerHidden'))
  54.             ->andWhere($expr->between('current_timestamp()''o.activeSince''o.activeTill'))
  55.             ->addOrderBy($expr->asc('bm.id'))
  56.             ->setParameters([
  57.                 'categoryId' => $query->getCategoryId(),
  58.                 'offerActive' => true,
  59.                 'offerHidden' => false,
  60.             ]);
  61.         return $this->paginator->paginate($queryBuilder->getQuery(), $query->getPage(), $query->getPerPage());
  62.     }
  63. }