src/EventSubscriber/CalendarSubscriber.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. // ...
  4. use App\Repository\AgendaRepository;
  5. use CalendarBundle\CalendarEvents;
  6. use CalendarBundle\Entity\Event;
  7. use CalendarBundle\Event\CalendarEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  10. class CalendarSubscriber implements EventSubscriberInterface
  11. {
  12.     private $agendaRepository;
  13.     private $router;
  14.     public function __construct(
  15.         AgendaRepository $agendaRepository,
  16.         UrlGeneratorInterface $router
  17.     ) {
  18.         $this->AgendaRepository $agendaRepository;
  19.         $this->router $router;
  20.     }
  21.     public static function getSubscribedEvents()
  22.     {
  23.         
  24.         return [
  25.             CalendarEvents::SET_DATA => 'onCalendarSetData',
  26.         ];
  27.     }
  28.     public function onCalendarSetData(CalendarEvent $calendar)
  29.     {
  30.         
  31.         $start $calendar->getStart();
  32.         $end $calendar->getEnd();
  33.         $filters $calendar->getFilters();
  34.         
  35.         $id_sala $filters['id_sala'];
  36.         // Modify the query to fit to your entity and needs
  37.         // Change booking.beginAt by your start date property
  38.         $agendas $this->AgendaRepository
  39.             ->createQueryBuilder('agenda')
  40.             ->where('agenda.inicio BETWEEN :start and :end OR agenda.fin BETWEEN :start and :end')
  41.             ->setParameter('start'$start->format('Y-m-d'))
  42.             ->setParameter('end'$end->format('Y-m-d'))
  43.             ->andWhere('agenda.sala = :val')
  44.             ->setParameter('val'$id_sala)
  45.             ->andWhere('agenda.estado = :val1')
  46.             ->setParameter('val1'1)
  47.             ->getQuery()
  48.             ->getResult()
  49.         ;
  50.         //dd($agendas);
  51.         foreach ($agendas as $agenda) {
  52.             // this create the events with your data (here booking data) to fill calendar
  53.             $txtestado '';
  54.             if($agenda->getEstadoAgenda()=='0'){
  55.                 $txtestado 'LLAMAR A CONFIRMAR';   
  56.             }elseif ($agenda->getEstadoAgenda()=='1') {
  57.                 $txtestado 'CONFIRMADO';        
  58.             }elseif ($agenda->getEstadoAgenda()=='2') {
  59.                 $txtestado 'ADMISIONADO';        
  60.             }  
  61.             $agendaEvent = new Event(
  62.                 $agenda->getProcedimiento()->getNombre().' '.$agenda->getEspecialidad()->getNombre().' : '.$agenda->getPaciente()->getApellido1().' '.$agenda->getPaciente()->getApellido2().' '.$agenda->getPaciente()->getNombre1().' '.$agenda->getPaciente()->getNombre2().' SEGURO:'.$agenda->getseguro()->getNombre().' ESTADO: '.$txtestado,
  63.                 $agenda->getInicio(),
  64.                 $agenda->getFin() // If the end date is null or not defined, a all day event is created.
  65.             );
  66.             /*
  67.              * Add custom options to events
  68.              *
  69.              * For more information see: https://fullcalendar.io/docs/event-object
  70.              * and: https://github.com/fullcalendar/fullcalendar/blob/master/src/core/options.ts
  71.              */
  72.             if($agenda->getEstadoAgenda()=='0'){
  73.                 $agendaEvent->setOptions([
  74.                     'backgroundColor' => 'black',
  75.                     'borderColor' => 'white',
  76.                 ]);
  77.             }elseif ($agenda->getEstadoAgenda()=='1') {
  78.                 $agendaEvent->setOptions([
  79.                     'backgroundColor' => 'blue',
  80.                     'borderColor' => 'white',
  81.                 ]);    
  82.             }elseif ($agenda->getEstadoAgenda()=='2') {
  83.                 $agendaEvent->setOptions([
  84.                     'backgroundColor' => 'green',
  85.                     'borderColor' => 'white',
  86.                 ]);    
  87.             }     
  88.             $agendaEvent->addOption(
  89.                 'url',
  90.                 $this->router->generate('agenda_edit', [
  91.                     'id' => $agenda->getId(),
  92.                 ])
  93.             );
  94.             // finally, add the event to the CalendarEvent to fill the calendar
  95.             $calendar->addEvent($agendaEvent);
  96.         }
  97.     }
  98.     // ...
  99. }