How to customize the Data of FullCalenderBundle [Symfony4]

前端 未结 1 1848
甜味超标
甜味超标 2021-01-16 19:19

I have added a select form above the calendar to select an user and show his events(entity booking for example)on the Fullcalendar

so my question is, how the data of

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 20:04

    You should create a select of your users and do something like this

    $('#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');
    });
    

    in your listener you can now update the query accordingly

    $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('Y-m-d H:i:s'))
        ->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))
        ->getQuery()->getResult();
    

    0 讨论(0)
提交回复
热议问题