From 29134f0f11431f85f8684be2c9f0c029a5617d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 3 Dec 2021 20:24:31 +0100 Subject: [PATCH] continue context for evaluations --- .../AccompanyingPeriodWorkEvaluation.php | 32 +++++++++++------ .../Entity/SocialWork/Evaluation.php | 14 ++++---- ...ccompanyingPeriodWorkEvaluationContext.php | 34 +++++++++++++++++-- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php index cdcad98bd..9fcf492f6 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php @@ -44,7 +44,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU /** * @ORM\Column(type="text", nullable=false, options={"default": ""}) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"write"}) * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ @@ -52,7 +52,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU /** * @ORM\Column(type="date_immutable", nullable=true, options={"default": null}) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?DateTimeImmutable $createdAt = null; @@ -60,7 +60,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU * @ORM\ManyToOne( * targetEntity=User::class * ) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?User $createdBy = null; @@ -76,7 +76,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU /** * @ORM\Column(type="date_immutable", nullable=true, options={"default": null}) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"write"}) * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ @@ -86,7 +86,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU * @ORM\ManyToOne( * targetEntity=Evaluation::class * ) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ private ?Evaluation $evaluation = null; @@ -95,7 +95,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?int $id = null; @@ -116,14 +116,14 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU /** * @ORM\Column(type="date_immutable", nullable=true, options={"default": null}) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ private ?DateTimeImmutable $maxDate = null; /** * @ORM\Column(type="date_immutable", nullable=true, options={"default": null}) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"write"}) * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ @@ -131,7 +131,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU /** * @ORM\Column(type="date_immutable", nullable=true, options={"default": null}) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?DateTimeImmutable $updatedAt = null; @@ -139,7 +139,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU * @ORM\ManyToOne( * targetEntity=User::class * ) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?User $updatedBy = null; @@ -244,6 +244,18 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU return $this->warningInterval; } + /** + * @Serializer\Groups({"docgen:read"}) + */ + public function getWarningDate(): ?DateTimeImmutable + { + if (null === $this->getWarningDate() || null === $this->getWarningInterval()) { + return null; + } + + return $this->getWarningDate()->sub($this->getWarningInterval()); + } + public function removeDocument(AccompanyingPeriodWorkEvaluationDocument $document): self { $this->documents->removeElement($document); diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php index 6b1d81700..fd846fbe9 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php @@ -28,21 +28,21 @@ class Evaluation * @ORM\Column(type="dateinterval", nullable=true, options={"default": null}) * @Serializer\Groups({"read"}) */ - private $delay; + private ?\DateInterval $delay = null; /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ - private $id; + private ?int $id = null; /** * @ORM\Column(type="dateinterval", nullable=true, options={"default": null}) * @Serializer\Groups({"read"}) */ - private $notificationDelay; + private ?\DateInterval $notificationDelay = null; /** * @ORM\ManyToOne( @@ -50,13 +50,13 @@ class Evaluation * inversedBy="evaluations" * ) */ - private $socialAction; + private ?SocialAction $socialAction = null; /** * @ORM\Column(type="json") - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ - private $title = []; + private array $title = []; public function getDelay(): ?DateInterval { diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php index 1f17ce48a..39dfcd493 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php @@ -23,6 +23,8 @@ use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; class AccompanyingPeriodWorkEvaluationContext implements DocGeneratorContextWithAdminFormInterface, @@ -34,17 +36,21 @@ class AccompanyingPeriodWorkEvaluationContext implements private EvaluationRepository $evaluationRepository; + private NormalizerInterface $normalizer; + private TranslatableStringHelperInterface $translatableStringHelper; public function __construct( AccompanyingPeriodWorkContext $accompanyingPeriodWorkContext, EntityManagerInterface $em, EvaluationRepository $evaluationRepository, + NormalizerInterface $normalizer, TranslatableStringHelperInterface $translatableStringHelper ) { $this->accompanyingPeriodWorkContext = $accompanyingPeriodWorkContext; $this->em = $em; $this->evaluationRepository = $evaluationRepository; + $this->normalizer = $normalizer; $this->translatableStringHelper = $translatableStringHelper; } @@ -92,14 +98,32 @@ class AccompanyingPeriodWorkEvaluationContext implements ]); } + /** + * @param AccompanyingPeriodWorkEvaluation $entity + * @return void + */ public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void { - // TODO: Implement buildPublicForm() method. + $this->accompanyingPeriodWorkContext->buildPublicForm($builder, $template, $entity->getAccompanyingPeriodWork()); } + /** + * @param AccompanyingPeriodWorkEvaluation $entity + */ public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array { - // TODO: Implement getData() method. + $data = $this->accompanyingPeriodWorkContext + ->getData($template, $entity->getAccompanyingPeriodWork(), $contextGenerationData); + $data['evaluation'] = $this->normalizer->normalize( + $entity, + 'docgen', + [ + 'docgen:expect' => AccompanyingPeriodWorkEvaluation::class, + AbstractNormalizer::GROUPS => ['docgen:read'], + ] + ); + + return $data; } public function getDescription(): string @@ -127,9 +151,13 @@ class AccompanyingPeriodWorkEvaluationContext implements return true; } + /** + * @param AccompanyingPeriodWorkEvaluation $entity + */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool { - // TODO: Implement hasPublicForm() method. + return $this->accompanyingPeriodWorkContext + ->hasPublicForm($template, $entity->getAccompanyingPeriodWork()); } public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void