docgen: add age and base context

This commit is contained in:
Julien Fastré 2021-12-15 23:42:37 +01:00
parent 689f612382
commit 9453fc2dd5
6 changed files with 15 additions and 5 deletions

View File

@ -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

View File

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

View File

@ -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(

View File

@ -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()),

View File

@ -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) {

View File

@ -56,6 +56,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
'placeOfBirth' => '',
'memo' => '',
'numberOfChildren' => '',
'age' => '@ignored',
];
private NormalizerInterface $normalizer;