Feature: [calendar] associate document with calendar

This commit is contained in:
2022-10-20 21:35:57 +02:00
parent 1ec3e176fb
commit 2b1d9cabff
5 changed files with 329 additions and 0 deletions

View File

@@ -116,6 +116,17 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
*/
private CommentEmbeddable $comment;
/**
* @ORM\Column(type="integer", nullable=false, options={"default": 0})
*/
private int $dateTimeVersion = 0;
/**
* @var Collection<CalendarDoc::class>
* @ORM\OneToMany(targetEntity=CalendarDoc::class, mappedBy="calendar", orphanRemoval=true)
*/
private Collection $documents;
/**
* @ORM\Column(type="datetime_immutable", nullable=false)
* @Serializer\Groups({"calendar:read", "read", "calendar:light", "docgen:read"})
@@ -216,12 +227,25 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
public function __construct()
{
$this->comment = new CommentEmbeddable();
$this->documents = new ArrayCollection();
$this->privateComment = new PrivateCommentEmbeddable();
$this->persons = new ArrayCollection();
$this->professionals = new ArrayCollection();
$this->invites = new ArrayCollection();
}
/**
* @internal use @{CalendarDoc::__construct} instead
*/
public function addDocument(CalendarDoc $calendarDoc): self
{
if ($this->documents->contains($calendarDoc)) {
$this->documents[] = $calendarDoc;
}
return $this;
}
/**
* @internal Use {@link (Calendar::addUser)} instead
*/
@@ -287,6 +311,19 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
return $this->comment;
}
/**
* Each time the date and time is update, this version is incremented.
*/
public function getDateTimeVersion(): int
{
return $this->dateTimeVersion;
}
public function getDocuments(): Collection
{
return $this->documents;
}
/**
* @Serializer\Groups({"docgen:read"})
*/
@@ -472,6 +509,18 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
]));
}
/**
* @internal use @{CalendarDoc::setCalendar} with null instead
*/
public function removeDocument(CalendarDoc $calendarDoc): self
{
if ($calendarDoc->getCalendar() !== $this) {
throw new LogicException('cannot remove document of another calendar');
}
return $this;
}
/**
* @internal Use {@link (Calendar::removeUser)} instead
*/
@@ -562,6 +611,10 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
public function setEndDate(DateTimeImmutable $endDate): self
{
if ($this->endDate->getTimestamp() !== $endDate->getTimestamp()) {
$this->increaseaDatetimeVersion();
}
$this->endDate = $endDate;
return $this;
@@ -609,6 +662,10 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
public function setStartDate(DateTimeImmutable $startDate): self
{
if ($this->startDate->getTimestamp() !== $startDate->getTimestamp()) {
$this->increaseaDatetimeVersion();
}
$this->startDate = $startDate;
return $this;
@@ -631,4 +688,9 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
private function increaseaDatetimeVersion(): void
{
++$this->dateTimeVersion;
}
}