Merge branch 'issue712_add_thirdparty_docgen_context' into 'master'

Issue712 add thirdparty docgen context

See merge request Chill-Projet/chill-bundles!540
This commit is contained in:
2023-05-31 21:51:40 +00:00
10 changed files with 713 additions and 23 deletions

View File

@@ -24,6 +24,9 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\PersonRepository;
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 Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@@ -55,6 +58,10 @@ class ActivityContext implements
private TranslatorInterface $translator;
private ThirdPartyRender $thirdPartyRender;
private ThirdPartyRepository $thirdPartyRepository;
public function __construct(
DocumentCategoryRepository $documentCategoryRepository,
NormalizerInterface $normalizer,
@@ -63,7 +70,9 @@ class ActivityContext implements
PersonRenderInterface $personRender,
PersonRepository $personRepository,
TranslatorInterface $translator,
BaseContextData $baseContextData
BaseContextData $baseContextData,
ThirdPartyRender $thirdPartyRender,
ThirdPartyRepository $thirdPartyRepository
) {
$this->documentCategoryRepository = $documentCategoryRepository;
$this->normalizer = $normalizer;
@@ -73,6 +82,8 @@ class ActivityContext implements
$this->personRepository = $personRepository;
$this->translator = $translator;
$this->baseContextData = $baseContextData;
$this->thirdPartyRender = $thirdPartyRender;
$this->thirdPartyRepository = $thirdPartyRepository;
}
public function adminFormReverseTransform(array $data): array
@@ -89,6 +100,8 @@ class ActivityContext implements
'person1Label' => $data['person1Label'] ?? $this->translator->trans('docgen.person 1'),
'person2' => $data['person2'] ?? false,
'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'),
'thirdParty' => $data['thirdParty'] ?? false,
'thirdPartyLabel' => $data['thirdPartyLabel'] ?? $this->translator->trans('thirdParty'),
];
}
@@ -118,6 +131,14 @@ class ActivityContext implements
->add('person2Label', TextType::class, [
'label' => 'person 2 label',
'required' => true,
])
->add('thirdParty', CheckboxType::class, [
'required' => false,
'label' => 'docgen.Ask for thirdParty',
])
->add('thirdPartyLabel', TextType::class, [
'label' => 'docgen.thirdParty label',
'required' => true,
]);
}
@@ -143,6 +164,20 @@ 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
@@ -157,6 +192,12 @@ class ActivityContext implements
}
}
if (null !== ($id = ($data['thirdParty'] ?? null))) {
$denormalized['thirdParty'] = $this->thirdPartyRepository->find($id);
} else {
$denormalized['thirdParty'] = null;
}
return $denormalized;
}
@@ -165,9 +206,11 @@ class ActivityContext implements
$normalized = [];
foreach (['mainPerson', 'person1', 'person2'] as $k) {
$normalized[$k] = null === $data[$k] ? null : $data[$k]->getId();
$normalized[$k] = ($data[$k] ?? null)?->getId();
}
$normalized['thirdParty'] = ($data['thirdParty'] ?? null)?->getId();
return $normalized;
}
@@ -196,6 +239,13 @@ class ActivityContext implements
}
}
if ($options['thirdParty']) {
$data['thirdParty'] = $this->normalizer->normalize($contextGenerationData['thirdParty'], 'docgen', [
'docgen:expects' => ThirdParty::class,
'groups' => 'docgen:read'
]);
}
return $data;
}
@@ -235,7 +285,7 @@ class ActivityContext implements
{
$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