mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
docgen: add age and base context
This commit is contained in:
parent
689f612382
commit
9453fc2dd5
@ -13,6 +13,8 @@ and this project adheres to
|
||||
<!-- write down unreleased development here -->
|
||||
* AddAddress: optimize loading: wait for the user finish typing;
|
||||
* UserPicker: fix bug with deprecated role
|
||||
* docgen: add base context + tests
|
||||
* docgen: add age for person
|
||||
|
||||
## Test releases
|
||||
|
||||
|
@ -45,7 +45,7 @@ class BaseContextData
|
||||
$data['location'] = $this->normalizer->normalize(
|
||||
$user instanceof User ? $user->getCurrentLocation() : null,
|
||||
'docgen',
|
||||
['docgen:expects' => Location::class, 'groups' => ['docgen:expects']]
|
||||
['docgen:expects' => Location::class, 'groups' => ['docgen:read']]
|
||||
);
|
||||
|
||||
return $data;
|
||||
|
@ -38,6 +38,7 @@ final class BaseContextDataTest extends KernelTestCase
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertArrayHasKey('creator', $actual);
|
||||
$this->assertArrayHasKey('createdAt', $actual);
|
||||
$this->assertArrayHasKey('location', $actual);
|
||||
}
|
||||
|
||||
public function testGenerateWithUser()
|
||||
@ -52,6 +53,7 @@ final class BaseContextDataTest extends KernelTestCase
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertArrayHasKey('creator', $actual);
|
||||
$this->assertArrayHasKey('createdAt', $actual);
|
||||
$this->assertArrayHasKey('location', $actual);
|
||||
}
|
||||
|
||||
private function buildBaseContext(
|
||||
|
@ -74,7 +74,7 @@ class PersonDocGenNormalizer implements
|
||||
$data = [
|
||||
'type' => 'person',
|
||||
'isNull' => false,
|
||||
'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expect' => Civility::class])),
|
||||
'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])),
|
||||
'firstname' => $person->getFirstName(),
|
||||
'lastname' => $person->getLastName(),
|
||||
'altNames' => implode(
|
||||
@ -87,6 +87,7 @@ class PersonDocGenNormalizer implements
|
||||
)
|
||||
),
|
||||
'text' => $this->personRender->renderString($person, []),
|
||||
'age' => $person->getAge(),
|
||||
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $dateContext),
|
||||
'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $dateContext),
|
||||
'gender' => $this->translator->trans($person->getGender()),
|
||||
|
@ -15,6 +15,7 @@ use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
|
||||
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Repository\DocumentCategoryRepository;
|
||||
@ -38,6 +39,8 @@ class AccompanyingPeriodContext implements
|
||||
DocGeneratorContextWithAdminFormInterface,
|
||||
DocGeneratorContextWithPublicFormInterface
|
||||
{
|
||||
private BaseContextData $baseContextData;
|
||||
|
||||
private DocumentCategoryRepository $documentCategoryRepository;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
@ -56,7 +59,8 @@ class AccompanyingPeriodContext implements
|
||||
TranslatableStringHelperInterface $translatableStringHelper,
|
||||
EntityManagerInterface $em,
|
||||
PersonRender $personRender,
|
||||
TranslatorInterface $translator
|
||||
TranslatorInterface $translator,
|
||||
BaseContextData $baseContextData
|
||||
) {
|
||||
$this->documentCategoryRepository = $documentCategoryRepository;
|
||||
$this->normalizer = $normalizer;
|
||||
@ -64,12 +68,11 @@ class AccompanyingPeriodContext implements
|
||||
$this->em = $em;
|
||||
$this->personRender = $personRender;
|
||||
$this->translator = $translator;
|
||||
$this->baseContextData = $baseContextData;
|
||||
}
|
||||
|
||||
public function adminFormReverseTransform(array $data): array
|
||||
{
|
||||
dump($data);
|
||||
|
||||
if (array_key_exists('category', $data)) {
|
||||
$data['category'] = [
|
||||
'idInsideBundle' => $data['category']->getIdInsideBundle(),
|
||||
@ -171,6 +174,7 @@ class AccompanyingPeriodContext implements
|
||||
$options = $template->getOptions();
|
||||
|
||||
$data = [];
|
||||
$data = array_merge($data, $this->baseContextData->getData());
|
||||
$data['course'] = $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => AccompanyingPeriod::class, 'groups' => 'docgen:read']);
|
||||
|
||||
foreach (['mainPerson', 'person1', 'person2'] as $k) {
|
||||
|
@ -56,6 +56,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
||||
'placeOfBirth' => '',
|
||||
'memo' => '',
|
||||
'numberOfChildren' => '',
|
||||
'age' => '@ignored',
|
||||
];
|
||||
|
||||
private NormalizerInterface $normalizer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user