Cómo personalizar los datos de FullCalenderBundle

He añadido un formulario de selección sobre el calendario para seleccionar un usuario y mostrar sus eventos (por ejemplo, reserva de entidad) en el calendario completo

así que mi pregunta es, ¿cómo cambian los datos de FullCalenderBundle por el usuario seleccionado en el formulario?

esto es algunos de los archivos,

FullCalenderListener.php

em = $em; $this->router = $router; $this->security = $security; } public function loadEvents(CalendarEvent $calendar) { $startDate = $calendar->getStart(); $endDate = $calendar->getEnd(); $filters = $calendar->getFilters(); // Modify the query to fit to your entity and needs // Change b.beginAt by your start date in your custom entity $user = $this->security->getUser(); $bookings = $this->em->getRepository(Booking::class) ->createQueryBuilder('b') ->where('b.Responsable = :responsable') ->setParameter('responsable', $user->getUsername()) ->andWhere('b.beginAt BETWEEN :startDate and :endDate') ->setParameter('startDate', $startDate->format('Ymd H:i:s')) ->setParameter('endDate', $endDate->format('Ymd H:i:s')) ->getQuery()->getResult(); foreach($bookings as $booking) { // this create the events with your own entity (here booking entity) to populate calendar $bookingEvent = new Event( $booking->getTitle(), $booking->getBeginAt(), $booking->getEndAt() // If the end date is null or not defined, it creates a all day event ); /* * Optional calendar event settings * * For more information see : Toiba\FullCalendarBundle\Entity\Event * and : https://fullcalendar.io/docs/event-object */ // $bookingEvent->setUrl('http://www.google.com'); // $bookingEvent->setBackgroundColor($booking->getColor()); // $bookingEvent->setCustomField('borderColor', $booking->getColor()); $bookingEvent->setUrl( $this->router->generate('booking_show', array( 'id' => $booking->getId(), )) ); // finally, add the booking to the CalendarEvent for displaying on the calendar $calendar->addEvent($bookingEvent); } } } 

calendar.html.twig

 {% extends 'base.html.twig' %} {% block body %} 
Choose a user
{{ form(form) }}
Create new booking {% include '@FullCalendar/Calendar/calendar.html.twig' %}
{% endblock %} {% block stylesheets %} {{ parent() }} {% endblock %} {% block javascripts %} {{ parent() }} $(function () { $('#calendar-holder').fullCalendar({ height: 'parent', themeSystem: 'bootstrap4', locale: 'fr', header: { left: 'prev, next, today', center: 'title', right: 'month, agendaWeek, agendaDay' }, businessHours: { start: '09:00', end: '18:00', dow: [1, 2, 3, 4, 5] }, height: "auto", contentHeight: "auto", lazyFetching: true, navLinks: true, selectable: true, editable: true, eventDurationEditable: true, eventSources: [ { url: "{{ path('fullcalendar_load_events') }}", type: 'POST', data: { filters: {} }, error: function () { alert('There was an error while fetching FullCalendar!'); } } ] }); }); {% endblock %}

He intentado tanto y no puedo hacerlo, gracias por tu ayuda

Debes crear una selección de tus usuarios y hacer algo como esto.

 $('#users').on('change', function() { var userId = this.value; $('#calendar-holder').fullCalendar({ eventSources: [{ url: "{{ path('fullcalendar_load_events') }}", type: 'POST', data: { filters: { user_id: userId, } }, error: function () { alert('There was an error while fetching FullCalendar!'); } }] }); $('#calendar-holder').fullCalendar('refetchEvents'); }); 

en su oyente ahora puede actualizar la consulta en consecuencia

 $bookings = $this->em->getRepository(Booking::class) ->createQueryBuilder('booking') ->where('booking.beginAt BETWEEN :startDate and :endDate') ->innerJoin('booking.user', 'user') ->andWhere('user.id = :userId') ->setParameter('userId', $filters['user_id']) ->setParameter('startDate', $startDate->format('Ymd H:i:s')) ->setParameter('endDate', $endDate->format('Ymd H:i:s')) ->getQuery()->getResult(); 
Intereting Posts