From db33fab097c36d2de80f0c498da3f858a925f3da Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 23 May 2023 18:30:18 +0200 Subject: [PATCH] Feature: add thirdParty choice in docgen accperiodworkevaluation context (WIP) --- ...ccompanyingPeriodWorkEvaluationContext.php | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php index 34b339822..1c33c9323 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php @@ -18,13 +18,18 @@ use Chill\DocStoreBundle\Entity\StoredObject; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; +use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\PersonBundle\Entity\SocialWork\Evaluation; use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository; +use Chill\ThirdPartyBundle\Entity\ThirdParty; +use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender; +use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository; 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; +use Symfony\Contracts\Translation\TranslatorInterface; /** * @implements DocGeneratorContextWithPublicFormInterface @@ -43,18 +48,30 @@ class AccompanyingPeriodWorkEvaluationContext implements private TranslatableStringHelperInterface $translatableStringHelper; + private ThirdPartyRender $thirdPartyRender; + + private ThirdPartyRepository $thirdPartyRepository; + + private TranslatorInterface $translator; + public function __construct( AccompanyingPeriodWorkContext $accompanyingPeriodWorkContext, EntityManagerInterface $em, EvaluationRepository $evaluationRepository, NormalizerInterface $normalizer, - TranslatableStringHelperInterface $translatableStringHelper + TranslatableStringHelperInterface $translatableStringHelper, + ThirdPartyRender $thirdPartyRender, + ThirdPartyRepository $thirdPartyRepository, + TranslatorInterface $translator ) { $this->accompanyingPeriodWorkContext = $accompanyingPeriodWorkContext; $this->em = $em; $this->evaluationRepository = $evaluationRepository; $this->normalizer = $normalizer; $this->translatableStringHelper = $translatableStringHelper; + $this->thirdPartyRender = $thirdPartyRender; + $this->thirdPartyRepository = $thirdPartyRepository; + $this->translator = $translator; } public function adminFormReverseTransform(array $data): array @@ -102,6 +119,39 @@ class AccompanyingPeriodWorkEvaluationContext implements public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void { $this->accompanyingPeriodWorkContext->buildPublicForm($builder, $template, $entity->getAccompanyingPeriodWork()); + + //TODO add more choices to thirdParty form + //Question: replace the form or just add more choices to form 'thirdParty'? + + $thirdParties = array_merge( + array_filter($entity->getAccompanyingPeriodWork()->getThirdParties()->toArray()), + array_filter([$entity->getAccompanyingPeriodWork()->getHandlingThierParty()]), + array_filter(array_map( + fn (Resource $r): ?ThirdParty => $r->getThirdParty(), + $entity->getAccompanyingPeriodWork()->getAccompanyingPeriod()->getResources()->filter( + static fn (Resource $r): bool => null !== $r->getThirdParty() + )->toArray()) + ) + + ); + dump($thirdParties); + + $options = $template->getOptions(); + if ($options['thirdParty'] ?? false) { + $builder->add('thirdParty', EntityType::class, [ + 'class' => ThirdParty::class, + 'choices' => $thirdParties, + 'choice_label' => fn (ThirdParty $p) => $this->thirdPartyRender->renderString($p, []), + 'multiple' => false, + 'required' => false, + 'expanded' => true, + 'label' => $options['thirdPartyLabel'], + 'placeholder' => $this->translator->trans('Any third party selected'), + ]); + } + + + } public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array @@ -116,7 +166,7 @@ class AccompanyingPeriodWorkEvaluationContext implements AbstractNormalizer::GROUPS => ['docgen:read'], ] ); - + dump($data); return $data; }