Bonjour,

Je désire mettre en place un calendrier de réservations. Pour ce faire, j'utilise le bundle tattali/CalendarBundle interagissant avec fullCalendar.

Je sais créer une réservation et afficher toutes les réservations dans un calendrier. Cependant, je voudrais qu'une réservation soit liée à un véhicule et pour chaque véhicule, qu'un calendrier n'affiche que les réservations liées à celui-ci.

Donc, voici mon entité Booking :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
<?php
 
namespace App\Entity;
 
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 
/**
 * @ORM\Entity(repositoryClass="App\Repository\BookingRepository")
 * 
 * @UniqueEntity(
 *               fields={"beginAt"},
 *               message="Une réservation existe déjà avec cette date de début."
 * )
 */
class Booking
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;
 
    /**
     * @ORM\Column(type="datetime")
     * 
     * @Assert\NotBlank(
     *      message = "La date de construction ne peut pas être vide."
     * )
     * @Assert\Type("\DateTime")
     * @Assert\GreaterThan("today")
     */
    private $beginAt;
 
    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $endAt;
 
    /**
     * @ORM\Column(type="string", length=255)
     */
    private $title;
 
    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Vehicle", inversedBy="bookings")
     * @ORM\JoinColumn(nullable=false)
     */
    private $vehicle;
 
    public function getId(): ?int
    {
        return $this->id;
    }
 
    public function getBeginAt(): ?\DateTimeInterface
    {
        return $this->beginAt;
    }
 
    public function setBeginAt(\DateTimeInterface $beginAt): self
    {
        $this->beginAt = $beginAt;
 
        return $this;
    }
 
    public function getEndAt(): ?\DateTimeInterface
    {
        return $this->endAt;
    }
 
    public function setEndAt(?\DateTimeInterface $endAt): self
    {
        $this->endAt = $endAt;
 
        return $this;
    }
 
    public function getTitle(): ?string
    {
        return $this->title;
    }
 
    public function setTitle(string $title): self
    {
        $this->title = $title;
 
        return $this;
    }
 
    public function getVehicle(): ?Vehicle
    {
        return $this->vehicle;
    }
 
    public function setVehicle(?Vehicle $vehicle): self
    {
        $this->vehicle = $vehicle;
 
        return $this;
    }
}
Afin d'afficher les réservations dans le calendrier, j'ai ce listener :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 
<?php
 
namespace App\Listener;
 
use App\Entity\Booking;
use App\Repository\BookingRepository;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use CalendarBundle\Entity\Event;
use CalendarBundle\Event\CalendarEvent;
 
class CalendarListener
{
    private $bookingRepository;
    private $router;
 
    public function __construct(BookingRepository $bookingRepository, UrlGeneratorInterface $router) 
    {
 
        $this->bookingRepository = $bookingRepository;
        $this->router = $router;
 
    }
 
    public function load(CalendarEvent $calendar): void
    {
 
        $start = $calendar->getStart()->format('Y-m-d H:i:s');
        $end = $calendar->getEnd()->format('Y-m-d H:i:s');
 
        $filters = $calendar->getFilters();
 
        $bookings = $this->bookingRepository->findBetweenDates($start, $end);
 
        foreach ($bookings as $booking) 
        {
 
            // this create the events with your data (here booking data) to fill calendar
            $bookingEvent = new Event(
                                        $booking->getTitle(),
                                        $booking->getBeginAt(),
                                        $booking->getEndAt() // If the end date is null or not defined, a all day event is created.
                                     )
            ;
 
            /*
             * 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
             */
 
            $bookingEvent->setOptions([
                                        'backgroundColor' => 'red',
                                        'borderColor' => 'red',
                                      ]
                                     )
            ;
 
            $bookingEvent->addOption(
                                        'url',
                                        $this->router->generate('admin.booking.show', ['id' => $booking->getId(),])
                                    )
            ;
 
            // finally, add the event to the CalendarEvent to fill the calendar
            $calendar->addEvent($bookingEvent);
 
        }
 
    }
 
}
Ce que désirerais faire, c'est passer un paramètre vehicle supplémentaire à ma fonction "findBetweenDates" afin de ne ramener que les réservations liées à celui-ci. Ca donnerait donc
Code : Sélectionner tout - Visualiser dans une fenêtre à part
$bookings = $this->bookingRepository->findBetweenDates($start, $end, $vehicle);
.

Cependant, malgré 2 jours de recherches, je ne vois pas comment transmettre ce paramètre véhicule à mon listener soit via l'objet calendar, soit directement à mon mistener.

Quelqu'un aurait une idée?

Merci d'avance pour votre aide.