src/Repository/AppointmentRepository.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Appointment;
  4. class AppointmentRepository extends BaseRepository
  5. {
  6.     public function getListByDateTime($date null $startDate null $endDate null$type){
  7.         $qb $this->createQueryBuilder('t');
  8.         if($type) {
  9.             $qb->andWhere('t.type = :type')
  10.                 ->setParameter('type' $type);
  11.         }
  12.         if($date) {
  13.             $qb->andWhere('t.date = :date')
  14.                 ->setParameter('date' $date);
  15.         }
  16.         if($startDate && $endDate){
  17.             $qb->andWhere('t.date >= :startDate')
  18.                 ->setParameter('startDate' $startDate);
  19.             $qb->andWhere('t.date <= :endDate')
  20.                 ->setParameter('endDate' $endDate);
  21.         }
  22.         return $qb->getQuery()->getResult();
  23.     }
  24.     public function getListActiveOfDate($date$type$timezone){
  25.         $qb $this->createQueryBuilder('t')
  26.                 ->andWhere('t.type = :type')
  27.                 ->setParameter('type' $type);
  28.         $qb->andWhere('t.date = :date')
  29.                 ->setParameter('date' $date);
  30.         $now = new \DateTime('now', new \DateTimeZone($timezone));
  31.         if($date == $now->format('Y-m-d')){
  32.             $qb->andWhere('t.startAt > :currentTime')
  33.                 ->setParameter('currentTime'$now->format('H:i:s'));
  34.         }
  35.         $expr $qb->expr();
  36.         $exprOrX $qb->expr()->orX();
  37.         $exprOrX->add($expr->isNull('t.isReserved'));
  38.         $qb->andWhere($exprOrX);
  39.         $qb->andWhere('t.status = 1')
  40.             ->orderBy('t.startAt''ASC');
  41.         $appointments =  $qb->getQuery()->getResult();
  42.         $arrTime = [];
  43.         foreach($appointments as $appointment){
  44.             $arrTime[] = $appointment->getStartAt()->format('H:i');
  45.         }
  46.         return $arrTime;
  47.     }
  48. }