src/EventSubscriber/CalendarSubscriber.php line 26
<?phpnamespace App\EventSubscriber;use App\Repository\MissionRepository;use CalendarBundle\CalendarEvents;use CalendarBundle\Entity\Event;use CalendarBundle\Event\CalendarEvent;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;class CalendarSubscriber implements EventSubscriberInterface{public function __construct(private readonly MissionRepository $missionRepository,private readonly UrlGeneratorInterface $router) {}public static function getSubscribedEvents(){return [CalendarEvents::SET_DATA => 'onCalendarSetData',];}public function onCalendarSetData(CalendarEvent $calendar){$start = $calendar->getStart();$end = $calendar->getEnd();$missions = $this->missionRepository->createQueryBuilder('mission')->where('mission.day BETWEEN :start and :end')->setParameter('start', $start->format('Y-m-d H:i:s'))->setParameter('end', $end->format('Y-m-d H:i:s'))->getQuery()->getResult();foreach ($missions as $mission) {$color = $mission->getCustomer()->getColor();$eventName = $this->getFormattedEventTitle($mission->getCustomer()->getName(), $mission->getPlace());$event = new Event($eventName,$mission->getDay());$event->setOptions(['backgroundColor' => $color,'borderColor' => $color]);$event->addOption('url',$this->router->generate('app_mission_show', ['id' => $mission->getId()]));$calendar->addEvent($event);}}private function getFormattedEventTitle(string $customer, string $place): string{return $place . ' (' . $customer . ')';}}