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,
Voici donc mon entité Booking:
<?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 :
<?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
$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.