Feature: add thirdParty choice in docgen accperiodworkevaluation context (WIP)

This commit is contained in:
nobohan 2023-05-23 18:30:18 +02:00
parent 91a19b9e99
commit db33fab097

View File

@ -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<AccompanyingPeriodWorkEvaluation>
@ -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;
}