From fa05a6856abda486e96d773452317f1d7b699985 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 8 Nov 2021 11:41:45 +0100 Subject: [PATCH] person: add civility: entity, migration, form, twig, config --- .../DependencyInjection/Configuration.php | 1 + .../ChillPersonBundle/Entity/Person.php | 32 ++++++++++++++++++ .../ChillPersonBundle/Form/PersonType.php | 28 +++++++++++++++- .../config/config_test_with_hidden_fields.yml | 3 +- .../Resources/views/Person/edit.html.twig | 3 ++ .../Resources/views/Person/view.html.twig | 9 +++++ .../config/services/form.yaml | 5 +-- .../migrations/Version20211108100849.php | 33 +++++++++++++++++++ .../translations/messages.fr.yml | 2 ++ 9 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20211108100849.php diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php index 4218174eb..2c53af0fe 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php @@ -77,6 +77,7 @@ class Configuration implements ConfigurationInterface ->append($this->addFieldNode('nationality')) ->append($this->addFieldNode('country_of_birth')) ->append($this->addFieldNode('marital_status')) + ->append($this->addFieldNode('civility')) ->append($this->addFieldNode('spoken_languages')) ->append($this->addFieldNode('address')) ->append($this->addFieldNode('accompanying_period')) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 9aaad8c04..0ae5d2a79 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -34,6 +34,7 @@ use Chill\PersonBundle\Entity\MaritalStatus; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\Address; +use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\PersonBundle\Entity\Person\PersonCurrentAddress; use DateTime; @@ -212,6 +213,15 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ private $maritalStatus; + /** + * The marital status of the person + * @var Civility + * + * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Civility") + * @ORM\JoinColumn(nullable=true) + */ + private $civility; + /** * The date of the last marital status change of the person * @var \DateTime @@ -962,6 +972,28 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->maritalStatus; } + /** + * Set civility + * + * @param Civility $civility + * @return Person + */ + public function setCivility(Civility $civility = null) + { + $this->civility = $civility; + return $this; + } + + /** + * Get civility + * + * @return Civility + */ + public function getCivility() + { + return $this->civility; + } + /** * Set contactInfo * diff --git a/src/Bundle/ChillPersonBundle/Form/PersonType.php b/src/Bundle/ChillPersonBundle/Form/PersonType.php index abe4750f2..521d9a9d9 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonType.php @@ -22,6 +22,7 @@ namespace Chill\PersonBundle\Form; use Chill\CustomFieldsBundle\Form\Type\CustomFieldType; +use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Form\Type\ChillCollectionType; use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\Select2CountryType; @@ -35,6 +36,10 @@ use Chill\PersonBundle\Form\Type\Select2MaritalStatusType; use Symfony\Component\Form\AbstractType; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\CommentType; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\EntityRepository; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\TelType; @@ -63,16 +68,20 @@ class PersonType extends AbstractType */ protected $configAltNamesHelper; + protected TranslatableStringHelper $translatableStringHelper; + /** * * @param string[] $personFieldsConfiguration configuration of visibility of some fields */ public function __construct( array $personFieldsConfiguration, - ConfigPersonAltNamesHelper $configAltNamesHelper + ConfigPersonAltNamesHelper $configAltNamesHelper, + TranslatableStringHelper $translatableStringHelper ) { $this->config = $personFieldsConfiguration; $this->configAltNamesHelper = $configAltNamesHelper; + $this->translatableStringHelper = $translatableStringHelper; } /** @@ -190,6 +199,23 @@ class PersonType extends AbstractType )); } + if ($this->config['civility'] === 'visible'){ + $builder + ->add('civility', EntityType::class, [ + 'label' => 'Civility', + 'class' => Civility::class, + 'choice_label' => function (Civility $civility): string { + return $this->translatableStringHelper->localize($civility->getName()); + }, + 'query_builder' => function (EntityRepository $er): QueryBuilder { + return $er->createQueryBuilder('c') + ->where('c.active = true'); + }, + 'placeholder' => 'choose civility', + 'required' => false + ]); + } + if ($this->config['marital_status'] === 'visible'){ $builder ->add('maritalStatus', Select2MaritalStatusType::class, array( diff --git a/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml b/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml index e11599661..0b12be8d0 100644 --- a/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml +++ b/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml @@ -15,4 +15,5 @@ chill_person: phonenumber: hidden country_of_birth: hidden marital_status: hidden - spoken_languages: hidden \ No newline at end of file + spoken_languages: hidden + civility: hidden \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index 80c1e76f9..d394a75a8 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -37,6 +37,9 @@

{{ 'General information'|trans }}

+ {%- if form.civility is defined -%} + {{ form_row(form.civility, {'label' : 'Civility'}) }} + {% endif %} {{ form_row(form.firstName, {'label' : 'First name'}) }} {{ form_row(form.lastName, {'label' : 'Last name'}) }} {% if form.altNames is defined %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig index a67723f27..adc6a49ce 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig @@ -51,6 +51,15 @@ This view should receive those arguments:

{{ 'General information'|trans }}

+ {% if person.civility is not null %} +
{{ 'Civility'|trans }} :
+
+ {% if person.civility.name|length > 0 %} + {{ person.civility.name|first }} + {% endif %} +
+ {% endif %} +
{{ 'First name'|trans }} :
{{ person.firstName }}
diff --git a/src/Bundle/ChillPersonBundle/config/services/form.yaml b/src/Bundle/ChillPersonBundle/config/services/form.yaml index dacfa41de..2390005cf 100644 --- a/src/Bundle/ChillPersonBundle/config/services/form.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/form.yaml @@ -7,8 +7,9 @@ services: Chill\PersonBundle\Form\PersonType: arguments: - - '%chill_person.person_fields%' - - '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper' + $personFieldsConfiguration: '%chill_person.person_fields%' + $configAltNamesHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper' + $translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper' tags: - { name: form.type, alias: '@chill.person.form.person_creation' } diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20211108100849.php b/src/Bundle/ChillPersonBundle/migrations/Version20211108100849.php new file mode 100644 index 000000000..49395dfae --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20211108100849.php @@ -0,0 +1,33 @@ +addSql('ALTER TABLE chill_person_person ADD civility_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_person ADD CONSTRAINT FK_BF210A1423D6A298 FOREIGN KEY (civility_id) REFERENCES chill_main_civility (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_BF210A1423D6A298 ON chill_person_person (civility_id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_person DROP CONSTRAINT FK_BF210A1423D6A298'); + $this->addSql('DROP INDEX IDX_BF210A1423D6A298'); + $this->addSql('ALTER TABLE chill_person_person DROP civility_id'); + } +} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 2a82d8c09..af3ca6f05 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -80,6 +80,8 @@ Married: Marié(e) 'Contact information': 'Informations de contact' 'Administrative information': Administratif File number: Dossier n° +Civility: Civilité +choose civility: -- # dédoublonnage Old person: Doublon