mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Update AccompanyingPeriod normalization with UserHistory
The AccompanyingPeriod normalization now includes 'createdBy' and 'ref' fields from the UserHistory. AccompanyingPeriodDocGenNormalizer has been modified adding UserHistory retrieval and subsequently normalization. A new method was also added to the AccompanyingPeriod entity to retrieve the current UserHistory.
This commit is contained in:
parent
0ce9cdd07a
commit
350d991a85
@ -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)) {
|
||||
|
@ -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)),
|
||||
|
Loading…
x
Reference in New Issue
Block a user