<?php
namespace App\Repository;
use App\Entity\Appointment;
class AppointmentRepository extends BaseRepository
{
public function getListByDateTime($date = null , $startDate = null , $endDate = null, $type){
$qb = $this->createQueryBuilder('t');
if($type) {
$qb->andWhere('t.type = :type')
->setParameter('type' , $type);
}
if($date) {
$qb->andWhere('t.date = :date')
->setParameter('date' , $date);
}
if($startDate && $endDate){
$qb->andWhere('t.date >= :startDate')
->setParameter('startDate' , $startDate);
$qb->andWhere('t.date <= :endDate')
->setParameter('endDate' , $endDate);
}
return $qb->getQuery()->getResult();
}
public function getListActiveOfDate($date, $type, $timezone){
$qb = $this->createQueryBuilder('t')
->andWhere('t.type = :type')
->setParameter('type' , $type);
$qb->andWhere('t.date = :date')
->setParameter('date' , $date);
$now = new \DateTime('now', new \DateTimeZone($timezone));
if($date == $now->format('Y-m-d')){
$qb->andWhere('t.startAt > :currentTime')
->setParameter('currentTime', $now->format('H:i:s'));
}
$expr = $qb->expr();
$exprOrX = $qb->expr()->orX();
$exprOrX->add($expr->isNull('t.isReserved'));
$qb->andWhere($exprOrX);
$qb->andWhere('t.status = 1')
->orderBy('t.startAt', 'ASC');
$appointments = $qb->getQuery()->getResult();
$arrTime = [];
foreach($appointments as $appointment){
$arrTime[] = $appointment->getStartAt()->format('H:i');
}
return $arrTime;
}
}