endpoint for recent accompanying period attributions

This commit is contained in:
2022-01-28 15:39:37 +01:00
parent fcd5fba13e
commit 292c9380ad
6 changed files with 132 additions and 19 deletions

View File

@@ -338,7 +338,8 @@ class AccompanyingPeriod implements
private ?User $user = null;
/**
* @ORM\OneToMany(targetEntity=UserHistory::class, mappedBy="accompanyingPeriod")
* @ORM\OneToMany(targetEntity=UserHistory::class, mappedBy="accompanyingPeriod", orphanRemoval=true,
* cascade={"persist", "remove"})
*
* @var Collection|UserHistory[]
*/
@@ -1226,15 +1227,15 @@ class AccompanyingPeriod implements
if ($this->user !== $user) {
$this->userPrevious = $this->user;
if (null !== $user) {
$this->userHistories->add(new UserHistory($this, $user));
}
foreach ($this->userHistories as $history) {
if (null === $history->getEndDate()) {
$history->setEndDate(new DateTimeImmutable('now'));
}
}
if (null !== $user) {
$this->userHistories->add(new UserHistory($this, $user));
}
}
$this->user = $user;