src/Repository/ProfileTopPlacementRepository.php line 35

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. class ProfileTopPlacementRepository extends ServiceEntityRepository
  14. {
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registryTopPlacement::class);
  18.     }
  19.     public function getCurrentlyPlaced(City $city\DateTimeInterface $currentTime): ?Profile
  20.     {
  21.         $qb $this->createQueryBuilder('top_profile_placement')
  22.             ->select('top_profile_placement, profile'//, photo
  23.             ->join('top_profile_placement.profile''profile')
  24. //            ->join('profile.photos', 'photo')
  25.             ->andWhere('profile.city = :city')
  26.             ->andWhere('top_profile_placement.placedAt <= :currentTime AND :currentTime < top_profile_placement.expiresAt')
  27.             ->setParameter('city'$city->getId())
  28.             ->setParameter('currentTime'$currentTime)
  29.             ->setMaxResults(1);
  30.         ;
  31.         $placement $qb->getQuery()->getOneOrNullResult();
  32.         return $placement $placement->getProfile() : null;
  33.     }
  34.     public function getPlacementsByPeriod(City $city\DateTimeInterface $dateStart\DateTimeInterface $dateEnd): array
  35.     {
  36.         $qb $this->createQueryBuilder('top')
  37.             ->andWhere('top.city = :city')
  38.             ->setParameter('city'$city->getId())
  39.         ;
  40.         $orX $qb->expr()->orX(
  41.             'top.placedAt <= :dateStart AND :dateStart < top.expiresAt',
  42.             'top.placedAt < :dateEnd AND :dateEnd <= top.expiresAt',
  43.             ':dateStart <= top.placedAt AND top.placedAt < :dateEnd',
  44.             ':dateStart < top.expiresAt AND top.expiresAt <= :dateEnd'
  45.         );
  46.         $qb->andWhere($orX)
  47.             ->setParameter('dateStart'$dateStart)
  48.             ->setParameter('dateEnd'$dateEnd)
  49.         ;
  50.         return $qb->getQuery()->getResult();
  51.     }
  52. }