Symfony 4 - FullCalenderBundle - Полдня? - PullRequest
       13

Symfony 4 - FullCalenderBundle - Полдня?

0 голосов
/ 28 сентября 2019

Я использую комплект fullCalendar: https://github.com/tattali/CalendarBundle

Я использую его для отображения отсутствий в календаре.Эти пропуски могут соответствовать полному дню, полдня (утром или полудню) или временному интервалу.

За исключением того, что я не понимаю, как отображать полдня и интервалы

Iмой слушатель:

<?php

namespace App\EventListener;

use App\Repository\AbsenceRepository;
use App\Services\ValidationService;
use CalendarBundle\Entity\Event;
use CalendarBundle\Event\CalendarEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;

class CalendarListener
{
    private $repoAbsences;
    private $router;
    private $validationService;
    private $security;


    public function __construct(AbsenceRepository $repoAbsence, UrlGeneratorInterface $router, ValidationService $validationService, Security $security)
    {
        $this->repoAbsences = $repoAbsence;
        $this->router = $router;
        $this->validationService = $validationService;
        $this->security = $security;
    }

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

        $query = $this->repoAbsences
            ->createQueryBuilder('a')
            ->join("a.user", "u")
            ->join("u.groupe", "g")
            ->andWhere('a.dateDebut BETWEEN :start and :end')
            ->andWhere("a.etat = 'En attente'")
            ->setParameter('start', $start->format('Y-m-d H:i:s'))
            ->setParameter('end', $end->format('Y-m-d H:i:s'));

        if ($filters['user_name'] != "") {
            $query->andWhere("u.nom LIKE :name OR u.prenom LIKE :name")
                ->setParameter('name', $filters['user_name'] . '%');
        }

        if ($filters['service_name'] != "") {
            $query->andWhere('g.nom = :service')
                ->setParameter('service', $filters['service_name']);
        }

        $absences = $query->getQuery()
            ->getResult();


        $user = $this->security->getUser();

        $absences = $this->validationService->getDemandesCongesForCalendar($user, $absences);


        foreach ($absences as $absence) {

            $absenceEvent = new Event(
                $absence->getUser()->getFullName(),
                $absence->getDateDebut(),
                $absence->getDateFin()
            );
            $calendar->addEvent($absenceEvent);
        }
    }
}

И мой JS:

{% block javascripts %}

    <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>
    <script src="https://cdn.jsdelivr.net/npm/@fullcalendar/core@4.1.0/locales/fr.js"></script>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            var calendarEl = document.getElementById('calendar-holder');

            var user = document.getElementById("name").value;
            var service = document.getElementById("service").value;

            console.log(user);
            console.log(service);


            var calendar = new FullCalendar.Calendar(calendarEl, {

                locale: 'fr',
                height: 450,
                contentHeight: 450,
                aspectRatio: 2.5,
                defaultView: 'dayGridMonth',
                editable: false,
                eventSources: [
                    {
                        url: "/fc-load-events",
                        method: "POST",
                        extraParams: {
                            filters: JSON.stringify(
                                {user_name: user, service_name: service}
                            )
                        },
                        failure: () => {
                            alert("Une erreur est survenue lors du chargement de l'agenda !");
                        }
                    },
                ],
                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();
        });
    </script>

{% endblock %}

Могу ли я сделать это в моем слушателе?

...