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.         $id_unidad $filters['id_unidad'];
  37.         $tipo      $filters['tipo'];
  38.         // Modify the query to fit to your entity and needs
  39.         // Change booking.beginAt by your start date property
  40.         //dd($filters);
  41.         if($id_unidad == 0){
  42.                
  43.             $agendas $this->AgendaRepository
  44.                 ->createQueryBuilder('agenda')
  45.                 ->where('agenda.inicio BETWEEN :start and :end OR agenda.fin BETWEEN :start and :end')
  46.                 ->setParameter('start'$start->format('Y-m-d'))
  47.                 ->setParameter('end'$end->format('Y-m-d'))
  48.                 ->andWhere('agenda.sala = :val')
  49.                 ->setParameter('val'$id_sala)
  50.                 ->andWhere('agenda.estado = :val1')
  51.                 ->setParameter('val1'1)
  52.                 ->getQuery()
  53.                 ->getResult()
  54.             ;
  55.             
  56.         
  57.             $reuniones $this->AgendaRepository
  58.                 ->createQueryBuilder('agenda')
  59.                 ->where('agenda.inicio BETWEEN :start and :end OR agenda.fin BETWEEN :start and :end')
  60.                 ->setParameter('start'$start->format('Y-m-d'))
  61.                 ->setParameter('end'$end->format('Y-m-d'))
  62.                 ->andWhere('agenda.sala = :val')
  63.                 ->setParameter('val'$id_sala)
  64.                 ->andWhere('agenda.estado = :val1')
  65.                 ->setParameter('val1'2)
  66.                 ->getQuery()
  67.                 ->getResult()
  68.             ;
  69.         }else{
  70.             if($tipo == 'privado'){
  71.                 $procedimientoIds = [3,5,90,91,92,95,193,207,208,215,216];
  72.                 $agendas $this->AgendaRepository
  73.                     ->createQueryBuilder('a')
  74.                     ->innerJoin('a.sala''s')
  75.                     ->innerJoin('a.seguro''seguro')
  76.                     ->innerJoin('a.procedimiento''procedimiento')
  77.                     ->where('a.inicio BETWEEN :start and :end OR a.fin BETWEEN :start and :end')
  78.                     ->setParameter('start'$start->format('Y-m-d'))
  79.                     ->setParameter('end'$end->format('Y-m-d'))
  80.                     ->andWhere('s.unidad = :val')
  81.                     ->setParameter('val'$id_unidad)
  82.                     ->andWhere('a.estado = :val1')
  83.                     ->setParameter('val1'1)
  84.                     ->andWhere('seguro.tipo = :valTipo')
  85.                     ->andWhere('procedimiento.id IN (:procedimientoIds)'// filtro por IDs
  86.                     ->setParameter('procedimientoIds'$procedimientoIds// pasa el array
  87.                     ->setParameter('valTipo'2)
  88.                     ->getQuery()
  89.                     ->getResult()
  90.                 ;   
  91.                 $reuniones = [];
  92.                 
  93.             }else{
  94.                 $agendas $this->AgendaRepository
  95.                     ->createQueryBuilder('a')
  96.                     ->innerJoin('a.sala''s')
  97.                     ->where('a.inicio BETWEEN :start and :end OR a.fin BETWEEN :start and :end')
  98.                     ->setParameter('start'$start->format('Y-m-d'))
  99.                     ->setParameter('end'$end->format('Y-m-d'))
  100.                     ->andWhere('s.unidad = :val')
  101.                     ->setParameter('val'$id_unidad)
  102.                     ->andWhere('a.estado = :val1')
  103.                     ->setParameter('val1'1)
  104.                     ->getQuery()
  105.                     ->getResult()
  106.                 ;
  107.                 $reuniones $this->AgendaRepository
  108.                     ->createQueryBuilder('a')
  109.                     ->innerJoin('a.sala''s')
  110.                     ->where('a.inicio BETWEEN :start and :end OR a.fin BETWEEN :start and :end')
  111.                     ->setParameter('start'$start->format('Y-m-d'))
  112.                     ->setParameter('end'$end->format('Y-m-d'))
  113.                     ->andWhere('s.unidad = :val')
  114.                     ->setParameter('val'$id_unidad)
  115.                     ->andWhere('a.estado = :val1')
  116.                     ->setParameter('val1'2)
  117.                     ->getQuery()
  118.                     ->getResult()
  119.                 ;
  120.             }    
  121.         
  122.             
  123.         }    
  124.         
  125.         foreach ($agendas as $agenda) {
  126.             $apxs $agenda->getAgendaProcedimientos();
  127.             $txt_ap '';
  128.             foreach($apxs as $ap){
  129.                 $txt_ap .= ' ->'.$ap->getProcedimiento()->getNombre();
  130.             }
  131.             // this create the events with your data (here booking data) to fill calendar
  132.             $txtestado '';
  133.             if($agenda->getEstadoAgenda()=='0'){
  134.                 $txtestado 'LLAMAR A CONFIRMAR';   
  135.             }elseif ($agenda->getEstadoAgenda()=='1') {
  136.                 $txtestado 'CONFIRMADO';        
  137.             }elseif ($agenda->getEstadoAgenda()=='2') {
  138.                 $txtestado 'ADMISIONADO';        
  139.             }
  140.             if($id_unidad == 0){
  141.                 $agendaEvent = new Event(
  142.                     $agenda->getPaciente()->getApellido1().' '.$agenda->getPaciente()->getApellido2().' '.$agenda->getPaciente()->getNombre1().' '.$agenda->getPaciente()->getNombre2().' - '.$agenda->getProcedimiento()->getNombre().$txt_ap.' - '.$agenda->getEspecialidad()->getNombre().' : SEGURO:'.$agenda->getseguro()->getNombre().' ESTADO: '.$txtestado,
  143.                     $agenda->getInicio(),
  144.                     $agenda->getFin() // If the end date is null or not defined, a all day event is created.
  145.                 );
  146.                 
  147.                 $htmlDescription '';
  148.                 if($agenda->getConfirma() == '1'){
  149.                     $htmlDescription 'CONFIRMADO';    
  150.                 }
  151.                 
  152.                 
  153.                 $agendaEvent->setOptions([
  154.                     'backgroundColor' => '#581845',
  155.                     'borderColor' => 'white',
  156.                     'description' => $htmlDescription,
  157.                     'confirma' => $agenda->getConfirma(),
  158.                     'id' => $agenda->getId(),
  159.                     'procedimientos' => $agenda->getProcedimiento()->getNombre().$txt_ap
  160.                 ]);
  161.             }else{
  162.                 $msn $agenda->getPaciente()->getApellido1().' '.$agenda->getPaciente()->getApellido2().' '.$agenda->getPaciente()->getNombre1().' '.$agenda->getPaciente()->getNombre2().' - '.$agenda->getProcedimiento()->getNombre().$txt_ap.' - '.$agenda->getEspecialidad()->getNombre().' : SEGURO:'.$agenda->getseguro()->getNombre().' ESTADO: '.$txtestado;
  163.                 if($agenda->getConfirma()== '1'){
  164.                     $msn $msn.' -CONFIRMADO';
  165.                 }
  166.                 if($agenda->getDocumentos()){
  167.                     $msn $msn.' -DOCUMENTOS LISTOS';
  168.                 }    
  169.                 $agendaEvent = new Event(
  170.                     $msn,
  171.                     $agenda->getInicio(),
  172.                     $agenda->getFin() // If the end date is null or not defined, a all day event is created.
  173.                 );
  174.                 
  175.                 
  176.                 $htmlDescription '';
  177.                 if($agenda->getConfirma() == '1'){
  178.                     $htmlDescription 'CONFIRMADO';    
  179.                 }
  180.                 
  181.                 $confirma $agenda->getConfirma();
  182.                 if($tipo == 'privado' and $agenda->getDocumentos()){
  183.                    
  184.                     $htmlDescription 'DOCUMENTOS OK';
  185.                     $confirma 1;
  186.                 }    
  187.                 
  188.                 $color "#A9A9A9";
  189.                 if($agenda->getDoctor() != null){
  190.                     if($agenda->getDoctor()->getColor() != null){
  191.                         $color $agenda->getDoctor()->getColor();
  192.                     }
  193.                 }
  194.                 
  195.                 $agendaEvent->setOptions([
  196.                     'backgroundColor' => $color,
  197.                     'borderColor' => 'black',
  198.                     'description' => $htmlDescription,
  199.                     'confirma' => $confirma,
  200.                     'id' => $agenda->getId(),
  201.                     'procedimientos' => $agenda->getProcedimiento()->getNombre().$txt_ap
  202.                 ]);
  203.             }    
  204.             /*
  205.              * Add custom options to events
  206.              *
  207.              * For more information see: https://fullcalendar.io/docs/event-object
  208.              * and: https://github.com/fullcalendar/fullcalendar/blob/master/src/core/options.ts
  209.              */
  210.             if($agenda->getEstadoAgenda()=='0' and $id_unidad == 0){
  211.                 
  212.                 $agendaEvent->addOption('backgroundColor''black');
  213.                 $agendaEvent->addOption('borderColor''white');
  214.                    
  215.             }elseif ($agenda->getEstadoAgenda()=='1' and $id_unidad == 0) {
  216.                 
  217.                 $agendaEvent->addOption('backgroundColor''blue');
  218.                 $agendaEvent->addOption('borderColor''white');
  219.             }elseif ($agenda->getEstadoAgenda()=='2' and $id_unidad == 0) {
  220.                    
  221.                 $agendaEvent->addOption('backgroundColor''green');
  222.                 $agendaEvent->addOption('borderColor''white');
  223.             }     
  224.             $agendaEvent->addOption(
  225.                 'url',
  226.                 $this->router->generate('agenda_edit', [
  227.                     'id' => $agenda->getId(),
  228.                 ])
  229.             );
  230.             if($agenda->getId()== '99118'){
  231.                         //dd($agendaEvent);
  232.                     }
  233.             // finally, add the event to the CalendarEvent to fill the calendar
  234.             $calendar->addEvent($agendaEvent);
  235.         }
  236.         
  237.         foreach ($reuniones as $agenda) {
  238.             // this create the events with your data (here booking data) to fill calendar
  239.             $txtestado 'REUNION';
  240.             if($id_unidad == 0){
  241.                 $agendaEvent = new Event(  
  242.                     $txtestado.' '.$agenda->getObservacion(),
  243.                     $agenda->getInicio(),
  244.                     $agenda->getFin() // If the end date is null or not defined, a all day event is created.
  245.                 );
  246.                 
  247.                 $htmlDescription '';
  248.                 if($agenda->getConfirma() == '1'){
  249.                     $htmlDescription 'CONFIRMADO';    
  250.                 }
  251.                 
  252.                 $agendaEvent->setOptions([
  253.                     'backgroundColor' => '#581845',
  254.                     'borderColor' => 'white',
  255.                     'description' => $htmlDescription,
  256.                     'confirma' => $agenda->getConfirma(),
  257.                     'id' => $agenda->getId()
  258.                 ]);
  259.             }else{
  260.                 $agendaEvent = new Event(  
  261.                     'DR. '.$agenda->getDoctor()->getApellido1().' '.$agenda->getDoctor()->getNombre1().' - '.$txtestado.' '.$agenda->getObservacion(),
  262.                     $agenda->getInicio(),
  263.                     $agenda->getFin() // If the end date is null or not defined, a all day event is created.
  264.                 );
  265.                 
  266.                 
  267.                 $htmlDescription '';
  268.                 if($agenda->getConfirma() == '1'){
  269.                     $htmlDescription 'CONFIRMADO';    
  270.                 }
  271.                 
  272.                 $agendaEvent->setOptions([
  273.                     'backgroundColor' => $agenda->getDoctor()->getColor(),
  274.                     'borderColor' => 'black',
  275.                     'description' => $htmlDescription,
  276.                     'confirma' => $agenda->getConfirma(),
  277.                     'id' => $agenda->getId()
  278.                 ]);
  279.             }    
  280.             /*
  281.              * Add custom options to events
  282.              *
  283.              * For more information see: https://fullcalendar.io/docs/event-object
  284.              * and: https://github.com/fullcalendar/fullcalendar/blob/master/src/core/options.ts
  285.              */
  286.             
  287.             
  288.                
  289.             $agendaEvent->addOption(
  290.                 'url',
  291.                 $this->router->generate('agenda_reunion_edit', [
  292.                     'id' => $agenda->getId(),
  293.                 ])
  294.             );
  295.             // finally, add the event to the CalendarEvent to fill the calendar
  296.             $calendar->addEvent($agendaEvent);
  297.         }
  298.     }
  299.     // ...
  300. }