adesigns / calendar-bundle

This bundle allows you to integrate the jQuery FullCalendar plugin into your Symfony2 application.
MIT License
96 stars 60 forks source link

Events Not loading #56

Closed BenArfanour closed 7 years ago

BenArfanour commented 7 years ago

I've installed this bundle , i followed all steps , rather the calendar displayed but i can't load events to see them on the calendar

`<?php /**

namespace metoBundle\EventListener;

use ADesigns\CalendarBundle\Entity\EventEntity; use Doctrine\ORM\EntityManager;

class CalendarEventListener { private $entityManager;

public function __construct(EntityManager $entityManager)
{
    $this->entityManager = $entityManager;
}

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('metoBundle:prog')
        ->createQueryBuilder('company_events')
        ->where('company_events.event_datetime 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();

    // $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);
        }

        //optional calendar event settings
        $eventEntity->setAllDay(true); // default is false, set to true if this is an all day event
        $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('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);
    }
}

} Service.xml <?xml version="1.0" ?>

` calendar-settings.js `$(function () { var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); $('#calendar-holder').fullCalendar({ header: { left: 'prev, next', center: 'title', right: 'month, basicWeek, basicDay,' }, lazyFetching: true, timeFormat: { // for agendaWeek and agendaDay agenda: 'h:mmt', // 5:00 - 6:30 // for all other views '': 'h:mmt' // 7p }, eventSources: [ { url: Routing.generate('fullcalendar_loader'), type: 'POST', // A way to add custom filters to your event listeners data: { filter: 'my_custom_filter_param' }, error: function() { //alert('There was an error while fetching Google Calendar!'); } } ] }); }); `
osshelouis commented 7 years ago

I had the same issue as well using this bundle, but i couldnt find any solution for this

mikeyudin commented 7 years ago

This issue is very vague. Without seeing your codebase, I cannot answer/solve this issue. The only thing I can recommend is try running your query outside of the event loader, using dates that would be passed in via the calendar JS.

Numerous people are successfully using this bundle, so I don't think there are any errors in the code.

mikeyudin commented 7 years ago

As mentioned in another issue:

This bundle does not care how you load events. All it does is dispatch the event "calendar.load_events", and expects your code to add events to the CalendarEvent class. It has no knowledge of how you are querying your database, or where the events are coming from. You are copying an example EventListener from the docs. That example does not need to match how your code works at all.

EventEntity is not meant to be used as a Doctrine Entity. You don't need to extend it. You just need to populate new instantiated EventEntity objects and pass them to the CalendarEvent.