0

I use https://github.com/tattali/CalendarBundle#1-download-calendarbundle-using-composer I work with symfony4.2.9

I took almost the same code(just putted dates in the events) and I can't see the events in the calendar. No error, no troubleshooting with Ajax, but nothing append. The calendar is displayed but empty

namespace App\EventListener;
use CalendarBundle\Entity\Event;
use CalendarBundle\Event\CalendarEvent;

class CalendarListener
{
  public function load(CalendarEvent $calendar)
  {
    $start = $calendar->getStart();
    $end = $calendar->getEnd();
    $filters = $calendar->getFilters();

    // You may want to make a custom query to fill the calendar

    $calendar->addEvent(new Event(
        'Event 1',
        new \DateTime( '2019-06-05'),
        new \DateTime( '2019-06-05')
    ));

    // If the end date is null or not defined, it creates a all day event
    $calendar->addEvent(new Event(
        'All day event',
        new \DateTime( '2019-06-06')
    ));
  }
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Welcome!</title>
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
        <link rel="stylesheet" href="/css/bootstrap.min.css">
        <link rel="stylesheet" href="/css/app.css">

            <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fullcalendar/core@4.1.0/main.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fullcalendar/daygrid@4.1.0/main.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fullcalendar/timegrid@4.1.0/main.min.css">

        <script src="/js/jquery.min.js"></script>

    </head>
<body>
<nav class="navbar navbar-expand-lg  bg-">
            <a class="navbar-brand" href="/">Share</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarColor01">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item active">
                        <a class="nav-link" href="/account/dashboard"><i class="fas fa-chart-line fa-2x"></i>  Tableau de bord</a>
                    </li>
                    <li class="nav-item ">
                        <a class="nav-link" href="/dashboard/showMines"><i class="fas fa-hands-helping fa-2x"></i>  offres d'atelier <span class="badge-pill badge-danger dash">3</span> </a>
                    </li>
                    <li class="nav-item ">
                        <a class="nav-link" href="/dashbord/books"><i class="fas fa-graduation-cap fa-2x "></i>  cours pris<span class="badge-pill badge-danger dash">2</span></a>
                    </li>
                    <li class="nav-item ">
                        <a class="nav-link" href="/dashboard/courses"><i class="fas fa-chalkboard-teacher fa-2x"></i>  cours donnés</a>
                    </li>
                     <li class="nav-item ">
                        <a class="nav-link" href="/dashboard/calendar"><i class="fas fa-calendar-alt fa-2x"></i>  mon agenda</a>
                    </li>

                </ul>

                <ul class="navbar-nav ml-auto align-items-center">
                                <li class="nev-item">
                    <a href="/" class="nav-link" ><i class="fas fa-home fa-2x"></i></i>  Retour à l'accueil</a>
                </li>
                <li class="nav-item dropdown">

                    <a href="#" class="nav-link dropdown-toggle" id="accountDropdownlink" data-toggle="dropdown">
                        <img src="https://randomuser.me/api/portraits/women/56.jpg" alt="Avatar de Cécile" class="avatar avatar-small" class="mr-2"><span class="ml-2 mt-5">Cécile</span>
                    </a>

                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="accountDropdownlink">
                    <a class="dropdown-item" href="/activity/new">Créer une activité</a>
                        <div class="dropdown-divider"></div>

                        <a class="dropdown-item" href="/account">Mon compte</a>

                  <a class="dropdown-item" href="/account/edit">Modifier mon profil</a>
                        <div class="dropdown-divider"></div>

                        <a class="dropdown-item" href="/logout">Déconnexion</a>

                </div>

                </li>    



                </ul>

            </div>
        </nav></div>



<div class="container mt-5">
    <div id="calendar-holder"></div>
</div>    


<footer class="bg-warning text-center py-3 mt-3">


</footer>

<script src="/js/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>


    <script>

    document.addEventListener('DOMContentLoaded', () => {

    var calendarEl = document.getElementById('calendar-holder');

    var calendar = new FullCalendar.Calendar(calendarEl, {
        //locale: 'fr',
        defaultView: 'dayGridMonth',
        editable: true,
        eventSources: [
            {
                url: "/fc-load-events",
                method: "POST",
                extraParams: {
                  //  filters: JSON.stringify({})
                },
                failure: () => {
                     alert("There was an error while fetching FullCalendar!");
                },
            },
        ],
        header: {
            locale:'fr',
            left: 'prev,next today',
            center: 'title',
            right: 'dayGridMonth,timeGridWeek,timeGridDay',
        },
        plugins: [ 'interaction', 'dayGrid', 'timeGrid' ], // https://fullcalendar.io/docs/plugin-index
        timeZone: 'Europe/Paris',
    });
   calendar.setOption('locale', 'fr');

    calendar.render();



});

    </script>

    <script src="https://cdn.jsdelivr.net/npm/@fullcalendar/core@4.1.0/main.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@fullcalendar/interaction@4.1.0/main.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@fullcalendar/daygrid@4.1.0/main.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@fullcalendar/timegrid@4.1.0/main.min.js"></script>


I expect to see my events :), if someone has an idea about what's wrong

ADyson
  • 57,178
  • 14
  • 51
  • 63
cessother
  • 127
  • 1
  • 1
  • 9
  • Can you please post the JavaScript and HTML code which is generated by this PHP? – ADyson Jun 05 '19 at 07:23
  • Done, I hope that's what you need – cessother Jun 05 '19 at 07:47
  • You mentioned you troubleshooted the AJAX, so what exactly was in the raw response from the `fc-events` URL? There would need to be an array of valid events in JSON format. I'm not familiar with symfony admittedly, but it's unclear to me how the PHP code shown would, by itself, result in such a response. Does the `$calendar` object get turned into JSON at some point? – ADyson Jun 05 '19 at 08:23
  • I have trooble with ajax and the request is : start=2019-05-26T00%3A00%3A00&end=2019-07-07T00%3A00%3A00&timeZone=Europe%2FParis – cessother Jun 05 '19 at 08:43
  • It's just the date of beginning and end of the calendar. I've tried to load the calendar without filters, but still nothing append – cessother Jun 05 '19 at 08:44
  • In the question you said you had no trouble with the AJAX. But ok. What trouble do you have exactly? You've shown me what request is sent, but what I want to know is what **response** is received? Do you understand how to look for that in your browser's Network tool? e.g. This shows you where to find it using Chrome: https://developers.google.com/web/tools/chrome-devtools/network/reference#response . – ADyson Jun 05 '19 at 09:00
  • In your case, click on the `/fc-load-events` URL in your network tab and then click on the Response tab. If it was working correctly, I would expect to see something like `[{ "title": "Event 1", "start": "2019-06-05", "end": "2019-06-05" }, { "title": "All day event", "start": "2019-06-06" }]` in the response body – ADyson Jun 05 '19 at 09:03
  • Also check this route /fc-load-events on the router file... – Pedro Serpa Jun 05 '19 at 09:10
  • @ADyson, the response i json [ ]. Maybe there is a problem with the date format ? – cessother Jun 05 '19 at 10:04
  • @Pedro Serpa, do you mean th file routes.yaml ? – cessother Jun 05 '19 at 10:06
  • that wouldn't cause it to return just an empty array. I would expect it to generate an exception or similar if you used an invalid date format. Anyway [this simple demo](http://sandbox.onlinephpfunctions.com/code/e8d09f02bf64d313f423565e42675e0c508e33b7) proves there's nothing wrong with how you're writing the dates. More likely the serialisation process is going wrong or not happening somehow. You'll have to debug the PHP in more depth. – ADyson Jun 05 '19 at 10:08

0 Answers0