'', 'closingDate' => DateTime::class, 'confidential' => '', 'confidentialText' => '', 'createdAt' => DateTime::class, 'createdBy' => User::class, 'emergency' => '', 'emergencyText' => '', 'openingDate' => DateTime::class, 'originText' => '', 'requestorAnonymous' => false, 'socialIssues' => [], 'intensity' => '', 'step' => '', 'closingMotiveText' => '', 'socialIssuesText' => '', 'scopes' => [], 'scopesText' => '', 'ref' => User::class, 'participations' => [], ]; private ClosingMotiveRender $closingMotiveRender; private ScopeResolverDispatcher $scopeResolverDispatcher; private SocialIssueRender $socialIssueRender; private TranslatableStringHelper $translatableStringHelper; private TranslatorInterface $translator; public function __construct( TranslatorInterface $translator, TranslatableStringHelper $translatableStringHelper, SocialIssueRender $socialIssueRender, ClosingMotiveRender $closingMotiveRender, ScopeResolverDispatcher $scopeResolverDispatcher ) { $this->translator = $translator; $this->translatableStringHelper = $translatableStringHelper; $this->socialIssueRender = $socialIssueRender; $this->closingMotiveRender = $closingMotiveRender; $this->scopeResolverDispatcher = $scopeResolverDispatcher; } /** * @param AccompanyingPeriod|null $period */ public function normalize($period, ?string $format = null, array $context = []) { if ($period instanceof AccompanyingPeriod) { $scopes = $this->scopeResolverDispatcher->isConcerned($period) ? $this->scopeResolverDispatcher->resolveScope($period) : []; if (!is_array($scopes)) { $scopes = [$scopes]; } $dateContext = array_merge($context, ['docgen:expects' => DateTime::class, 'groups' => 'docgen:read']); $userContext = array_merge($context, ['docgen:expects' => User::class, 'groups' => 'docgen:read']); $participationContext = array_merge($context, ['docgen:expects' => AccompanyingPeriodParticipation::class, 'groups' => 'docgen:read']); return [ 'id' => $period->getId(), 'closingDate' => $this->normalizer->normalize($period->getClosingDate(), $format, $dateContext), 'confidential' => $period->isConfidential(), 'createdAt' => $this->normalizer->normalize($period->getCreatedAt(), $format, $dateContext), 'createdBy' => $this->normalizer->normalize($period->getCreatedBy(), $format, $userContext), '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])), 'participations' => $this->normalizer->normalize($period->getParticipations(), $format, $participationContext), 'currentParticipations' => $this->normalizer->normalize($period->getCurrentParticipations(), $format, $participationContext), 'requestorAnonymous' => $period->isRequestorAnonymous(), 'requestor' => $this->normalizer->normalize($period->getRequestor(), $format, array_merge($context, ['docgen:expects' => Person::class])), 'resources' => $this->normalizer->normalize($period->getResources(), $format, $context), 'scopes' => $this->normalizer->normalize($period->getScopes(), $format, array_merge($context, ['docgen:expects' => Scope::class, 'groups' => 'docgen:read'])), 'socialIssues' => $this->normalizer->normalize($period->getSocialIssues(), $format, $context), 'intensity' => $this->translator->trans($period->getIntensity()), 'step' => $this->translator->trans('accompanying_period.' . $period->getStep()), 'emergencyText' => $period->isEmergency() ? $this->translator->trans('accompanying_period.emergency') : '', 'confidentialText' => $period->isConfidential() ? $this->translator->trans('confidential') : '', //'originText' => null !== $period->getOrigin() ? $this->translatableStringHelper->localize($period->getOrigin()->getLabel()) : '', 'isClosed' => $period->getClosingDate() !== null, 'closingMotiveText' => null !== $period->getClosingMotive() ? $this->closingMotiveRender->renderString($period->getClosingMotive(), []) : '', 'ref' => $this->normalizer->normalize($period->getUser(), $format, $userContext), 'hasRef' => $period->getUser() !== null, 'socialIssuesText' => implode(', ', array_map(function (SocialIssue $s) { return $this->socialIssueRender->renderString($s, []); }, $period->getSocialIssues()->toArray())), 'scopesText' => implode(', ', array_map(function (Scope $s) { return $this->translatableStringHelper->localize($s->getName()); }, $scopes)), //'scopes' => $scopes, 'hasRequestor' => $period->getRequestor() !== null, ]; } elseif (null === $period) { return self::PERIOD_NULL; } throw new InvalidArgumentException('this neither an accompanying period or null'); } public function supportsNormalization($data, ?string $format = null, array $context = []): bool { if ('docgen' !== $format) { return false; } if ($data instanceof AccompanyingPeriod) { /*if (array_key_exists(self::IGNORE_FIRST_PASS_KEY, $context) && in_array(spl_object_hash($data), $context[self::IGNORE_FIRST_PASS_KEY], true)) { return false; }*/ return true; } if (null === $data && AccompanyingPeriod::class === ($context['docgen:expects'] ?? null)) { return true; } return false; } }