mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Feature: [calendar] associate document with calendar
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user