src/EventSubscriber/CalendarSubscriber.php line 28

  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Repository\ProjetRepository;
  4. use CalendarBundle\CalendarEvents;
  5. use CalendarBundle\Entity\Event;
  6. use CalendarBundle\Event\CalendarEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class CalendarSubscriber implements EventSubscriberInterface
  9. {
  10.     private ProjetRepository $projetRepository;
  11.     public function __construct(ProjetRepository $projetRepository)
  12.     {
  13.         $this->projetRepository $projetRepository;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             CalendarEvents::SET_DATA => 'onCalendarSetData',
  19.         ];
  20.     }
  21.     public function onCalendarSetData(CalendarEvent $calendar)
  22.     {
  23.         $start $calendar->getStart();
  24.         $end $calendar->getEnd();
  25.         $filters $calendar->getFilters();
  26.         // You may want to make a custom query from your database to fill the calendar
  27.         $projets $this->projetRepository->findAll();
  28.         foreach ($projets as $projet) {
  29.             $debut $projet->getRendezVousAt();
  30.             $event = new Event(
  31.                 $projet,
  32.                 $debut,
  33.                 $debut->add(new \DateInterval('PT30M'))
  34.             );
  35.             $event->setOptions([
  36.                 'backgroundColor' => '#FF0000',
  37.                 'borderColor' => '#FF0000',
  38.             ]);
  39.             $calendar->addEvent($event);
  40. //            $event = new Event(
  41. //                $projet,
  42. //                $debut,
  43. //                $debut->add(new \DateInterval('PT30M'))
  44. //            );
  45.         }
  46.     }
  47. }