mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Feature: add thirdParty choice in docgen person context
This commit is contained in:
parent
db33fab097
commit
d0867f9aa3
@ -137,9 +137,9 @@ class ActivityContext implements
|
|||||||
'label' => 'docgen.Ask for thirdParty',
|
'label' => 'docgen.Ask for thirdParty',
|
||||||
])
|
])
|
||||||
->add('thirdPartyLabel', TextType::class, [
|
->add('thirdPartyLabel', TextType::class, [
|
||||||
'label' => 'thirdParty label',
|
'label' => 'docgen.thirdParty label',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
]);;
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,7 +159,7 @@ class AccompanyingPeriodContext implements
|
|||||||
'label' => 'docgen.Ask for thirdParty',
|
'label' => 'docgen.Ask for thirdParty',
|
||||||
])
|
])
|
||||||
->add('thirdPartyLabel', TextType::class, [
|
->add('thirdPartyLabel', TextType::class, [
|
||||||
'label' => 'thirdParty label',
|
'label' => 'docgen.thirdParty label',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
])
|
])
|
||||||
->add('category', EntityType::class, [
|
->add('category', EntityType::class, [
|
||||||
|
@ -26,14 +26,21 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Chill\PersonBundle\Entity\Person\PersonResource;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
|
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
|
||||||
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
|
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
|
||||||
|
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
@ -67,6 +74,12 @@ final class PersonContext implements PersonContextInterface
|
|||||||
|
|
||||||
private TranslatorInterface $translator;
|
private TranslatorInterface $translator;
|
||||||
|
|
||||||
|
private ThirdPartyRender $thirdPartyRender;
|
||||||
|
|
||||||
|
private ThirdPartyRepository $thirdPartyRepository;
|
||||||
|
|
||||||
|
private ResidentialAddressRepository $residentialAddressRepository;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AuthorizationHelperInterface $authorizationHelper,
|
AuthorizationHelperInterface $authorizationHelper,
|
||||||
BaseContextData $baseContextData,
|
BaseContextData $baseContextData,
|
||||||
@ -78,7 +91,10 @@ final class PersonContext implements PersonContextInterface
|
|||||||
ScopeRepositoryInterface $scopeRepository,
|
ScopeRepositoryInterface $scopeRepository,
|
||||||
Security $security,
|
Security $security,
|
||||||
TranslatorInterface $translator,
|
TranslatorInterface $translator,
|
||||||
TranslatableStringHelperInterface $translatableStringHelper
|
TranslatableStringHelperInterface $translatableStringHelper,
|
||||||
|
ThirdPartyRender $thirdPartyRender,
|
||||||
|
ThirdPartyRepository $thirdPartyRepository,
|
||||||
|
ResidentialAddressRepository $residentialAddressRepository
|
||||||
) {
|
) {
|
||||||
$this->authorizationHelper = $authorizationHelper;
|
$this->authorizationHelper = $authorizationHelper;
|
||||||
$this->centerResolverManager = $centerResolverManager;
|
$this->centerResolverManager = $centerResolverManager;
|
||||||
@ -91,6 +107,9 @@ final class PersonContext implements PersonContextInterface
|
|||||||
$this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes'];
|
$this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes'];
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->translatableStringHelper = $translatableStringHelper;
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
|
$this->thirdPartyRender = $thirdPartyRender;
|
||||||
|
$this->thirdPartyRepository = $thirdPartyRepository;
|
||||||
|
$this->residentialAddressRepository = $residentialAddressRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function adminFormReverseTransform(array $data): array
|
public function adminFormReverseTransform(array $data): array
|
||||||
@ -110,6 +129,8 @@ final class PersonContext implements PersonContextInterface
|
|||||||
$r = [
|
$r = [
|
||||||
'mainPerson' => $data['mainPerson'] ?? false,
|
'mainPerson' => $data['mainPerson'] ?? false,
|
||||||
'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'),
|
'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'),
|
||||||
|
'thirdParty' => $data['thirdParty'] ?? false,
|
||||||
|
'thirdPartyLabel' => $data['thirdPartyLabel'] ?? $this->translator->trans('thirdParty'),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (array_key_exists('category', $data)) {
|
if (array_key_exists('category', $data)) {
|
||||||
@ -131,6 +152,14 @@ final class PersonContext implements PersonContextInterface
|
|||||||
->setParameter('docClass', PersonDocument::class),
|
->setParameter('docClass', PersonDocument::class),
|
||||||
'choice_label' => fn ($entity = null) => $entity ? $this->translatableStringHelper->localize($entity->getName()) : '',
|
'choice_label' => fn ($entity = null) => $entity ? $this->translatableStringHelper->localize($entity->getName()) : '',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
])
|
||||||
|
->add('thirdParty', CheckboxType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'docgen.Ask for thirdParty',
|
||||||
|
])
|
||||||
|
->add('thirdPartyLabel', TextType::class, [
|
||||||
|
'label' => 'docgen.thirdParty label',
|
||||||
|
'required' => true,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,12 +168,43 @@ final class PersonContext implements PersonContextInterface
|
|||||||
*/
|
*/
|
||||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
||||||
{
|
{
|
||||||
|
$options = $template->getOptions();
|
||||||
|
|
||||||
$builder->add('title', TextType::class, [
|
$builder->add('title', TextType::class, [
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'label' => 'docgen.Document title',
|
'label' => 'docgen.Document title',
|
||||||
'data' => $this->translatableStringHelper->localize($template->getName()),
|
'data' => $this->translatableStringHelper->localize($template->getName()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$thirdParties = array_merge(
|
||||||
|
array_filter(array_map(
|
||||||
|
fn (ResidentialAddress $r): ?ThirdParty => $r->getHostThirdParty(),
|
||||||
|
$this
|
||||||
|
->residentialAddressRepository
|
||||||
|
->findCurrentResidentialAddressByPerson($entity)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array_filter(array_map(
|
||||||
|
fn (PersonResource $r): ?ThirdParty => $r->getThirdParty(),
|
||||||
|
$entity->getResources()->filter(
|
||||||
|
static fn (PersonResource $r): bool => null !== $r->getThirdParty()
|
||||||
|
)->toArray())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
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'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->isScopeNecessary($entity)) {
|
if ($this->isScopeNecessary($entity)) {
|
||||||
$builder->add('scope', ScopePickerType::class, [
|
$builder->add('scope', ScopePickerType::class, [
|
||||||
'center' => $this->centerResolverManager->resolveCenters($entity),
|
'center' => $this->centerResolverManager->resolveCenters($entity),
|
||||||
@ -170,6 +230,13 @@ final class PersonContext implements PersonContextInterface
|
|||||||
'docgen:person:with-budget' => true,
|
'docgen:person:with-budget' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($template->getOptions()['thirdParty']) {
|
||||||
|
$data['thirdParty'] = $this->normalizer->normalize($contextGenerationData['thirdParty'], 'docgen', [
|
||||||
|
'docgen:expects' => ThirdParty::class,
|
||||||
|
'groups' => 'docgen:read'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,6 +290,7 @@ final class PersonContext implements PersonContextInterface
|
|||||||
return [
|
return [
|
||||||
'title' => $data['title'] ?? '',
|
'title' => $data['title'] ?? '',
|
||||||
'scope_id' => $scope instanceof Scope ? $scope->getId() : null,
|
'scope_id' => $scope instanceof Scope ? $scope->getId() : null,
|
||||||
|
'thirdParty' => null === $data['thirdParty'] ? null : $data['thirdParty']->getId(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,6 +310,7 @@ final class PersonContext implements PersonContextInterface
|
|||||||
return [
|
return [
|
||||||
'title' => $data['title'] ?? '',
|
'title' => $data['title'] ?? '',
|
||||||
'scope' => $scope,
|
'scope' => $scope,
|
||||||
|
'thirdParty' => null !== ($id = ($data['thirdParty'] ?? null)) ? $this->thirdPartyRepository->find($id) : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +114,7 @@ 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
|
Ask for thirdParty: Demander à l'utilisateur de préciser un tiers
|
||||||
|
thirdParty label: Libellé du tiers
|
||||||
|
|
||||||
# exports
|
# exports
|
||||||
export:
|
export:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user