diff --git a/src/Command/SendBandReminderCommand.php b/src/Command/SendBandReminderCommand.php index 8a3a53b..0cb03dc 100644 --- a/src/Command/SendBandReminderCommand.php +++ b/src/Command/SendBandReminderCommand.php @@ -35,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $dateNow = date('Y-m-d H:i:00', time()); $dateLater = date('Y-m-d H:i:00', (time() + 5 * 60 )); - $timeSlots = $this->timeSlotRepository->findNextTimeSlots($dateNow, $dateLater); + $timeSlots = $this->timeSlotRepository->findNextTimeSlotsBasedOn5Minutes($dateNow, $dateLater); foreach ($timeSlots as $timeSlot) { $io->comment($timeSlot->getBand()->getName()); diff --git a/src/Controller/API/FestivalApiController.php b/src/Controller/API/FestivalApiController.php index d3f7bd4..7cc18bd 100644 --- a/src/Controller/API/FestivalApiController.php +++ b/src/Controller/API/FestivalApiController.php @@ -108,4 +108,28 @@ public function listFestivalStagesTimeSlots(FestivalRepository $festivalReposito return JsonResponse::fromJsonString($serializer->serializeCircularReferenceJson($timeSlotArray)); } + + #[Route('/api/festivals/{festival}/stages/{stageName}/upnext', name: 'festival-stages-upnext')] + public function listFestivalStagesUpNext(FestivalRepository $festivalRepository, StageRepository $stageRepository, TimeSlotRepository $timeSlotRepository, string $festival, string $stageName): JsonResponse + { + $serializer = new SerializerService(); +// $festivals = $festivalRepository->findOneBy(['name' => $festival]); + + date_default_timezone_set('Europe/Berlin'); + + $dateNow = date('Y-m-d H:i:00', time()); + +// $stage = $stageRepository->findBy(['name' => $stageName, 'festival' => $festivals]); + $timeSlot = $timeSlotRepository->findNextTimeSlots($dateNow); + + $upNext = []; + + $upNext[] = [ + 'startTime' => $timeSlot->getStartTime()->format('H:i:s d.m.Y '), + 'band' => $timeSlot->getBand()->getName(), + 'stage' => $timeSlot->getStage()->getName(), + ]; + + return JsonResponse::fromJsonString($serializer->serializeCircularReferenceJson($upNext)); + } } diff --git a/src/Repository/TimeSlotRepository.php b/src/Repository/TimeSlotRepository.php index 3ade64b..08509cc 100644 --- a/src/Repository/TimeSlotRepository.php +++ b/src/Repository/TimeSlotRepository.php @@ -2,9 +2,11 @@ namespace App\Repository; +use App\Entity\Stage; use App\Entity\TimeSlot; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; +use Symfony\Component\Validator\Constraints\Time; /** * @extends ServiceEntityRepository @@ -46,7 +48,7 @@ public function __construct(ManagerRegistry $registry) // ; // } - public function findNextTimeSlots(string $dateNow, string $dateLater): array + public function findNextTimeSlotsBasedOn5Minutes(string $dateNow, string $dateLater): array { return $this->createQueryBuilder('t') ->andWhere('t.startTime > :dateNow') @@ -57,4 +59,15 @@ public function findNextTimeSlots(string $dateNow, string $dateLater): array ->getQuery() ->getResult(); } + + public function findNextTimeSlots(string $dateNow): TimeSlot + { + return $this->createQueryBuilder('t') + ->andWhere('t.startTime > :dateNow') + ->setParameter('dateNow', $dateNow) + ->orderBy('t.startTime', 'ASC') + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); + } }