src/Repository/ProfileTopPlacementRepository.php line 36

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-04-25
  5.  * Time: 13:39
  6.  */
  7. namespace App\Repository;
  8. use App\Entity\Location\City;
  9. use App\Entity\Profile\Profile;
  10. use App\Entity\Sales\Profile\TopPlacement;
  11. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. use Happyr\DoctrineSpecification\Filter\Filter;
  14. class ProfileTopPlacementRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registryTopPlacement::class);
  19.     }
  20.     public function getCurrentlyPlaced(City $city\DateTimeInterface $currentTime): ?Profile
  21.     {
  22.         $qb $this->createQueryBuilder('top_profile_placement')
  23.             ->select('top_profile_placement, profile'//, photo
  24.             ->join('top_profile_placement.profile''profile')
  25. //            ->join('profile.photos', 'photo')
  26.             ->andWhere('profile.city = :city')
  27.             ->andWhere('top_profile_placement.placedAt <= :currentTime AND :currentTime < top_profile_placement.expiresAt')
  28.             ->setParameter('city'$city->getId())
  29.             ->setParameter('currentTime'$currentTime)
  30.             ->setMaxResults(1);
  31.         ;
  32.         $placement $qb->getQuery()->getOneOrNullResult();
  33.         return $placement $placement->getProfile() : null;
  34.     }
  35.     public function getCurrentlyPlacedAndSatisfiedBy(City $city\DateTimeInterface $currentTime, ?Filter $spec null): ?Profile
  36.     {
  37.         $qb $this->createQueryBuilder($dqlAlias 'top_profile_placement')
  38.             ->select('top_profile_placement, profile'//, photo
  39.             ->join('top_profile_placement.profile''profile')
  40. //            ->join('profile.photos', 'photo')
  41.             ->andWhere('profile.city = :city')
  42.             ->andWhere(':currentTime BETWEEN top_profile_placement.placedAt AND top_profile_placement.expiresAt')
  43.             ->setParameter('city'$city->getId())
  44.             ->setParameter('currentTime'$currentTime)
  45.             ->setMaxResults(1);
  46.         if (null !== $spec) {
  47.             $qb->andWhere($spec->getFilter($qb$dqlAlias));
  48.         }
  49.         $placement $qb->getQuery()->getOneOrNullResult();
  50.         return $placement $placement->getProfile() : null;
  51.     }
  52.     public function getPlacementsByPeriod(City $city\DateTimeInterface $dateStart\DateTimeInterface $dateEnd): array
  53.     {
  54.         $qb $this->createQueryBuilder('top')
  55.             ->andWhere('top.city = :city')
  56.             ->setParameter('city'$city->getId())
  57.         ;
  58. /*
  59.         $orX = $qb->expr()->orX(
  60.             'top.placedAt <= :dateStart AND :dateStart < top.expiresAt',
  61.             'top.placedAt < :dateEnd AND :dateEnd <= top.expiresAt',
  62.             ':dateStart <= top.placedAt AND top.placedAt < :dateEnd',
  63.             ':dateStart < top.expiresAt AND top.expiresAt <= :dateEnd'
  64.         );
  65. */
  66.         $orX $qb->expr()->orX(
  67.             ':dateStart <= top.placedAt AND top.placedAt < :dateEnd',
  68.             ':dateStart < top.expiresAt AND top.expiresAt <= :dateEnd',
  69.             'top.placedAt <= :dateStart AND :dateEnd <= top.expiresAt',
  70.         );
  71.         $qb->andWhere($orX)
  72.             ->setParameter('dateStart'$dateStart)
  73.             ->setParameter('dateEnd'$dateEnd)
  74.         ;
  75.         return $qb->getQuery()->getResult();
  76.     }
  77. }