Closed aniskasmi closed 3 years ago
Hi ! I have same problem !
Do you still face this issue ? this probably in your event listener
@tattali My event listener is correct same of tutorial
` document.addEventListener('DOMContentLoaded', () => { var calendarEl = document.getElementById('calendar-holder');
var calendar = new FullCalendar.Calendar(calendarEl, {
defaultView: 'dayGridMonth',
themeSystem: 'bootstrap',
editable: true,
locale: 'fr',
eventSources: [
{
url: "{{ path('fc_load_events') }}",
method: "POST",
extraParams: {
filters: JSON.stringify({})
},
failure: () => {
// alert("There was an error while fetching FullCalendar!");
},
},
],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay',
},
plugins: [ 'interaction', 'dayGrid', 'timeGrid' ], // https://fullcalendar.io/docs/plugin-index
timeZone: 'UTC',
});
calendar.render();
});
`
Oh my bad, not event listener, event subscriber !
no problem this :
` /**
@var UrlGeneratorInterface */ private $router;
public function __construct( CommunityPublicationRepository $communityPublicationRepository, UrlGeneratorInterface $router ) { $this->communityPublication = $communityPublicationRepository; $this->router = $router; }
public static function getSubscribedEvents() { return [ CalendarEvents::SET_DATA => 'onCalendarSetData', ]; }
public function onCalendarSetData(CalendarEvent $calendar) { $start = $calendar->getStart(); $end = $calendar->getEnd(); $filters = $calendar->getFilters();
// Modify the query to fit to your entity and needs
// Change booking.beginAt by your start date property
$publications = $this->communityPublication
->createQueryBuilder('cm')
->where('cm.post_date BETWEEN :start and :end')
->setParameter('start', $start->format('Y-m-d H:i:s'))
->setParameter('end', $end->format('Y-m-d H:i:s'))
->getQuery()
->getResult()
;
foreach ($publications as $publication) {
// this create the events with your data (here booking data) to fill calendar
$endDate = $publication->getPostDate();
$endDate->modify('+ 1 hour');
$title = $publication->getStatusIcon().' '.$publication->getTitle();
$publicationEvent = new Event(
$title,
$publication->getPostDate(),
$endDate
);
/*
* Add custom options to events
*
* For more information see: https://fullcalendar.io/docs/event-object
* and: https://github.com/fullcalendar/fullcalendar/blob/master/src/core/options.ts
*/
$publicationEvent->setOptions([
'backgroundColor' => $publication->getSocialColor(),
'borderColor' => $publication->getSocialColor(),
]);
$publicationEvent->addOption(
'url',
$this->router->generate('community_publication_show', [
'id' => $publication->getId(),
])
);
// finally, add the event to the CalendarEvent to fill the calendar
$calendar->addEvent($publicationEvent);
}
} `
@tattali Any news ?
Sorry for the delay do you have something in your services.yaml
?
@tattali No problem
` parameters: google_recaptcha_site_key: '%env(GOOGLE_RECAPTCHA_SITE_KEY)%' picture_directory: '%kernel.project_dir%/public/uploads/pictures' pdf_signed_directory: '%kernel.project_dir%/public/uploads/accounting/quote/pdf/signed' admin_cm_publication_post: '%kernel.project_dir%/public/uploads/admin/cm/publication'
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller/'
tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\EventSubscriber\CalendarSubscriber:
tags:
- { name: 'kernel.event_listener', event: 'calendar.set_data', method: onCalendarSetData }`
you need to only have
App\EventSubscriber\CalendarSubscriber:
not
App\EventSubscriber\CalendarSubscriber:
tags:
- { name: 'kernel.event_listener', event: 'calendar.set_data', method: onCalendarSetData }
even without
App\EventSubscriber\CalendarSubscriber:
this should work because autoconfigure
is true
@tattali Is work perfect thx
Hi.
I have duplication of my all event but on database i have just 1 entry