mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
improve docgen wip
This commit is contained in:
@@ -16,6 +16,8 @@ use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Templating\Entity\ClosingMotiveRender;
|
||||
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
||||
@@ -89,17 +91,6 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
public function normalize($period, ?string $format = null, array $context = [])
|
||||
{
|
||||
if ($period instanceof AccompanyingPeriod) {
|
||||
$ignored = $context[self::IGNORE_FIRST_PASS_KEY] ?? [];
|
||||
$ignored[] = spl_object_hash($period);
|
||||
$initial =
|
||||
$this->normalizer->normalize($period, $format, array_merge(
|
||||
$context,
|
||||
[self::IGNORE_FIRST_PASS_KEY => $ignored, AbstractNormalizer::GROUPS => 'docgen:read']
|
||||
));
|
||||
|
||||
// some transformation
|
||||
$user = $initial['user'];
|
||||
unset($initial['user']);
|
||||
|
||||
$scopes = $this->scopeResolverDispatcher->isConcerned($period) ? $this->scopeResolverDispatcher->resolveScope($period) : [];
|
||||
|
||||
@@ -107,28 +98,45 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
$scopes = [$scopes];
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
// get a first default data
|
||||
$initial,
|
||||
// and add data custom
|
||||
[
|
||||
'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()) : '',
|
||||
'closingMotiveText' => null !== $period->getClosingMotive() ?
|
||||
$this->closingMotiveRender->renderString($period->getClosingMotive(), []) : '',
|
||||
'ref' => $user,
|
||||
'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,
|
||||
]
|
||||
);
|
||||
$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;
|
||||
}
|
||||
@@ -143,10 +151,10 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
}
|
||||
|
||||
if ($data instanceof AccompanyingPeriod) {
|
||||
if (array_key_exists(self::IGNORE_FIRST_PASS_KEY, $context)
|
||||
/*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;
|
||||
}
|
||||
|
@@ -64,6 +64,7 @@ class PersonDocGenNormalizer implements
|
||||
}
|
||||
|
||||
$data = [
|
||||
'kind' => 'person',
|
||||
'firstname' => $person->getFirstName(),
|
||||
'lastname' => $person->getLastName(),
|
||||
'altNames' => implode(
|
||||
|
@@ -171,11 +171,11 @@ class AccompanyingPeriodContext implements
|
||||
$options = $template->getOptions();
|
||||
|
||||
$data = [];
|
||||
$data['course'] = $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
|
||||
$data['course'] = $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => AccompanyingPeriod::class, 'groups' => 'docgen:read']);
|
||||
|
||||
foreach (['mainPerson', 'person1', 'person2'] as $k) {
|
||||
if ($options[$k]) {
|
||||
$data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', ['docgen:expects' => Person::class]);
|
||||
$data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', ['docgen:expects' => Person::class, 'groups' => 'docgen:read']);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user