diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index a38b7055c..50213dd6c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -1507,6 +1507,16 @@ class AccompanyingPeriod implements return $this; } + public function getUserHistories(): ReadableCollection + { + return $this->userHistories; + } + + public function getCurrentUserHistory(): ?UserHistory + { + return $this->getUserHistories()->findFirst(fn (int $key, UserHistory $userHistory) => $userHistory->getEndDate() === null); + } + private function addStepHistory(AccompanyingPeriodStepHistory $stepHistory, array $context = []): self { if (!$this->stepHistories->contains($stepHistory)) { diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php index 80480cd33..a0f0f9a8e 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php @@ -17,7 +17,10 @@ use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher; +use Chill\MainBundle\Serializer\Normalizer\UserNormalizer; +use Chill\MainBundle\Templating\Entity\UserRender; use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\PersonBundle\AccompanyingPeriod\Events\UserRefEventSubscriber; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\Person; @@ -83,6 +86,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf { if ($period instanceof AccompanyingPeriod) { $scopes = $this->scopeResolverDispatcher->isConcerned($period) ? $this->scopeResolverDispatcher->resolveScope($period) : []; + $userHistory = $period->getCurrentUserHistory(); if (!\is_array($scopes)) { $scopes = [$scopes]; @@ -103,7 +107,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf 'closingMotive' => $this->normalizer->normalize($period->getClosingMotive(), $format, array_merge($context, ['docgen:expects' => AccompanyingPeriod\ClosingMotive::class])), 'confidential' => $period->isConfidential(), 'createdAt' => $this->normalizer->normalize($period->getCreatedAt(), $format, $dateContext), - 'createdBy' => $this->normalizer->normalize($period->getCreatedBy(), $format, $userContext), + 'createdBy' => $this->normalizer->normalize($period->getCreatedBy(), $format, [...$userContext, UserNormalizer::AT_DATE => $period->getCreatedAt()]), 'emergency' => $period->isEmergency(), 'openingDate' => $this->normalizer->normalize($period->getOpeningDate(), $format, $dateContext), 'origin' => $this->normalizer->normalize($period->getOrigin(), $format, array_merge($context, ['docgen:expects' => AccompanyingPeriod\Origin::class])), @@ -125,7 +129,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf 'isClosed' => null !== $period->getClosingDate(), 'closingMotiveText' => null !== $period->getClosingMotive() ? $this->closingMotiveRender->renderString($period->getClosingMotive(), []) : '', - 'ref' => $this->normalizer->normalize($period->getUser(), $format, $userContext), + 'ref' => $this->normalizer->normalize($userHistory?->getUser(), $format, [...$userContext, UserNormalizer::AT_DATE => $userHistory?->getStartDate()]), 'hasRef' => null !== $period->getUser(), 'socialIssuesText' => implode(', ', array_map(fn (SocialIssue $s) => $this->socialIssueRender->renderString($s, []), $period->getSocialIssues()->toArray())), 'scopesText' => implode(', ', array_map(fn (Scope $s) => $this->translatableStringHelper->localize($s->getName()), $scopes)),