From 9765bc5663402447fa25e842527d7a162d217082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 11 Apr 2022 17:12:59 +0200 Subject: [PATCH 1/6] fix cs --- .../Repository/ActivityACLAwareRepository.php | 10 +- .../ActivityACLAwareRepositoryInterface.php | 4 - ...tActivitiesByAccompanyingPeriodContext.php | 154 ++++++++++-------- 3 files changed, 86 insertions(+), 82 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php index 31b293a40..2778945eb 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php @@ -15,7 +15,6 @@ use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Entity\ActivityPresence; use Chill\ActivityBundle\Entity\ActivityType; use Chill\ActivityBundle\Security\Authorization\ActivityVoter; -use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\LocationType; use Chill\MainBundle\Entity\Scope; @@ -84,7 +83,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte { $rsm = new ResultSetMappingBuilder($this->em); - $sql = " + $sql = ' SELECT a.id AS activity_id, date, @@ -118,7 +117,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte WHERE accompanyingperiod_id = ? ORDER BY a.date DESC, a.id DESC LIMIT ? - "; + '; $rsm ->addEntityResult(Activity::class, 'a') @@ -133,7 +132,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte ->addFieldResult('location', 'phonenumber1', 'phonenumber1') ->addFieldResult('location', 'phonenumber2', 'phonenumber2') ->addFieldResult('location', 'email', 'email') - ->addJoinedEntityResult(LocationType::class,'locationType', 'location', 'locationType' ) + ->addJoinedEntityResult(LocationType::class, 'locationType', 'location', 'locationType') ->addFieldResult('locationType', 'locationtype_id', 'id') ->addFieldResult('locationType', 'locationtype_title', 'title') ->addJoinedEntityResult(ActivityType::class, 'activityType', 'a', 'activityType') @@ -151,8 +150,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte ->addScalarResult('socialactionids', 'socialActionIds', Types::JSON) ->addScalarResult('socialissueids', 'socialIssueIds', Types::JSON) ->addScalarResult('durationtimeminute', 'durationTimeMinute', Types::INTEGER) - ->addScalarResult('traveltimeminute', 'travelTimeMinute', Types::INTEGER) - ; + ->addScalarResult('traveltimeminute', 'travelTimeMinute', Types::INTEGER); $nq = $this->em->createNativeQuery($sql, $rsm); diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepositoryInterface.php b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepositoryInterface.php index a6f8fe934..1fc6d22b1 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepositoryInterface.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepositoryInterface.php @@ -26,10 +26,6 @@ interface ActivityACLAwareRepositoryInterface * * The aim of this method is to get a long list of activities and keep performance. * - * @param AccompanyingPeriod $period - * @param string $role - * @param int|null $limit - * @param array|null $orderBy * @return array an array of array, each item representing an activity */ public function findByAccompanyingPeriodSimplified(AccompanyingPeriod $period, ?int $limit = 1000): array; diff --git a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php index 3868545d9..0a442cec7 100644 --- a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php +++ b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php @@ -1,5 +1,14 @@ userRepository = $userRepository; } + public function adminFormReverseTransform(array $data): array + { + return $this->accompanyingPeriodContext->adminFormReverseTransform($data); + } + + public function adminFormTransform(array $data): array + { + return $this->accompanyingPeriodContext->adminFormTransform($data); + } + + public function buildAdminForm(FormBuilderInterface $builder): void + { + $this->accompanyingPeriodContext->buildAdminForm($builder); + } + + public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void + { + $this->accompanyingPeriodContext->buildPublicForm($builder, $template, $entity); + } + public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array { $data = $this->accompanyingPeriodContext->getData($template, $entity, $contextGenerationData); @@ -81,6 +111,46 @@ class ListActivitiesByAccompanyingPeriodContext implements return $data; } + public function getDescription(): string + { + return 'docgen.Accompanying period with a list of activities description'; + } + + public function getEntityClass(): string + { + return AccompanyingPeriod::class; + } + + public function getFormData(DocGeneratorTemplate $template, $entity): array + { + return $this->accompanyingPeriodContext->getFormData($template, $entity); + } + + public static function getKey(): string + { + return self::class; + } + + public function getName(): string + { + return 'docgen.Accompanying period with a list of activities'; + } + + public function hasAdminForm(): bool + { + return $this->accompanyingPeriodContext->hasAdminForm(); + } + + public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool + { + return $this->accompanyingPeriodContext->hasPublicForm($template, $entity); + } + + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void + { + $this->accompanyingPeriodContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); + } + private function getActivitiesSimplified(AccompanyingPeriod $period) { $activities = @@ -91,20 +161,21 @@ class ListActivitiesByAccompanyingPeriodContext implements $activity = $row[0]; $activity['date'] = $this->normalizer->normalize($activity['date'], 'docgen', [ - AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => \DateTime::class + AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => DateTime::class, ]); if (null === $activity['location']) { - $activity['location'] = $this->normalizer->normalize(null, 'docgen', [ - AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => Location::class + $activity['location'] = $this->normalizer->normalize(null, 'docgen', [ + AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => Location::class, ]); $activity['location']['type'] = 'location'; } else { $activity['location']['isNull'] = false; $activity['location']['type'] = 'location'; + foreach (['1', '2'] as $key) { - $activity['location']['phonenumber'.$key] = $this->normalizer->normalize( - $activity['location']['phonenumber'.$key], + $activity['location']['phonenumber' . $key] = $this->normalizer->normalize( + $activity['location']['phonenumber' . $key], 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => PhoneNumber::class] ); @@ -127,7 +198,7 @@ class ListActivitiesByAccompanyingPeriodContext implements $activity['activityType']['type'] = 'activityType'; } else { $activity['activityType'] = $this->normalizer->normalize(null, 'docgen', [ - AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => ActivityType::class + AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => ActivityType::class, ]); } @@ -139,7 +210,7 @@ class ListActivitiesByAccompanyingPeriodContext implements $activity['attendee']['type'] = 'activityPresence'; } else { $activity['attendee'] = $this->normalizer->normalize(null, 'docgen', [ - AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => ActivityPresence::class + AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => ActivityPresence::class, ]); } @@ -212,65 +283,4 @@ class ListActivitiesByAccompanyingPeriodContext implements return $results; } - - public function getDescription(): string - { - return 'docgen.Accompanying period with a list of activities description'; - } - - public function getEntityClass(): string - { - return AccompanyingPeriod::class; - } - - public static function getKey(): string - { - return self::class; - } - - public function getName(): string - { - return 'docgen.Accompanying period with a list of activities'; - } - - public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void - { - $this->accompanyingPeriodContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); - } - - public function adminFormReverseTransform(array $data): array - { - return $this->accompanyingPeriodContext->adminFormReverseTransform($data); - } - - public function adminFormTransform(array $data): array - { - return $this->accompanyingPeriodContext->adminFormTransform($data); - } - - public function buildAdminForm(FormBuilderInterface $builder): void - { - $this->accompanyingPeriodContext->buildAdminForm($builder); - } - - public function hasAdminForm(): bool - { - return $this->accompanyingPeriodContext->hasAdminForm(); - } - - public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void - { - $this->accompanyingPeriodContext->buildPublicForm($builder, $template, $entity); - } - - public function getFormData(DocGeneratorTemplate $template, $entity): array - { - return $this->accompanyingPeriodContext->getFormData($template, $entity); - } - - public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool - { - return $this->accompanyingPeriodContext->hasPublicForm($template, $entity); - } - } From 7fbb3dfd07d10f03e16d513f264d208525368354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 11 Apr 2022 17:43:31 +0200 Subject: [PATCH 2/6] docgen: add more persons choices in person1, person2 and mainPerson Allow to pick amongst: * requestor (if person) * resources of course (if person) * resources of person (if person) --- .../AccompanyingPeriodContext.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php index 495989b29..dc6e9c912 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php @@ -152,8 +152,25 @@ class AccompanyingPeriodContext implements $options = $template->getOptions(); $persons = $entity->getCurrentParticipations()->map(static function (AccompanyingPeriodParticipation $p) { return $p->getPerson(); - }) - ->toArray(); + }); + + foreach ($entity->getCurrentParticipations() as $p) { + foreach ($p->getPerson()->getResources() as $r) { + if (null !== $r->getPerson() && !$persons->contains($r->getPerson())) { + $persons->add($r->getPerson()); + } + } + } + + if (null !== $entity->getRequestorPerson() && !$persons->contains($entity->getRequestorPerson())) { + $persons->add($entity->getRequestorPerson()); + } + + foreach ($entity->getResources() as $r) { + if (null !== $r->getPerson() && !$persons->contains($r->getPerson())) { + $persons->add($r->getPerson()); + } + } foreach (['mainPerson', 'person1', 'person2'] as $key) { if ($options[$key] ?? false) { From 910245f8557abaffe020936ec02a84cc38494512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 11 Apr 2022 17:45:57 +0200 Subject: [PATCH 3/6] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abaa3fdd8..dcf61d70e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to ## Unreleased +* [docgen] add more persons choices in docgen for course: amongst requestor (if person), resources of course (if person), and PersonResource (if person); +* [docgen] add a new context with a list of activities in course ## Test releases From 69b2dce7ee8b289f52c53769099bf28fdbf69712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 11 Apr 2022 18:10:10 +0200 Subject: [PATCH 4/6] docgen/budget: add comment for each budget line (resource and charge) The comments are cocatenated by lines of each type, and separated by a `|` --- CHANGELOG.md | 1 + .../Service/Summary/SummaryBudget.php | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcf61d70e..a61c63a73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to * [docgen] add more persons choices in docgen for course: amongst requestor (if person), resources of course (if person), and PersonResource (if person); * [docgen] add a new context with a list of activities in course +* [docgen] add a comment in budget lines ## Test releases diff --git a/src/Bundle/ChillBudgetBundle/Service/Summary/SummaryBudget.php b/src/Bundle/ChillBudgetBundle/Service/Summary/SummaryBudget.php index 8e46feb7b..63cb69ad5 100644 --- a/src/Bundle/ChillBudgetBundle/Service/Summary/SummaryBudget.php +++ b/src/Bundle/ChillBudgetBundle/Service/Summary/SummaryBudget.php @@ -25,13 +25,13 @@ use function count; */ class SummaryBudget implements SummaryBudgetInterface { - private const QUERY_CHARGE_BY_HOUSEHOLD = 'select SUM(amount) AS sum, type FROM chill_budget.charge WHERE (person_id IN (_ids_) OR household_id = ?) AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY type'; + private const QUERY_CHARGE_BY_HOUSEHOLD = 'select SUM(amount) AS sum, string_agg(comment, \'|\') AS comment, type FROM chill_budget.charge WHERE (person_id IN (_ids_) OR household_id = ?) AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY type'; - private const QUERY_CHARGE_BY_PERSON = 'select SUM(amount) AS sum, type FROM chill_budget.charge WHERE person_id = ? AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY type'; + private const QUERY_CHARGE_BY_PERSON = 'select SUM(amount) AS sum, string_agg(comment, \'|\') AS comment, type FROM chill_budget.charge WHERE person_id = ? AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY type'; - private const QUERY_RESOURCE_BY_HOUSEHOLD = 'select SUM(amount) AS sum, type FROM chill_budget.resource WHERE (person_id IN (_ids_) OR household_id = ?) AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY type'; + private const QUERY_RESOURCE_BY_HOUSEHOLD = 'select SUM(amount) AS sum, string_agg(comment, \'|\') AS comment, type FROM chill_budget.resource WHERE (person_id IN (_ids_) OR household_id = ?) AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY type'; - private const QUERY_RESOURCE_BY_PERSON = 'select SUM(amount) AS sum, type FROM chill_budget.resource WHERE person_id = ? AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY type'; + private const QUERY_RESOURCE_BY_PERSON = 'select SUM(amount) AS sum, string_agg(comment, \'|\') AS comment, type FROM chill_budget.resource WHERE person_id = ? AND NOW() BETWEEN startdate AND COALESCE(enddate, \'infinity\'::timestamp) GROUP BY type'; private array $chargeLabels; @@ -110,7 +110,9 @@ class SummaryBudget implements SummaryBudgetInterface $rsm = new ResultSetMapping(); $rsm ->addScalarResult('sum', 'sum') - ->addScalarResult('type', 'type'); + ->addScalarResult('type', 'type') + ->addScalarResult('comment', 'comment') + ; return $rsm; } @@ -121,7 +123,7 @@ class SummaryBudget implements SummaryBudgetInterface $labels = $this->chargeLabels; return array_combine($keys, array_map(function ($i) use ($labels) { - return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($labels[$i])]; + return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($labels[$i]), 'comment' => '']; }, $keys)); } @@ -131,7 +133,7 @@ class SummaryBudget implements SummaryBudgetInterface $labels = $this->resourcesLabels; return array_combine($keys, array_map(function ($i) use ($labels) { - return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($labels[$i])]; + return ['sum' => 0.0, 'label' => $this->translatableStringHelper->localize($labels[$i]), 'comment' => '']; }, $keys)); } @@ -158,6 +160,7 @@ class SummaryBudget implements SummaryBudgetInterface $result[$row['type']] = [ 'sum' => (float) $row['sum'], 'label' => $this->translatableStringHelper->localize($label[$row['type']]), + 'comment' => (string) $row['comment'], ]; } From 01c571ab06e610427b2bcec36c8d85c2e7737122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 11 Apr 2022 21:04:36 +0200 Subject: [PATCH 5/6] fix path to table --- .../Repository/ActivityACLAwareRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php index 2778945eb..d960a0c21 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php @@ -111,8 +111,8 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte LEFT JOIN LATERAL (SELECT jsonb_agg(user_id) userids, activity_id FROM activity_user AS au WHERE a.id = au.activity_id GROUP BY activity_id) AS users ON TRUE LEFT JOIN LATERAL (SELECT jsonb_agg(thirdparty_id) thirdpartyids, activity_id FROM activity_thirdparty AS au WHERE a.id = au.activity_id GROUP BY activity_id) AS thirdparties ON TRUE LEFT JOIN LATERAL (SELECT jsonb_agg(person_id) personids, activity_id FROM activity_person AS au WHERE a.id = au.activity_id GROUP BY activity_id) AS persons ON TRUE - LEFT JOIN LATERAL (SELECT jsonb_agg(socialaction_id) socialactionids, activity_id FROM postgres.public.chill_activity_activity_chill_person_socialaction AS au WHERE a.id = au.activity_id GROUP BY activity_id) AS actions ON TRUE - LEFT JOIN LATERAL (SELECT jsonb_agg(socialissue_id) socialissueids, activity_id FROM postgres.public.chill_activity_activity_chill_person_socialissue AS au WHERE a.id = au.activity_id GROUP BY activity_id) AS issues ON TRUE + LEFT JOIN LATERAL (SELECT jsonb_agg(socialaction_id) socialactionids, activity_id FROM chill_activity_activity_chill_person_socialaction AS au WHERE a.id = au.activity_id GROUP BY activity_id) AS actions ON TRUE + LEFT JOIN LATERAL (SELECT jsonb_agg(socialissue_id) socialissueids, activity_id FROM chill_activity_activity_chill_person_socialissue AS au WHERE a.id = au.activity_id GROUP BY activity_id) AS issues ON TRUE WHERE accompanyingperiod_id = ? ORDER BY a.date DESC, a.id DESC From ccf7c885bbde5d318a9157c399cffc7e5dc6b2e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 13 Apr 2022 09:44:21 +0200 Subject: [PATCH 6/6] fix normalization for phonenumber on person when phonenumber is null --- .../Service/Summary/SummaryBudget.php | 3 +- .../Normalizer/PhonenumberNormalizerTest.php | 54 +++++++++++++++++++ .../Normalizer/PersonDocGenNormalizer.php | 8 +-- 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Tests/Serializer/Normalizer/PhonenumberNormalizerTest.php diff --git a/src/Bundle/ChillBudgetBundle/Service/Summary/SummaryBudget.php b/src/Bundle/ChillBudgetBundle/Service/Summary/SummaryBudget.php index 63cb69ad5..243cd4749 100644 --- a/src/Bundle/ChillBudgetBundle/Service/Summary/SummaryBudget.php +++ b/src/Bundle/ChillBudgetBundle/Service/Summary/SummaryBudget.php @@ -111,8 +111,7 @@ class SummaryBudget implements SummaryBudgetInterface $rsm ->addScalarResult('sum', 'sum') ->addScalarResult('type', 'type') - ->addScalarResult('comment', 'comment') - ; + ->addScalarResult('comment', 'comment'); return $rsm; } diff --git a/src/Bundle/ChillMainBundle/Tests/Serializer/Normalizer/PhonenumberNormalizerTest.php b/src/Bundle/ChillMainBundle/Tests/Serializer/Normalizer/PhonenumberNormalizerTest.php new file mode 100644 index 000000000..1e0d4ef29 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Serializer/Normalizer/PhonenumberNormalizerTest.php @@ -0,0 +1,54 @@ +parse('+32486123465'), 'docgen', ['docgen:expects' => PhoneNumber::class], '0486 12 34 65']; + + yield [null, 'docgen', ['docgen:expects' => PhoneNumber::class], '']; + } + + /** + * @dataProvider dataProviderNormalizePhonenumber + * + * @param mixed $format + * @param mixed $context + * @param mixed $expected + */ + public function testNormalize(?Phonenumber $phonenumber, $format, $context, $expected) + { + $parameterBag = $this->prophesize(ParameterBagInterface::class); + $parameterBag->get(Argument::exact('chill_main'))->willReturn(['phone_helper' => ['default_carrier_code' => 'BE']]); + $normalizer = new PhonenumberNormalizer($parameterBag->reveal()); + + $this->assertEquals($expected, $normalizer->normalize($phonenumber, $format, $context)); + } +} diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php index 490a7e2af..89f01bf94 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php @@ -23,6 +23,7 @@ use Chill\PersonBundle\Repository\Relationships\RelationshipRepository; use Chill\PersonBundle\Templating\Entity\PersonRenderInterface; use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; +use libphonenumber\PhoneNumber; use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; @@ -71,6 +72,7 @@ class PersonDocGenNormalizer implements $dateContext = $context; $dateContext['docgen:expects'] = DateTimeInterface::class; $addressContext = array_merge($context, ['docgen:expects' => Address::class]); + $phonenumberContext = array_merge($context, ['docgen:expects' => PhoneNumber::class]); $personResourceContext = array_merge($context, [ 'docgen:expects' => Person\PersonResource::class, // we simplify the list of attributes for the embedded persons @@ -113,9 +115,9 @@ class PersonDocGenNormalizer implements 'maritalStatus' => null !== ($ms = $person->getMaritalStatus()) ? $this->translatableStringHelper->localize($ms->getName()) : '', 'maritalStatusDate' => $this->normalizer->normalize($person->getMaritalStatusDate(), $format, $dateContext), 'email' => $person->getEmail(), - 'firstPhoneNumber' => $this->normalizer->normalize($person->getPhonenumber() ?? $person->getMobilenumber(), $format, $context), - 'fixPhoneNumber' => $this->normalizer->normalize($person->getPhonenumber(), $format, $context), - 'mobilePhoneNumber' => $this->normalizer->normalize($person->getMobilenumber(), $format, $context), + 'firstPhoneNumber' => $this->normalizer->normalize($person->getPhonenumber() ?? $person->getMobilenumber(), $format, $phonenumberContext), + 'fixPhoneNumber' => $this->normalizer->normalize($person->getPhonenumber(), $format, $phonenumberContext), + 'mobilePhoneNumber' => $this->normalizer->normalize($person->getMobilenumber(), $format, $phonenumberContext), 'nationality' => null !== ($c = $person->getNationality()) ? $this->translatableStringHelper->localize($c->getName()) : '', 'placeOfBirth' => $person->getPlaceOfBirth(), 'memo' => $person->getMemo(),