feat: automatic saving of drafts when editing bookings

This commit is contained in:
Björn Fromme
2026-01-06 10:29:17 +01:00
parent 97f8baba06
commit 60c1459902
7 changed files with 759 additions and 52 deletions
+82
View File
@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\BookingEditDraftRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: BookingEditDraftRepository::class)]
#[ORM\Table(name: 'booking_edit_draft')]
#[ORM\UniqueConstraint(name: 'user_booking_unique', columns: ['user_id', 'booking_id'])]
class BookingEditDraft
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private User $user;
#[ORM\Column(type: 'integer')]
private int $bookingId;
#[ORM\Column(type: 'json')]
private array $formData = [];
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $createdAt;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $updatedAt;
public function __construct(User $user, int $bookingId, array $formData)
{
$this->user = $user;
$this->bookingId = $bookingId;
$this->formData = $formData;
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): User
{
return $this->user;
}
public function getBookingId(): int
{
return $this->bookingId;
}
public function getFormData(): array
{
return $this->formData;
}
public function setFormData(array $formData): static
{
$this->formData = $formData;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
{
return $this->updatedAt;
}
}