public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startDate = $calendarEvent->getStartDatetime();
     $endDate = $calendarEvent->getEndDatetime();
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     //compruebo si el usuario es un cliente o un profesional
     if ($this->user->hasRole('ROLE_PROFESIONAL')) {
         //es un profesional
         $companyEvents = $this->entityManager->getRepository('UserProfesionalBundle:ProfessionalEvent')->createQueryBuilder('company_events')->where('company_events.start_date BETWEEN :startDate and :endDate AND company_events.professional = :user')->setParameter('user', $this->user->getProfessional()->getId())->setParameter('startDate', $startDate->format('Y-m-d H:i:s'))->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))->getQuery()->getResult();
     } else {
         //es un cliente
         $companyEvents = $this->entityManager->getRepository('UserProfesionalBundle:ProfessionalEvent')->createQueryBuilder('company_events')->where('company_events.start_date BETWEEN :startDate and :endDate AND company_events.client = :user')->setParameter('user', $this->user->getProfessional()->getId())->setParameter('startDate', $startDate->format('Y-m-d H:i:s'))->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))->getQuery()->getResult();
     }
     foreach ($companyEvents as $companyEvent) {
         // create an event with a start/end time, or an all day event
         $interval = new \DateInterval($companyEvent->getDuration());
         $enddate = $companyEvent->getStartDate()->add($interval);
         $eventEntity = new EventEntity($companyEvent->getClient()->getUser()->getName() . " " . $companyEvent->getClient()->getUser()->getSurname(), $companyEvent->getStartDate(), $enddate);
         //optional calendar event settings
         $eventEntity->setAllDay(true);
         // default is false, set to true if this is an all day event
         $eventEntity->setBgColor('#5B9BB4');
         //set the background color of the event's label
         $eventEntity->setFgColor('#FFFFFF');
         //set the foreground color of the event's label
         $eventEntity->setUrl($this->router->generate('profesional_show_event', array('idEvent' => $companyEvent->getId())));
         // url to send user to when event label is clicked
         $eventEntity->setCssClass('consulta');
         // a custom class you may want to apply to event labels
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startDateFilter = $calendarEvent->getStartDatetime();
     $endDateFilter = $calendarEvent->getEndDatetime();
     // alert('event listener!');
     // The original request so you can get filters from the calendar
     // Use the filter in your query for example
     $request = $calendarEvent->getRequest();
     $filter = $request->get('filter');
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     $classEvents = $this->entityManager->getRepository('SiploCalendarBundle:Event')->createQueryBuilder('company_events')->where('company_events.startDatetime BETWEEN :startDate and :endDate')->setParameter('startDate', $startDateFilter->format('Y-m-d H:i:s'))->setParameter('endDate', $endDateFilter->format('Y-m-d H:i:s'))->getQuery()->getResult();
     // $companyEvents and $companyEvent in this example
     // represent entities from your database, NOT instances of EventEntity
     // within this bundle.
     //
     // Create EventEntity instances and populate it's properties with data
     // from your own entities/database values.
     foreach ($classEvents as $classEvent) {
         $eventEntity = new EventEntity($classEvent->getTitle(), $classEvent->getStartDatetime(), $classEvent->getEndDatetime(), false);
         //optional calendar event settings
         // $eventEntity->setAllDay(true); // default is false, set to true if this is an all day event
         $eventEntity->setBgColor($classEvent->getBgColor());
         //set the background color of the event's label
         $eventEntity->setFgColor('#000000');
         //set the foreground color of the event's label
         $eventEntity->setUrl('http://www.google.com');
         // url to send user to when event label is clicked
         $eventEntity->setCssClass('my-custom-class');
         // a custom class you may want to apply to event labels
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startDate = $calendarEvent->getStartDatetime();
     $endDate = $calendarEvent->getEndDatetime();
     // The original request so you can get filters from the calendar
     // Use the filter in your query for example
     $request = $calendarEvent->getRequest();
     $filter = $request->get('filter');
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     $companyEvents = $this->entityManager->getRepository('AppBundle:Event')->findCurrent();
     // $companyEvents and $companyEvent in this example
     // represent entities from your database, NOT instances of EventEntity
     // within this bundle.
     //
     // Create EventEntity instances and populate it's properties with data
     // from your own entities/database values.
     foreach ($companyEvents as $companyEvent) {
         // create an event with a start/end time, or an all day event
         $eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getDatetime(), $companyEvent->getDatetime());
         //optional calendar event settings
         $eventEntity->setBgColor('#971c1e');
         //set the background color of the event's label
         $eventEntity->setFgColor('#FFFFFF');
         //set the foreground color of the event's label
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startDate = $calendarEvent->getStartDatetime();
     $endDate = $calendarEvent->getEndDatetime();
     // The original request so you can get filters from the calendar
     // Use the filter in your query for example
     $request = $calendarEvent->getRequest();
     $filter = $request->get('filter');
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     $companyEvents = $this->container->get('doctrine')->getEntityManager()->getRepository('AppBundle:Appointment')->createQueryBuilder('appointemnt')->where('appointemnt.startDatetime BETWEEN :startDate and :endDate AND appointemnt.specialist = :specialist_id')->setParameter('startDate', $startDate->format('Y-m-d H:i:s'))->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))->setParameter('specialist_id', $request->request->get('specialist_id'))->getQuery()->getResult();
     // $companyEvents and $companyEvent in this example
     // represent entities from your database, NOT instances of EventEntity
     // within this bundle.
     //
     // Create EventEntity instances and populate it's properties with data
     // from your own entities/database values.
     foreach ($companyEvents as $companyEvent) {
         $startDate = $companyEvent->getStartDatetime();
         $eventEntity = new EventEntity($companyEvent->getStartDatetime()->format($this->container->getParameter('date.format')), $companyEvent->getStartDatetime(), $companyEvent->getEndDatetime());
         //optional calendar event settings
         $eventEntity->setBgColor('#337ab7');
         //set the background color of the event's label
         $eventEntity->setFgColor('#FFFFFF');
         //set the foreground color of the event's label
         $eventEntity->setUrl('http://www.google.com');
         // url to send user to when event label is clicked
         $eventEntity->setCssClass('my-custom-class');
         // a custom class you may want to apply to event labels
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startDate = $calendarEvent->getStartDatetime();
     $endDate = $calendarEvent->getEndDatetime();
     $user = $this->securityContext->getToken()->getUser();
     $instanceRepository = $this->entityManager->getRepository('TSKScheduleBundle:ScheduleInstance');
     // TODO:  Filter instances based on userId, schoolId, etc ...
     $scheduleInstances = $instanceRepository->createQueryBuilder('si')->where('si.start BETWEEN :startDate and :endDate')->setParameter(':startDate', $startDate->format('Y-m-d H:i:s'))->setParameter(':endDate', $endDate->format('Y-m-d H:i:s'))->getQuery()->getResult();
     foreach ($scheduleInstances as $si) {
         $eventEntity = new EventEntity($si->getTitle(), $si->getStart(), $si->getEnd(), $si->getIsAllDay());
         $eventEntity->setId($si->getId());
         $color = '';
         $classes = $si->getScheduleEntity()->getClasses();
         if ($classes) {
             $class = $classes->first();
             if (is_object($class)) {
                 $color = $class->getScheduleColor();
             }
         }
         if (!$color) {
             $color = $si->getScheduleEntity()->getCategory()->getColor();
         }
         if ($color) {
             $eventEntity->setBgColor($color);
         }
         $calendarEvent->addEvent($eventEntity);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startTime = new \DateTime(self::TEST_START_TIME);
     $endTime = new \DateTime(self::TEST_END_TIME);
     if ($calendarEvent->getStartDatetime()->getTimestamp() === $startTime->getTimestamp() && $calendarEvent->getEndDatetime()->getTimestamp() === $endTime->getTimestamp()) {
         $event = new EventEntity("Fake Event Title", new \DateTime(), null, true);
         $calendarEvent->addEvent($event);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $request = $calendarEvent->getRequest();
     $title = $request->get('title');
     $description = $request->get('description');
     $start = $request->get('start');
     $end = $request->get('end');
     $idMachine = 2;
     /////TO FIX --> get ID from route
     if ($title && $description && $start && $end) {
         //converting unix timestamp from ms to s (because javascript provide ms)
         $start = \DateTime::createFromFormat('U', $start / 1000);
         $end = \DateTime::createFromFormat('U', $end / 1000);
         $em = $this->entityManager;
         $repository = $em->getRepository('ReservationBundle:Bookables\\Machine');
         $resource = $repository->find($idMachine);
         $event = new \CentraleLille\ReservationBundle\Entity\Booking\Event();
         $event->setBookable($resource);
         $event->setTitle($title);
         $event->setDescription($description);
         $time = new \DateTime('now');
         $event->setCreationDateTime($time);
         $event->setStartDateTime($start);
         $event->setEndDateTime($end);
         $event->setStatus('');
         //$booker = $this->get('event_booker');
         //$booker->book();
         $em->persist($event);
         $em->flush();
     }
     // The original request so you can get filters from the calendar
     // Use the filter in your query for example
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     $companyEvents = $this->entityManager->getRepository('ReservationBundle:Booking\\Event')->createQueryBuilder('event')->where('event.bookable = :id')->setParameter('id', $idMachine)->getQuery()->getResult();
     // $companyEvents and $companyEvent in this example
     // represent entities from your database, NOT instances of EventEntity
     // within this bundle.
     //
     // Create EventEntity instances and populate it's properties with data
     // from your own entities/database values.
     foreach ($companyEvents as $companyEvent) {
         // create an event with a start/end time, or an all day event
         $eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), $companyEvent->getEndDatetime(), false);
         //optional calendar event settings
         $eventEntity->setBgColor('#FF0000');
         //set the background color of the event's label
         $eventEntity->setFgColor('#FFFFFF');
         //set the foreground color of the event's label
         $eventEntity->setUrl('#');
         // url to send user to when event label is clicked
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startDate = $calendarEvent->getStartDatetime();
     $endDate = $calendarEvent->getEndDatetime();
     // The original request so you can get filters from the calendar
     // Use the filter in your query for example
     $request = $calendarEvent->getRequest();
     $filter = $request->get('param');
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     if ($filter == 'calendar') {
         $companyEvents = $this->entityManager->getRepository('TorBundle:ReservationTor')->findAll();
     } else {
         // $companyEvents = $this->entityManager->getRepository('TorBundle:InstructorsReservation')->findAll();
         $companyEvents = $this->entityManager->getRepository('TorBundle:InstructorsReservation')->createQueryBuilder('instructor_events')->where('instructor_events.idInstructor = :id')->setParameter('id', $filter)->getQuery()->getResult();
     }
     // $companyEvents and $companyEvent in this example
     // represent entities from your database, NOT instances of EventEntity
     // within this bundle.
     //
     // Create EventEntity instances and populate it's properties with data
     // from your own entities/database values.
     foreach ($companyEvents as $companyEvent) {
         // create an event with a start/end time, or an all day event
         if ($filter == 0) {
             $eventEntity = new EventEntity((string) $companyEvent->getUserId(), $companyEvent->getDataStart(), $companyEvent->getDateStop());
         } else {
             $eventEntity = new EventEntity((string) $companyEvent->getIdUser(), $companyEvent->getDateStart(), $companyEvent->getDateStop());
         }
         //optional calendar event settings
         $eventEntity->setAllDay(false);
         // default is false, set to true if this is an all day event
         $eventEntity->setBgColor('#FC2A0A');
         //set the background color of the event's label
         $eventEntity->setFgColor('#FFFFFF');
         //set the foreground color of the event's label
         //$eventEntity->setUrl('http://www.google.com'); // url to send user to when event label is clicked
         $eventEntity->setCssClass('my-custom-class');
         // a custom class you may want to apply to event labels
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startDate = $calendarEvent->getStartDatetime();
     $endDate = $calendarEvent->getEndDatetime();
     // The original request so you can get filters from the calendar
     // Use the filter in your query for example
     $request = $calendarEvent->getRequest();
     $filter = $request->get('filter');
     $user = $this->securityContext->getToken()->getUser();
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     $companyEvents = $this->entityManager->getRepository('CalendarEngineBundle:UserEvent')->createQueryBuilder('user_events')->where('user_events.date BETWEEN :startDate and :endDate')->andWhere('user_events.userId = :id')->setParameter('startDate', $startDate->format('Y-m-d H:i:s'))->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))->setParameter("id", $user->getId())->getQuery()->getResult();
     // $companyEvents and $companyEvent in this example
     // represent entities from your database, NOT instances of EventEntity
     // within this bundle.
     //
     // Create EventEntity instances and populate it's properties with data
     // from your own entities/database values.
     foreach ($companyEvents as $companyEvent) {
         $eventDate = $companyEvent->getDate();
         $now = new \DateTime('now');
         $eventEntity = new EventEntity($eventDate->format("H:i") . " " . $companyEvent->getEventTitle(), $eventDate, null, true);
         //optional calendar event settings
         $eventEntity->setAllDay(true);
         // default is false, set to true if this is an all day event
         if ($eventDate < $now) {
             $eventEntity->setBgColor('#FF0000');
             //set the background color of the event's label
         } else {
             $eventEntity->setBgColor('#17961E');
             //set the background color of the event's label
         }
         $eventEntity->setFgColor('#FFFFFF');
         //set the foreground color of the event's label
         $eventEntity->setUrl($this->router->generate('calendar_app_showEvent', ['id' => $companyEvent->getId()]));
         // url to send user to when event label is clicked
         $eventEntity->setCssClass('my-custom-class');
         // a custom class you may want to apply to event labels
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $sc = $this->sc;
     $startDate = $calendarEvent->getStartDatetime();
     $endDate = $calendarEvent->getEndDatetime();
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     $companyEvents = $this->entityManager->getRepository('TaskeetMainBundle:Event')->createQueryBuilder('company_events')->where('company_events.startDate BETWEEN :startDate and :endDate')->andWhere('company_events.owner = :owner ')->setParameter(':startDate', $startDate->format('Y-m-d H:i:s'))->setParameter(':endDate', $endDate->format('Y-m-d H:i:s'))->setParameter(':owner', $sc->getToken()->getUser()->getId())->getQuery()->getResult();
     foreach ($companyEvents as $companyEvent) {
         // create an event with a start/end time, or an all day event
         //if ($companyEvent->getAllDayEvent() === false) {
         $eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDate(), $companyEvent->getDueDate());
         //} else {
         //  $eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), null, true);
         // }
         //optional calendar event settings
         if ($companyEvent->getStartDate() == $companyEvent->getDueDate()) {
             $eventEntity->setAllDay(true);
         } else {
             $eventEntity->setAllDay(false);
         }
         if ($companyEvent->getType()->getName() == "categoria 1") {
             $eventEntity->setBgColor('#FF0000');
             //set the background color of the event's label
             $eventEntity->setFgColor('#FFFFFF');
             //set the foreground color of the event's label
         } else {
             $eventEntity->setBgColor('#000000');
             //set the background color of the event's label
             $eventEntity->setFgColor('#FFFFFF');
             //set the foreground color of the event's label
         }
         $eventEntity->setUrl($companyEvent->getid() . '/edit');
         // url to send user to when event label is clicked
         $eventEntity->setCssClass('my-custom-class');
         // a custom class you may want to apply to event labels
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }
 /**
  * @param CalendarEvent $calendarEvent
  */
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startDate = $calendarEvent->getStartDatetime();
     $endDate = $calendarEvent->getEndDatetime();
     // The original request so you can get filters from the calendar
     // Use the filter in your query for example
     $request = $calendarEvent->getRequest();
     $filter = $request->get('filter');
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     $events = $this->entityManager->getRepository('AppBundle:Event')->createQueryBuilder('event')->getQuery()->getResult();
     // $companyEvents and $companyEvent in this example
     // represent entities from your database, NOT instances of EventEntity
     // within this bundle.
     //
     // Create EventEntity instances and populate it's properties with data
     // from your own entities/database values.
     /** @var Event $event */
     foreach ($events as $event) {
         // create an event with a start/end time, or an all day event
         //            if ($event->isFullDay() === false) {
         $eventEntity = new EventEntity($event->getName(), $event->getStartDate(), $event->getEndDate());
         //            } else {
         //                $eventEntity = new EventEntity($event->getName(), $event->getStartDate(), null, true);
         //            }
         //optional calendar event settings
         $eventEntity->setAllDay($event->isFullDay());
         // default is false, set to true if this is an all day event
         $eventEntity->setBgColor($event->getColor());
         //set the background color of the event's label
         $eventEntity->setFgColor('#FFFFFF');
         //set the foreground color of the event's label
         //            $eventEntity->setUrl('http://www.google.com'); // url to send user to when event label is clicked
         //            $eventEntity->setCssClass('my-custom-class'); // a custom class you may want to apply to event labels
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $request = $calendarEvent->getRequest();
     $filter = $request->get('filter');
     //$startDate = $calendarEvent->getStartDatetime();
     //$endDate   = $calendarEvent->getEndDatetime();
     $sucursal = $request->get('sucursal');
     $hoyFiltro = $request->get('hoyFiltro');
     //        $fechaInicio = $request->get('fechaInicio');
     //        $fechaFin = $request->get('fechaFin');
     $request = $calendarEvent->getRequest();
     $filter = $request->get('filter');
     $nombre = $request->get('paciente');
     $user = $request->get('user');
     $fechaInicio = $request->get('start');
     $fechaFin = $request->get('end');
     $startDate = date('Y-m-d', $fechaInicio);
     $endDate = date('Y-m-d', $fechaFin);
     //var_dump($startDate);
     //var_dump($endDate);
     //var_dump($nombre);
     if ($sucursal == '') {
         //    $sucursal =3;
     }
     //var_dump($sucursal);
     //die();
     //        var_dump($fechaInicio);
     //        var_dump($fechaFin);
     //        die();
     //$fechaInicioDate = new \DateTime($fechaInicio);
     //$fechaFinDate = new \DateTime($fechaFin);
     //die();
     //$fechaInicio = $fechaInicioDate->format('Y-m-d');
     //$fechaFin = $fechaFinDate->format('Y-m-d');
     //var_dump($fechaInicio);
     //var_dump($fechaFin);
     //die();
     //$date = new \DateTime($hoyFiltro);
     //var_dump($hoyFiltro);
     //var_dump($sucursal);
     //var_dump($user);
     //die();
     //$em = $this->getDoctrine()->getManager();
     //        var_dump($sucursal);
     //        die();
     if ($nombre != '') {
         $dql = "SELECT pac.id , per.nombres,per.apellidos FROM DGPlusbelleBundle:Paciente pac " . "JOIN pac.persona per " . "JOIN pac.expediente exp " . "WHERE CONCAT(upper(per.nombres),' ',upper(per.apellidos),' ', upper(exp.numero)) LIKE upper(:nombre) ";
         $paciente = $this->em->createQuery($dql)->setParameters(array('nombre' => '%' . $nombre . '%'))->getResult();
     } else {
         $paciente = 1;
     }
     //var_dump($nombre);
     //var_dump($paciente);
     //die();
     if ($sucursal != '') {
         //echo "sucursal ";
         if ($user == 0) {
             //echo "user";
             if ($nombre == '') {
                 //echo " nombre";
                 $dql = "SELECT c FROM DGPlusbelleBundle:Cita c " . "WHERE c.sucursal=:sucursal AND c.fechaCita BETWEEN :fechaInicio AND :fechaFin";
                 $citas = $this->em->createQuery($dql)->setParameters(array('sucursal' => $sucursal, 'fechaInicio' => $startDate, 'fechaFin' => $endDate))->getResult();
                 //var_dump($citas);
             } else {
                 if (count($paciente) != 0) {
                     //echo $paciente[0]['id'];
                     //echo count($paciente);
                     $dql = "SELECT c FROM DGPlusbelleBundle:Cita c " . "JOIN c.paciente pac " . "JOIN pac.expediente exp " . "JOIN pac.persona per " . "WHERE c.sucursal=:sucursal AND c.fechaCita BETWEEN :fechaInicio AND :fechaFin AND CONCAT(upper(per.nombres),' ',upper(per.apellidos),' ', upper(exp.numero)) LIKE upper(:nombre) ";
                     $citas = $this->em->createQuery($dql)->setParameters(array('sucursal' => $sucursal, 'fechaInicio' => $startDate, 'fechaFin' => $endDate, 'nombre' => '%' . $nombre . '%'))->getResult();
                     //echo "prueba";
                 }
                 //var_dump($citas);
             }
             //                $citas = $this->em->getRepository('DGPlusbelleBundle:Cita')->findBy(array('sucursal'=>$sucursal));
         } else {
             //$citas = $this->em->getRepository('DGPlusbelleBundle:Cita')->findBy(array('sucursal'=>$sucursal));
             if ($nombre == '') {
                 $dql = "SELECT c FROM DGPlusbelleBundle:Cita c " . "WHERE c.sucursal=:sucursal AND c.empleado=:user AND c.fechaCita BETWEEN :fechaInicio AND :fechaFin";
                 $citas = $this->em->createQuery($dql)->setParameters(array('sucursal' => $sucursal, 'user' => $user, 'fechaInicio' => $startDate, 'fechaFin' => $endDate))->getResult();
             } else {
                 //                    $dql = "SELECT c FROM DGPlusbelleBundle:Cita c "
                 //                        . "WHERE c.sucursal=:sucursal AND c.fechaCita BETWEEN :fechaInicio AND :fechaFin AND c.paciente=:id";
                 //                    if(count($paciente)!=0){
                 //                        $citas = $this->em->createQuery($dql)
                 //                        ->setParameters(array('sucursal'=>$sucursal,'fechaInicio'=>$startDate,'fechaFin'=>$endDate,'id'=>$paciente[0]['id']))
                 //                         ->getResult();
                 //                    }
                 $dql = "SELECT c FROM DGPlusbelleBundle:Cita c " . "JOIN c.paciente pac " . "JOIN pac.expediente exp " . "JOIN pac.persona per " . "WHERE c.sucursal=:sucursal AND c.empleado=:empleado AND c.fechaCita BETWEEN :fechaInicio AND :fechaFin AND CONCAT(upper(per.nombres),' ',upper(per.apellidos),' ', upper(exp.numero)) LIKE upper(:nombre) ";
                 $citas = $this->em->createQuery($dql)->setParameters(array('sucursal' => $sucursal, 'empleado' => $user, 'fechaInicio' => $startDate, 'fechaFin' => $endDate, 'nombre' => '%' . $nombre . '%'))->getResult();
             }
             //$citas = $this->em->getRepository('DGPlusbelleBundle:Cita')->findBy(array('sucursal'=>$sucursal,'empleado'=>$user));
         }
     } else {
         //echo "sucursal todas";
         //$citas = $this->em->getRepository('DGPlusbelleBundle:Cita')->findBy(array('fechaCita'=>$date));
         if ($user == 0) {
             if ($nombre == '') {
                 $citas = $this->em->getRepository('DGPlusbelleBundle:Cita')->findAll();
             } else {
                 $citas = $this->em->getRepository('DGPlusbelleBundle:Cita')->findBy(array('paciente' => $paciente[0]['id']));
             }
         } else {
             if ($nombre == '') {
                 $citas = $this->em->getRepository('DGPlusbelleBundle:Cita')->findBy(array('empleado' => $user));
             } else {
                 $citas = $this->em->getRepository('DGPlusbelleBundle:Cita')->findBy(array('empleado' => $user, 'paciente' => $paciente[0]['id']));
             }
             //$citas = $this->em->getRepository('DGPlusbelleBundle:Cita')->findBy(array('sucursal'=>$sucursal));
         }
     }
     //die();
     //var_dump($citas);
     $cierres = $this->em->getRepository('DGPlusbelleBundle:CierreAdministrativo')->findAll();
     foreach ($cierres as $key => $cierreEvent) {
         $fi = $cierreEvent->getFecha()->format('Y-m-d');
         $ih = $cierreEvent->getHoraInicio()->format('H:i');
         $fh = $cierreEvent->getHoraFin()->format('H:i');
         $st = new \DateTime($fi . ' ' . $ih);
         $nh = new \DateTime($fi . ' ' . $fh);
         $eventEntity = new EventEntity('', $st, $nh);
         $empleado = $cierreEvent->getEmpleado()->getPersona()->getNombres() . ' ' . $cierreEvent->getEmpleado()->getPersona()->getApellidos();
         $motivo = $cierreEvent->getMotivo();
         $title = strtoupper("Cierre administrativo | " . $empleado . ' | ' . $motivo);
         $title = '<div class="col-xs-1 fa fa-lock fa-2" style="border:1px solid #F00; border-right:0px solid #F00; color:#FFF; height: 100%; float: left; background: #69BD45;  position: absolute; padding-left:2px "></div> <div class="col-xs-11" style="border-left:0px solid #000 !important; border:1px solid #F00;width: 93%; height: 100%; float: right; position: relative; "> | ' . $title . '</div>';
         $eventEntity->setTitle($title);
         $eventEntity->setBgColor('#FFF');
         //set the background color of the event's label
         $eventEntity->setFgColor('#000');
         $calendarEvent->addEvent($eventEntity);
     }
     $fechaHoy = date("Y-m-d");
     //var_dump($this->c->getTransport());
     if (count($paciente) != 0) {
         foreach ($citas as $key => $companyEvent) {
             // create an event with a start/end time, or an all day event
             //var_dump($key);
             $fi = $companyEvent->getFechaCita()->format('Y-m-d');
             $ih = $companyEvent->getHoraCita()->format('H:i');
             if ($fi == $fechaHoy) {
                 //var_dump($request->get($title));
                 //die();
                 //Claro
                 //$this->c->sendEmail("*****@*****.**","","","","Recordatorio de cita el dia: ".$fi." a las ".$ih);
                 //Tigo
                 //$this->c->sendEmail("*****@*****.**","","","","Recordatorio de cita el dia: ".$fi." a las ".$ih);
                 //Movistar, este no funciona
                 //$this->c->sendEmail("*****@*****.**","","","","Recordatorio de cita el dia: ".$fi." a las ".$ih);
                 //Digicel
                 //$this->c->sendEmail("*****@*****.**","","","","Recordatorio de cita el dia: ".$fi." a las ".$ih);
             }
             //$fh = $companyEvent->getHoraFin()->format('H:i');
             $h = date("H:i", strtotime('+30 minutes', strtotime($ih)));
             //var_dump($h);
             //$this->get('envio_correo')->sendEmail("*****@*****.**","","","","Recordatorio de cita el dia: ");
             //$st    = new \DateTime($fi.' '.$ih);
             //$nh    = new \DateTime($fi.' '.$h);
             //$//end   = new \DateTime($fi.' '.$fh);
             //$eventEntity = new EventEntity('', $st,$nh );
             $ih = $companyEvent->getHoraCita()->format('H:i');
             $fh = $companyEvent->getHoraFin()->format('H:i');
             $st = new \DateTime($fi . ' ' . $ih);
             $nh = new \DateTime($fi . ' ' . $fh);
             $eventEntity = new EventEntity('', $st, $nh);
             //var_dump($companyEvent);
             //echo $companyEvent->getHoraFin()=='00:00';
             if ($companyEvent->getHoraFin()->format("H:i") == '00:00') {
                 //var_dump($companyEvent);
                 $horaFin = $companyEvent->getHoraCita()->format("H:i");
                 $horaFinTime = strtotime($horaFin);
                 $horaFin = date("g:i a", strtotime('30 minutes', $horaFinTime));
             } else {
                 $horaFin = $companyEvent->getHoraFin()->format("H:i");
                 $horaFinTime = strtotime($horaFin);
                 //$horaFin = date("g:i a", strtotime($horaFinTime));
             }
             //echo $horaFin;
             if ($companyEvent->getPaciente() != null) {
                 $idPaciente = $companyEvent->getPaciente()->getId();
                 $dql = "SELECT exp" . " FROM DGPlusbelleBundle:Expediente exp" . " WHERE exp.paciente =:paciente";
                 $expediente = $this->em->createQuery($dql)->setParameter('paciente', $idPaciente)->getResult();
                 //var_dump($expediente);
                 if (count($expNumero = $expediente) != 0) {
                     $expNumero = $expediente[0]->getNumero();
                 } else {
                     $expNumero = "";
                 }
                 //optional calendar event settings
                 $doctor = $companyEvent->getEmpleado()->getPersona()->getNombres() . ' ' . $companyEvent->getEmpleado()->getPersona()->getApellidos();
                 //var_dump($index);
                 $eventEntity->setId($companyEvent->getID());
                 //                $title = strtoupper($expNumero).' - '.$companyEvent->getPaciente()->getPersona()->getNombres().' '.$companyEvent->getPaciente()->getPersona()->getApellidos();
                 $title = strtoupper($expNumero) . ' - ' . strtoupper($companyEvent->getPaciente()->getPersona()->getNombres() . ' ' . $companyEvent->getPaciente()->getPersona()->getApellidos()) . ' | ' . $doctor . ' | ' . $horaFin;
                 //var_dump($expNumero);
             } else {
                 $eventEntity->setId($companyEvent->getID());
                 $idPaciente = strtoupper("Reserva de cita");
                 $expNumero = "";
                 //                $title = $idPaciente.$expNumero;
                 $title = $idPaciente . $expNumero . ' | ' . strtoupper($doctor) . ' | ' . $horaFin;
             }
             //var_dump($idPaciente);
             //$expediente = $this->em->getRepository('DGPlusbelleBundle:Expediente')->findBy(array('paciente'=>$idPaciente));
             $eventEntity->setAllDay(false);
             // default is false, set to true if this is an all day event
             $unicode = "&#10003;";
             //Cita
             //$eventEntity->setBgColor('#C3C3C3'); //set the background color of the event's label
             //$eventEntity->setFgColor('#FFF'); //set color font
             $eventEntity->setBgColor('#FFF');
             //set the background color of the event's label
             $eventEntity->setFgColor('#000');
             //
             /*switch($companyEvent->getTratamiento()->getCategoria()->getId()){
                   case 1:     //Categoria 1
                       $eventEntity->setBgColor('#8C1821'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-check"> | '.$title/*' | '.$companyEvent->getEstado()./;
                       break;
                   case 2:     //Categoria 2
                       $eventEntity->setBgColor('#4C4B31'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-certificate"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   case 3:    //Categoria 3
                       $eventEntity->setBgColor('#C7931C'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   case 4:    //Categoria 4
                       //$eventEntity->setBgColor('#B2B064'); //set the background color of the event's label
                       $eventEntity->setBgColor('#EA92C3'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   case 5:    //Categoria 5
                       $eventEntity->setBgColor('#7E9499'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   case 6:    //Categoria 6
                       $eventEntity->setBgColor('#7C591A'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   case 7:    //Categoria 7
                       $eventEntity->setBgColor('#D77C87'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   case 8:    //Categoria 8
                       $eventEntity->setBgColor('#5D5D5D'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   case 9:    //Categoria 9
                       $eventEntity->setBgColor('#E07140'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   case 10:    //Categoria 10
                       $eventEntity->setBgColor('#0F6D38'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   
                   
                   case 11:    //Categoria 11
                       $eventEntity->setBgColor('#1C3343'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   
                   case 12:    //Categoria 12
                       $eventEntity->setBgColor('#67A59B'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). /;
                       break;
                   
                   case 13:    //Categoria 13
                       $eventEntity->setBgColor('#A053A0'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). ;
                       break;
                   
                   default:    //Categoria 14+
                       $eventEntity->setBgColor('#AC92EC'); //set the background color of the event's label
                       $eventEntity->setFgColor('#FFF'); //set the foreground color of the event's label
                       //$title = '</div><div class="fa fa-close"> | '.$title/*' | '.$companyEvent->getEstado(). ;
                       break;
               }
               */
             switch ($companyEvent->getEstado()) {
                 case "A":
                     //Asistida
                     //$eventEntity->setBgColor('#48CFAD'); //set the background color of the event's label
                     //$eventEntity->setFgColor('#000'); //set the foreground color of the event's label
                     $title = '<div class="col-xs-1 fa fa-calendar-check-o" style="border:1px solid #C3C3C3; border-right:0px solid #F00; color:#FFF; height: 100%; float: left; background: #69BD45;  position: absolute; padding-left:2px "></div> <div class="col-xs-11" style="border-left:0px solid #000 !important; border:1px solid #C3C3C3;  height: 100%; float: right; position: relative; "> | ' . $title . '</div>';
                     break;
                 case "P":
                     //Pendiente
                     //$eventEntity->setBgColor('#4FC1E9'); //set the background color of the event's label
                     //$eventEntity->setFgColor('#000'); //set the foreground color of the event's label
                     $title = '<div class=" col-xs-1 fa fa-calendar-minus-o" style="border:1px solid #C3C3C3; border-right:0px solid #F00; color:#FFF; height: 100%; float: left; background: #3852A4;  position: absolute; padding-left:2px "></div> <div class="col-xs-11" style="border-left:0px solid #000 !important; border:1px solid #C3C3C3; height: 100%; float: right; position: relative; "> | ' . $title . '</div>';
                     break;
                 case "C":
                     //Cancelada
                     //$eventEntity->setBgColor('#ED5565'); //set the background color of the event's label
                     //$eventEntity->setFgColor('#000'); //set the foreground color of the event's label
                     $title = '<div class="col-xs-1 fa fa-calendar-times-o" style="border:1px solid #C3C3C3; border-right:0px solid #F00; color:#FFF; height: 100%; float: left; background: #F00;  position: absolute; padding-left:2px "></div> <div class="col-xs-11" style="border-left:0px solid #000 !important; border:1px solid #C3C3C3; height: 100%; float: right; position: relative; "> | ' . $title . '</div>';
                     break;
                 case "N":
                     //No asistida
                     //$eventEntity->setBgColor('#ED5565'); //set the background color of the event's label
                     //$eventEntity->setFgColor('#000'); //set the foreground color of the event's label
                     $title = '<div class="col-xs-1 fa fa-calendar-o" style="border:1px solid #C3C3C3; border-right:0px solid #F00; color:#FFF; height: 100%; float: left; background: #421E5B;  position: absolute; padding-left:2px "></div> <div class="col-xs-11" style="border-left:0px solid #000 !important; border:1px solid #C3C3C3; height: 100%; float: right; position: relative; "> | ' . $title . '</div>';
                     break;
             }
             $eventEntity->setTitle($title);
             //$eventEntity->setUrl($unicode);
             //$eventEntity->setUrl('http://www.google.com'); // url to send user to when event label is clicked
             //$eventEntity->setCssClass('my-custom-class'); // a custom class you may want to apply to event labels
             //var_dump($eventEntity);
             //finally, add the event to the CalendarEvent for displaying on the calendar
             $calendarEvent->addEvent($eventEntity);
         }
         // fin de foreach para citas
     }
 }
 public function loadEvents(CalendarEvent $calendarEvent)
 {
     $startDate = $calendarEvent->getStartDatetime();
     $endDate = $calendarEvent->getEndDatetime();
     // The original request so you can get filters from the calendar
     // Use the filter in your query for example
     $request = $calendarEvent->getRequest();
     $filter = $request->get('filter');
     // load events using your custom logic here,
     // for instance, retrieving events from a repository
     /*=================================================*/
     /* I) Détermine quel type d'utilisateur est connecté*/
     /* Pourrait être remplacé par $utilisateur->getType()
        Mais impossible car il type n'est pas un attribut de la
        BDD; c'est uniquement un champs dans la BDD pour déterminer
        qui est User,Etudiant ou Prof...
        /*=================================================*/
     /* recuperation de l'utlilisateur actuelle */
     $utilisateur = $this->container->get('security.context')->getToken()->getUser();
     /* l'entite manager, pour intérgair avec la BDD */
     /* construction de la requete */
     $query = $this->entityManager->getRepository('UserBundle:Etudiant')->createQueryBuilder('a')->where('a.id = :iduser')->setParameter('iduser', $utilisateur->getId());
     /*exectuon de la requete*/
     $etudiant = $query->getQuery()->getOneOrNullResult();
     /* on ne veut qu'un seul resultat, donc pas de getResult()*/
     if ($etudiant == NULL) {
         $query = $this->entityManager->getRepository('UserBundle:Professeur')->createQueryBuilder('a')->where('a.id = :iduser')->setParameter('iduser', $utilisateur->getId());
         $professeur = $query->getQuery()->getOneOrNullResult();
         if ($professeur == NULL) {
             $type = 'user';
         } else {
             $type = 'professeur';
         }
     } else {
         $type = 'etudiant';
     }
     /*====================================================================*/
     /* II) Recherche des evenements en fonction du type de l'utilisateur */
     /*====================================================================*/
     switch ($type) {
         case 'user':
             $companyEvents = $this->entityManager->getRepository('EDTBundle:Evenement')->createQueryBuilder('company_events')->join('company_events.type', 't')->addSelect('t')->getQuery()->getResult();
             break;
         case 'professeur':
             $companyEvents = $this->entityManager->getRepository('EDTBundle:Evenement')->createQueryBuilder('company_events')->where('company_events.professeur = :prof')->join('company_events.type', 't')->addSelect('t')->setParameter('prof', $utilisateur)->getQuery()->getResult();
             break;
         case 'etudiant':
             $companyEvents = $this->entityManager->getRepository('EDTBundle:Evenement')->createQueryBuilder('company_events')->join('company_events.type', 't')->addSelect('t')->leftJoin('company_events.groupes', 'groupes')->where('groupes.id = :id_groupe')->setParameter('id_groupe', $etudiant->getGroupe()->getId())->getQuery()->getResult();
             break;
     }
     // $companyEvents and $companyEvent in this example
     // represent entities from your database, NOT instances of EventEntity
     // within this bundle.
     //
     // Create EventEntity instances and populate it's properties with data
     // from your own entities/database values.
     foreach ($companyEvents as $companyEvent) {
         // create an event with a start/end time, or an all day event
         if ($companyEvent->getAllDayEvent() === false) {
             $eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), $companyEvent->getEndDatetime());
         } else {
             $eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), null, true);
         }
         $color = '#00FFFF';
         if ($companyEvent) {
             switch ($companyEvent->getType()->getNom()) {
                 case 'CM':
                     $color = '#0000FF';
                     break;
                 case 'TD':
                     $color = '#FF0000';
                     break;
                 case 'TP':
                     $color = '#00FF00';
                     break;
                 case 'TDI':
                     $color = '#FF00FF';
                     break;
             }
         }
         $eventEntity->setBgColor($color);
         //set the background color of the event's label
         $eventEntity->setFgColor('#FFFFFF');
         //set the foreground color of the event's label
         $eventEntity->setUrl('#');
         // url to send user to when event label is clicked
         //$eventEntity->setCssClass('my-custom-class'); // a custom class you may want to apply to event labels
         //finally, add the event to the CalendarEvent for displaying on the calendar
         $calendarEvent->addEvent($eventEntity);
     }
 }