From 76e7f5b1ee7ade94a0ea349019b304f8ea3f216d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 20 Jul 2021 23:50:31 +0200 Subject: [PATCH] allow age calculation on NULL birthdate and allow age to be null + improve translation of age --- .../translations/messages+intl-icu.fr.yaml | 6 ++++++ src/Bundle/ChillPersonBundle/Entity/Person.php | 8 ++++++-- .../Resources/views/Person/banner.html.twig | 6 +++--- .../Tests/Controller/PersonControllerUpdateTest.php | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml diff --git a/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml new file mode 100644 index 000000000..d5dedbb9f --- /dev/null +++ b/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml @@ -0,0 +1,6 @@ +years_old: >- + {age, plural, + one {# an} + many {# ans} + other {# ans} + } diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index c4b36a348..7f9805f52 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -734,9 +734,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->birthdate; } - public function getAge(): int + public function getAge(): ?int { - return date_diff($this->birthdate, date_create('now'))->format("%y"); + if ($this->birthdate instanceof \DateTimeInterface) { + return date_diff($this->birthdate, date_create('now'))->format("%y"); + } + + return null; } /** diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig index dd136014e..6fb12847d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig @@ -76,10 +76,10 @@ {{ 'Unknown date of birth'|trans }} {% else %} {{ person.birthdate|format_date('short') }} + + {{ 'years_old'|trans({ 'age': person.age }) }} + {% endif %} - - {{ person.age ~ ((person.age > 1) ? ' ans' : ' an') }} - {%- if chill_person.fields.nationality == 'visible' -%} diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php index ffdd65f35..5be74fa8f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php @@ -102,7 +102,7 @@ class PersonControllerUpdateTest extends WebTestCase public function testHiddenFielsArePresent() { $crawler = $this->client->request('GET', $this->editUrl); - +var_dump($crawler->text()); $configurables = array('placeOfBirth', 'phonenumber', 'email', 'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus'); $form = $crawler->selectButton('Enregistrer')->form(); //;