mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
update normalizers to take into account referrerHistory logic for accompanying period work
This commit is contained in:
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use Chill\MainBundle\Serializer\Normalizer\UserNormalizer;
|
||||
use Chill\MainBundle\Workflow\Helper\MetadataExtractor;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
@@ -53,35 +54,51 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac
|
||||
$context
|
||||
);
|
||||
|
||||
// then, we add normalization for things which are not into the entity
|
||||
// add the referrers
|
||||
$initial['referrers'] = [];
|
||||
|
||||
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
|
||||
AccompanyingPeriodWork::class,
|
||||
$object->getId()
|
||||
);
|
||||
if ($object instanceof AccompanyingPeriodWork) {
|
||||
foreach ($object->getReferrersHistory() as $referrerHistory) {
|
||||
if (null !== $referrerHistory->getEndDate()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$initial['workflows_availables_evaluation'] = $this->metadataExtractor->availableWorkflowFor(
|
||||
AccompanyingPeriodWorkEvaluation::class
|
||||
);
|
||||
$initial['referrers'][] = $this->normalizer->normalize($referrerHistory->getUser(),
|
||||
$format, [...$context, UserNormalizer::AT_DATE => $referrerHistory->getStartDate()]);
|
||||
}
|
||||
}
|
||||
|
||||
$initial['workflows_availables_evaluation_documents'] = $this->metadataExtractor->availableWorkflowFor(
|
||||
AccompanyingPeriodWorkEvaluationDocument::class
|
||||
);
|
||||
if ($format === 'json') {
|
||||
|
||||
$workflows = $this->entityWorkflowRepository->findBy([
|
||||
'relatedEntityClass' => AccompanyingPeriodWork::class,
|
||||
'relatedEntityId' => $object->getId(),
|
||||
]);
|
||||
// then, we add normalization for things which are not into the entity
|
||||
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
|
||||
AccompanyingPeriodWork::class,
|
||||
$object->getId()
|
||||
);
|
||||
|
||||
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
|
||||
$initial['workflows_availables_evaluation'] = $this->metadataExtractor->availableWorkflowFor(
|
||||
AccompanyingPeriodWorkEvaluation::class
|
||||
);
|
||||
|
||||
$initial['workflows_availables_evaluation_documents'] = $this->metadataExtractor->availableWorkflowFor(
|
||||
AccompanyingPeriodWorkEvaluationDocument::class
|
||||
);
|
||||
|
||||
$workflows = $this->entityWorkflowRepository->findBy([
|
||||
'relatedEntityClass' => AccompanyingPeriodWork::class,
|
||||
'relatedEntityId' => $object->getId(),
|
||||
]);
|
||||
|
||||
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
|
||||
}
|
||||
|
||||
return $initial;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
|
||||
{
|
||||
return 'json' === $format
|
||||
&& $data instanceof AccompanyingPeriodWork
|
||||
return ('json' === $format || 'docgen' === $format)
|
||||
&& ($data instanceof AccompanyingPeriodWork || ('docgen' === $format && $data === null && ($context['docgen:expects'] ?? null) === AccompanyingPeriodWork::class))
|
||||
&& !\array_key_exists(self::IGNORE_WORK, $context);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user