add history for user in accompanying period (+ counter)

This commit is contained in:
2022-01-28 14:42:18 +01:00
parent 2cd51eed2e
commit fcd5fba13e
6 changed files with 196 additions and 31 deletions

View File

@@ -26,6 +26,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
use Chill\PersonBundle\Entity\AccompanyingPeriod\UserHistory;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\AccompanyingPeriodValidity;
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ParticipationOverlap;
@@ -336,6 +337,13 @@ class AccompanyingPeriod implements
*/
private ?User $user = null;
/**
* @ORM\OneToMany(targetEntity=UserHistory::class, mappedBy="accompanyingPeriod")
*
* @var Collection|UserHistory[]
*/
private Collection $userHistories;
/**
* Temporary field, which is filled when the user is changed.
*
@@ -368,6 +376,7 @@ class AccompanyingPeriod implements
$this->comments = new ArrayCollection();
$this->works = new ArrayCollection();
$this->resources = new ArrayCollection();
$this->userHistories = new ArrayCollection();
}
/**
@@ -1212,10 +1221,20 @@ class AccompanyingPeriod implements
return $this;
}
public function setUser(User $user): self
public function setUser(?User $user): self
{
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'));
}
}
}
$this->user = $user;