From 380c55698cd4bfca3387e7272f67f5dbca7db3f5 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 16 May 2022 11:28:37 +0200 Subject: [PATCH] main: add civility to User --- CHANGELOG.md | 2 + src/Bundle/ChillMainBundle/Entity/User.php | 17 ++++++++ src/Bundle/ChillMainBundle/Form/UserType.php | 6 +++ .../Resources/views/User/index.html.twig | 5 +++ .../migrations/Version20220513151853.php | 16 +++++--- .../migrations/Version20220516085659.php | 40 +++++++++++++++++++ 6 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20220516085659.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 077cc0242..5f85ec8c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to ## Unreleased +* [main] add civility to User (entity, migration and form type) (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/577) + * [admin] refactorisation of the admin section: reorganisation of the menu, translations, form types, new entities (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/592) * [admin] add admin section for languages and countries (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/596) * [activity] activity admin: translations + remove label field for comment on admin activity type (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/587) diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index ad4888d58..80848e2cf 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -47,6 +47,11 @@ class User implements AdvancedUserInterface */ private array $attributes = []; + /** + * @ORM\ManyToOne(targetEntity=Civility::class) + */ + private ?Civility $civility = null; + /** * @ORM\ManyToOne(targetEntity=Location::class) */ @@ -184,6 +189,11 @@ class User implements AdvancedUserInterface return $this->attributes; } + public function getCivility(): ?Civility + { + return $this->civility; + } + public function getCurrentLocation(): ?Location { return $this->currentLocation; @@ -363,6 +373,13 @@ class User implements AdvancedUserInterface return $this; } + public function setCivility(?Civility $civility): User + { + $this->civility = $civility; + + return $this; + } + public function setCurrentLocation(?Location $currentLocation): User { $this->currentLocation = $currentLocation; diff --git a/src/Bundle/ChillMainBundle/Form/UserType.php b/src/Bundle/ChillMainBundle/Form/UserType.php index 6662d0bab..9ba25b37f 100644 --- a/src/Bundle/ChillMainBundle/Form/UserType.php +++ b/src/Bundle/ChillMainBundle/Form/UserType.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\UserJob; +use Chill\MainBundle\Form\Type\PickCivilityType; use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -47,6 +48,11 @@ class UserType extends AbstractType 'required' => true, ]) ->add('label', TextType::class) + ->add('civility', PickCivilityType::class, [ + 'required' => false, + 'label' => 'Civility', + 'placeholder' => 'choose civility', + ]) ->add('mainCenter', EntityType::class, [ 'label' => 'Main center', 'required' => false, diff --git a/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig index bab54d56e..1d254abb9 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig @@ -11,6 +11,11 @@
+ {% if entity.civility is not null %} + {% if entity.civility.name|length > 0 %} + {{ entity.civility.name|first }} + {% endif %} + {% endif %} {{ entity.label }} {% if entity.isEnabled %} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220513151853.php b/src/Bundle/ChillMainBundle/migrations/Version20220513151853.php index 31319ce1b..ec99ce2ba 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20220513151853.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20220513151853.php @@ -1,5 +1,12 @@ addSql('update users set attributes = \'[]\'::json where attributes IS NULL'); } - - public function down(Schema $schema): void - { - - } } diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220516085659.php b/src/Bundle/ChillMainBundle/migrations/Version20220516085659.php new file mode 100644 index 000000000..8e4d7347b --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20220516085659.php @@ -0,0 +1,40 @@ +addSql('ALTER TABLE users DROP CONSTRAINT FK_1483A5E923D6A298'); + $this->addSql('DROP INDEX IDX_1483A5E923D6A298'); + $this->addSql('ALTER TABLE users DROP civility_id'); + } + + public function getDescription(): string + { + return 'Add civility to User'; + } + + public function up(Schema $schema): void + { + $this->addSql('ALTER TABLE users ADD civility_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E923D6A298 FOREIGN KEY (civility_id) REFERENCES chill_main_civility (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_1483A5E923D6A298 ON users (civility_id)'); + } +}