diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/index.html.twig b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/index.html.twig index 1cdad36ff..606876860 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/index.html.twig +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/index.html.twig @@ -13,7 +13,7 @@ {% for entity in entities %} {{ entity.id }} - {{ entity.name | localize_translatable_string }} + {{ entity.name|localize_translatable_string}} {{ contextManager.getContextByKey(entity.context).name|trans }} diff --git a/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php b/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php index 0583d981a..636821258 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php +++ b/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php @@ -217,7 +217,6 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte if (is_iterable($value)) { $arr = []; - foreach ($value as $k => $v) { $arr[$k] = $this->normalizer->normalize($v, $format, array_merge( diff --git a/src/Bundle/ChillDocStoreBundle/Form/AccompanyingCourseDocumentType.php b/src/Bundle/ChillDocStoreBundle/Form/AccompanyingCourseDocumentType.php index 12797da79..1b5edb966 100644 --- a/src/Bundle/ChillDocStoreBundle/Form/AccompanyingCourseDocumentType.php +++ b/src/Bundle/ChillDocStoreBundle/Form/AccompanyingCourseDocumentType.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace Chill\DocStoreBundle\Form; +use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument; use Chill\DocStoreBundle\Entity\Document; +use Chill\DocStoreBundle\Entity\DocumentCategory; use Chill\DocStoreBundle\Entity\PersonDocument; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Form\Type\ChillDateType; @@ -70,11 +72,11 @@ class AccompanyingCourseDocumentType extends AbstractType //TODO : adapt to using AccompanyingCourseDocument categories. Currently there are none... ->add('category', EntityType::class, [ 'placeholder' => 'Choose a document category', - 'class' => 'ChillDocStoreBundle:DocumentCategory', + 'class' => DocumentCategory::class, 'query_builder' => static function (EntityRepository $er) { return $er->createQueryBuilder('c') ->where('c.documentClass = :docClass') - ->setParameter('docClass', PersonDocument::class); + ->setParameter('docClass', AccompanyingCourseDocument::class); }, 'choice_label' => function ($entity = null) { return $entity ? $this->translatableStringHelper->localize($entity->getName()) : ''; diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php index 829bc3ade..644c03ac1 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php @@ -73,6 +73,7 @@ class HouseholdMember * targetEntity="\Chill\PersonBundle\Entity\Person" * ) * @Serializer\Groups({"read", "docgen:read"}) + * @Serializer\Context({"docgen:person:with-household": false}) * @Assert\Valid(groups={"household_memberships"}) * @Assert\NotNull(groups={"household_memberships"}) */ diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php index c12f6f6a7..f103105a0 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Serializer\Normalizer; use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper; use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\PersonAltName; use Chill\PersonBundle\Templating\Entity\PersonRender; @@ -57,7 +58,7 @@ class PersonDocGenNormalizer implements return $this->normalizeNullValue($format, $context); } - return [ + $data = [ 'firstname' => $person->getFirstName(), 'lastname' => $person->getLastName(), 'altNames' => implode( @@ -84,6 +85,16 @@ class PersonDocGenNormalizer implements 'memo' => $person->getMemo(), 'numberOfChildren' => (string) $person->getNumberOfChildren(), ]; + + if ($context['docgen:person:with-household'] ?? false) { + $data['household'] = $this->normalizer->normalize( + $person->getCurrentHousehold(), + $format, + array_merge($context, ['docgen:expects' => Household::class]) + ); + } + + return $data; } public function supportsNormalization($data, ?string $format = null, array $context = []) diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php index 5fa12f741..1274b46b9 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php @@ -36,8 +36,8 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte 'id' => $socialAction->getId(), 'type' => 'social_work_social_action', 'text' => $this->render->renderString($socialAction, []), - 'parent' => $this->normalizer->normalize($socialAction->getParent()), - 'desactivationDate' => $this->normalizer->normalize($socialAction->getDesactivationDate()), + 'parent' => $this->normalizer->normalize($socialAction->getParent(), $format, $context), + 'desactivationDate' => $this->normalizer->normalize($socialAction->getDesactivationDate(), $format, $context), 'title' => $socialAction->getTitle(), ]; diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php index 10431d7aa..1b30d93fc 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php @@ -67,7 +67,7 @@ class AccompanyingPeriodContext implements } public function adminFormReverseTransform(array $data): array - { + {dump($data); if (array_key_exists('category', $data)) { $data['category'] = [ 'idInsideBundle' => $data['category']->getIdInsideBundle(), @@ -80,7 +80,7 @@ class AccompanyingPeriodContext implements public function adminFormTransform(array $data): array { - $data = [ + $r = [ 'mainPerson' => $data['mainPerson'] ?? false, 'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'), 'person1' => $data['person1'] ?? false, @@ -90,11 +90,11 @@ class AccompanyingPeriodContext implements ]; if (array_key_exists('category', $data)) { - $data['category'] = array_key_exists('category', $data) ? + $r['category'] = array_key_exists('category', $data) ? $this->documentCategoryRepository->find($data['category']) : null; } - return $data; + return $r; } public function buildAdminForm(FormBuilderInterface $builder): void @@ -204,7 +204,7 @@ class AccompanyingPeriodContext implements public function getName(): string { - return 'Accompanying Period basic'; + return 'docgen.Accompanying Period basic'; } public function hasAdminForm(): bool @@ -231,7 +231,7 @@ class AccompanyingPeriodContext implements ->setCourse($entity) ->setObject($storedObject); - if (array_key_exists('category', $template->getOptions()['category'])) { + if (array_key_exists('category', $template->getOptions())) { $doc ->setCategory( $this->documentCategoryRepository->find( diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php index 09d154900..b47c46b00 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php @@ -102,7 +102,7 @@ class AccompanyingPeriodWorkContext implements public function getName(): string { - return 'Accompanying period work'; + return 'docgen.Accompanying period work'; } public function hasAdminForm(): bool diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php index 9c8d6172a..26004eee3 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php @@ -153,7 +153,7 @@ class AccompanyingPeriodWorkEvaluationContext implements public function getName(): string { - return 'Accompanying period work context'; + return 'docgen.Accompanying period work context'; } public function hasAdminForm(): bool diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php index 64c7c5c5a..04ac15c85 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php @@ -11,6 +11,9 @@ declare(strict_types=1); namespace Serializer\Normalizer; +use Chill\PersonBundle\Entity\Household\Household; +use Chill\PersonBundle\Entity\Household\HouseholdMember; +use Chill\PersonBundle\Entity\Household\Position; use Chill\PersonBundle\Entity\Person; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -77,8 +80,55 @@ final class PersonDocGenNormalizerTest extends KernelTestCase */ public function testNormalize(?Person $person, $expected, $msg) { - $normalized = $this->normalizer->normalize($person, 'docgen', ['docgen:expects' => Person::class]); + $normalized = $this->normalizer->normalize($person, 'docgen', [ + 'docgen:expects' => Person::class, + 'groups' => 'docgen:read' + ]); $this->assertEquals($expected, $normalized, $msg); } + + public function testNormalizePersonWithHousehold() + { + $household = new Household(); + $person = new Person(); + $person + ->setFirstName('Renaud') + ->setLastName('Mégane') + ; + $householdMember = new HouseholdMember(); + $householdMember + ->setPosition((new Position())->setAllowHolder(true)->setLabel(['fr' => 'position']) + ->setShareHousehold(true)) + ->setHolder(true) + ; + $person->addHouseholdParticipation($householdMember); + $household->addMember($householdMember); + + $person = new Person(); + $person + ->setFirstName('Citroen') + ->setLastName('Xsara') + ; + $householdMember = new HouseholdMember(); + $householdMember + ->setPosition((new Position())->setAllowHolder(true)->setLabel(['fr' => 'position2']) + ->setShareHousehold(false)) + ->setHolder(false) + ; + $person->addHouseholdParticipation($householdMember); + $household->addMember($householdMember); + + $actual = $this->normalizer->normalize($person, 'docgen', [ + 'groups' => 'docgen:read', + 'docgen:expects' => Person::class, + 'docgen:person:with-household' => true, + + ]); + + $this->assertCount(2, $household->getMembers()); + $this->assertIsArray($actual); + + var_dump($actual); + } } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 0ca5ce19d..a37ee0f4e 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -455,13 +455,15 @@ see social issues: Voir les problématiques sociales see persons associated: Voir les usagers concernés docgen: + Accompanying Period basic: "Parcours d'accompagnement (basique)" + Accompanying period work: "Action d'accompagnement" + Accompanying period work context: "Evaluation des actions d'accompagnement" Main person: Personne principale person 1: Première personne person 2: Seconde personne Ask for main person: Demander à l'utilisateur de préciser la personne principale Ask for person 1: Demander à l'utilisateur de préciser la première personne Ask for person 2: Demander à l'utilisateur de préciser la seconde personne - Accompanying period work: Actions 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 evaluation: Contexte pour les évaluations dans les actions d'accompagnement