Feature: add thirdParty choice in docgen activityContext

This commit is contained in:
nobohan 2023-05-22 17:15:49 +02:00
parent 977299192f
commit c6658aa2f3
3 changed files with 58 additions and 5 deletions

View File

@ -24,6 +24,9 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface; use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@ -55,6 +58,10 @@ class ActivityContext implements
private TranslatorInterface $translator; private TranslatorInterface $translator;
private ThirdPartyRender $thirdPartyRender;
private ThirdPartyRepository $thirdPartyRepository;
public function __construct( public function __construct(
DocumentCategoryRepository $documentCategoryRepository, DocumentCategoryRepository $documentCategoryRepository,
NormalizerInterface $normalizer, NormalizerInterface $normalizer,
@ -63,7 +70,9 @@ class ActivityContext implements
PersonRenderInterface $personRender, PersonRenderInterface $personRender,
PersonRepository $personRepository, PersonRepository $personRepository,
TranslatorInterface $translator, TranslatorInterface $translator,
BaseContextData $baseContextData BaseContextData $baseContextData,
ThirdPartyRender $thirdPartyRender,
ThirdPartyRepository $thirdPartyRepository
) { ) {
$this->documentCategoryRepository = $documentCategoryRepository; $this->documentCategoryRepository = $documentCategoryRepository;
$this->normalizer = $normalizer; $this->normalizer = $normalizer;
@ -73,6 +82,8 @@ class ActivityContext implements
$this->personRepository = $personRepository; $this->personRepository = $personRepository;
$this->translator = $translator; $this->translator = $translator;
$this->baseContextData = $baseContextData; $this->baseContextData = $baseContextData;
$this->thirdPartyRender = $thirdPartyRender;
$this->thirdPartyRepository = $thirdPartyRepository;
} }
public function adminFormReverseTransform(array $data): array public function adminFormReverseTransform(array $data): array
@ -89,6 +100,8 @@ class ActivityContext implements
'person1Label' => $data['person1Label'] ?? $this->translator->trans('docgen.person 1'), 'person1Label' => $data['person1Label'] ?? $this->translator->trans('docgen.person 1'),
'person2' => $data['person2'] ?? false, 'person2' => $data['person2'] ?? false,
'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'), 'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'),
'thirdParty' => $data['thirdParty'] ?? false,
'thirdPartyLabel' => $data['thirdPartyLabel'] ?? $this->translator->trans('thirdParty'),
]; ];
} }
@ -118,7 +131,15 @@ class ActivityContext implements
->add('person2Label', TextType::class, [ ->add('person2Label', TextType::class, [
'label' => 'person 2 label', 'label' => 'person 2 label',
'required' => true, 'required' => true,
]); ])
->add('thirdParty', CheckboxType::class, [
'required' => false,
'label' => 'docgen.Ask for thirdParty',
])
->add('thirdPartyLabel', TextType::class, [
'label' => 'thirdParty label',
'required' => true,
]);;
} }
/** /**
@ -143,6 +164,21 @@ class ActivityContext implements
]); ]);
} }
} }
$thirdParties = $entity->getThirdParties();
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 contextGenerationDataDenormalize(DocGeneratorTemplate $template, $entity, array $data): array public function contextGenerationDataDenormalize(DocGeneratorTemplate $template, $entity, array $data): array
@ -157,6 +193,12 @@ class ActivityContext implements
} }
} }
if (null !== ($id = ($data['thirdParty'] ?? null))) {
$denormalized['thirdParty'] = $this->thirdPartyRepository->find($id);
} else {
$denormalized['thirdParty'] = null;
}
return $denormalized; return $denormalized;
} }
@ -168,6 +210,8 @@ class ActivityContext implements
$normalized[$k] = null === $data[$k] ? null : $data[$k]->getId(); $normalized[$k] = null === $data[$k] ? null : $data[$k]->getId();
} }
$normalized['thirdParty'] = null === $data['thirdParty'] ? null : $data['thirdParty']->getId();
return $normalized; return $normalized;
} }
@ -196,6 +240,13 @@ class ActivityContext implements
} }
} }
if ($options['thirdParty']) {
$data['thirdParty'] = $this->normalizer->normalize($contextGenerationData['thirdParty'], 'docgen', [
'docgen:expects' => ThirdParty::class,
'groups' => 'docgen:read'
]);
}
return $data; return $data;
} }
@ -235,7 +286,7 @@ class ActivityContext implements
{ {
$options = $template->getOptions(); $options = $template->getOptions();
return $options['mainPerson'] || $options['person1'] || $options['person2']; return $options['mainPerson'] || $options['person1'] || $options['person2'] || $options ['thirdParty'];
} }
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void

View File

@ -927,10 +927,10 @@ docgen:
Accompanying period work: "Action d'accompagnement" Accompanying period work: "Action d'accompagnement"
Accompanying period work context: "Evaluation des actions d'accompagnement" Accompanying period work context: "Evaluation des actions d'accompagnement"
Main person: Usager principal Main person: Usager principal
person 1: Premièr usager person 1: Premier usager
person 2: Second usager person 2: Second usager
Ask for main person: Demander à l'utilisateur de préciser l'usager principal Ask for main person: Demander à l'utilisateur de préciser l'usager principal
Ask for person 1: Demander à l'utilisateur de préciser le premièr usager Ask for person 1: Demander à l'utilisateur de préciser le premier usager
Ask for person 2: Demander à l'utilisateur de préciser le second usager Ask for person 2: Demander à l'utilisateur de préciser le second usager
A basic context for accompanying period: Contexte pour les parcours A basic context for accompanying period: Contexte pour les parcours
A context for accompanying period work: Contexte pour les actions d'accompagnement A context for accompanying period work: Contexte pour les actions d'accompagnement

View File

@ -75,6 +75,7 @@ No email given: Aucune adresse courriel renseignée
The party is visible in those centers: Le tiers est visible dans ces centres The party is visible in those centers: Le tiers est visible dans ces centres
The party is not visible in any center: Le tiers n'est associé à aucun centre The party is not visible in any center: Le tiers n'est associé à aucun centre
No third parties: Aucun tiers No third parties: Aucun tiers
Any third party selected: Aucun tiers sélectionné
Thirdparty handling: Tiers traitant Thirdparty handling: Tiers traitant
Thirdparty workers: Tiers intervenants Thirdparty workers: Tiers intervenants
@ -112,6 +113,7 @@ crud:
docgen: docgen:
A context for person with a third party (for sending mail): Un contexte d'une personne avec un tiers (pour envoyer un courrier à ce tiers, par exemple) A context for person with a third party (for sending mail): Un contexte d'une personne avec un tiers (pour envoyer un courrier à ce tiers, par exemple)
Person with third party: Personne avec choix d'un tiers Person with third party: Personne avec choix d'un tiers
Ask for thirdParty: Demander à l'utilisateur de préciser un tiers
# exports # exports
export: export: