From 8e30873001791effff4e49b2379f560fc45e2397 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 25 Sep 2024 16:02:40 +0200 Subject: [PATCH 01/83] Create gender admin entity and add configuration to use it entity, migration, controller, repository, templates, form added --- .../Controller/GenderController.php | 17 ++++ .../ChillMainExtension.php | 25 +++++ src/Bundle/ChillMainBundle/Entity/Gender.php | 93 +++++++++++++++++++ .../ChillMainBundle/Form/GenderType.php | 44 +++++++++ .../Repository/GenderRepository.php | 7 ++ .../Resources/views/Gender/edit.html.twig | 11 +++ .../Resources/views/Gender/index.html.twig | 53 +++++++++++ .../Resources/views/Gender/new.html.twig | 11 +++ .../migrations/Version20240925133053.php | 28 ++++++ .../Menu/AdminPersonMenuBuilder.php | 8 +- 10 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Controller/GenderController.php create mode 100644 src/Bundle/ChillMainBundle/Entity/Gender.php create mode 100644 src/Bundle/ChillMainBundle/Form/GenderType.php create mode 100644 src/Bundle/ChillMainBundle/Repository/GenderRepository.php create mode 100644 src/Bundle/ChillMainBundle/Resources/views/Gender/edit.html.twig create mode 100644 src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig create mode 100644 src/Bundle/ChillMainBundle/Resources/views/Gender/new.html.twig create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20240925133053.php diff --git a/src/Bundle/ChillMainBundle/Controller/GenderController.php b/src/Bundle/ChillMainBundle/Controller/GenderController.php new file mode 100644 index 000000000..8a949294f --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/GenderController.php @@ -0,0 +1,17 @@ +addOrderBy('e.order', 'ASC'); + + return parent::orderQuery($action, $query, $request, $paginator); + } +} diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 9d788c64e..b406f56f1 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Controller\CivilityApiController; use Chill\MainBundle\Controller\CivilityController; use Chill\MainBundle\Controller\CountryApiController; use Chill\MainBundle\Controller\CountryController; +use Chill\MainBundle\Controller\GenderController; use Chill\MainBundle\Controller\GeographicalUnitApiController; use Chill\MainBundle\Controller\LanguageController; use Chill\MainBundle\Controller\LocationController; @@ -52,6 +53,7 @@ use Chill\MainBundle\Doctrine\Type\PointType; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Entity\Country; +use Chill\MainBundle\Entity\Gender; use Chill\MainBundle\Entity\GeographicalUnitLayer; use Chill\MainBundle\Entity\Language; use Chill\MainBundle\Entity\Location; @@ -63,6 +65,7 @@ use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Form\CenterType; use Chill\MainBundle\Form\CivilityType; use Chill\MainBundle\Form\CountryType; +use Chill\MainBundle\Form\GenderType; use Chill\MainBundle\Form\LanguageType; use Chill\MainBundle\Form\LocationFormType; use Chill\MainBundle\Form\LocationTypeType; @@ -485,6 +488,28 @@ class ChillMainExtension extends Extension implements ], ], ], + [ + 'class' => Gender::class, + 'name' => 'main_gender', + 'base_path' => '/admin/main/gender', + 'base_role' => 'ROLE_ADMIN', + 'form_class' => GenderType::class, + 'controller' => GenderController::class, + 'actions' => [ + 'index' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillMain/Gender/index.html.twig', + ], + 'new' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillMain/Gender/new.html.twig', + ], + 'edit' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillMain/Gender/edit.html.twig', + ], + ], + ], [ 'class' => Language::class, 'name' => 'main_language', diff --git a/src/Bundle/ChillMainBundle/Entity/Gender.php b/src/Bundle/ChillMainBundle/Entity/Gender.php new file mode 100644 index 000000000..8bc94e473 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/Gender.php @@ -0,0 +1,93 @@ + '0.0'])] + private float $order = 0; + + public function getId(): int + { + return $this->id; + } + + public function getLabel(): array + { + return $this->label; + } + + public function setLabel(array $label): void + { + $this->label = $label; + } + + public function isActive(): bool + { + return $this->active; + } + + public function setActive(bool $active): void + { + $this->active = $active; + } + + public function isGrammatical(): bool + { + return $this->isGrammatical; + } + + public function setIsGrammatical(bool $isGrammatical): void + { + $this->isGrammatical = $isGrammatical; + } + + public function getIcon(): string + { + return $this->icon; + } + + public function setIcon(string $icon): void + { + $this->icon = $icon; + } + + public function getOrder(): float + { + return $this->order; + } + + public function setOrder(float $order): void + { + $this->order = $order; + } +} diff --git a/src/Bundle/ChillMainBundle/Form/GenderType.php b/src/Bundle/ChillMainBundle/Form/GenderType.php new file mode 100644 index 000000000..2f188ba58 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Form/GenderType.php @@ -0,0 +1,44 @@ +add('label', TranslatableStringFormType::class, [ + 'required' => true, + ]) + ->add('icon', TextType::class) + ->add('isGrammatical', ChoiceType::class, [ + 'choices' => [ + 'Grammatical' => true, + 'Not grammatical' => false, + ], + ]) + ->add('active', ChoiceType::class, [ + 'choices' => [ + 'Active' => true, + 'Inactive' => false, + ], + ]) + ->add('order', IntegerType::class); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Gender::class, + ]); + } +} diff --git a/src/Bundle/ChillMainBundle/Repository/GenderRepository.php b/src/Bundle/ChillMainBundle/Repository/GenderRepository.php new file mode 100644 index 000000000..357e301b5 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Repository/GenderRepository.php @@ -0,0 +1,7 @@ +id + {{ 'gender.label'|trans }} + {{ 'gender.icon'|trans }} + {{ 'gender.isGrammatical'|trans }} + {{ 'gender.active'|trans }} + {{ 'gender.ordering'|trans }} + + {% endblock %} + {% block table_entities_tbody %} + {% for entity in entities %} + + {{ entity.id }} + {{ entity.label|localize_translatable_string }} +{# todo: decide which icon source to use#} + + + {%- if entity.isGrammatical -%} + + {%- else -%} + + {%- endif -%} + + + {%- if entity.active -%} + + {%- else -%} + + {%- endif -%} + + {{ entity.order }} + + + + + {% endfor %} + {% endblock %} + + {% block actions_before %} +
  • + {{'Back to the admin'|trans}} +
  • + {% endblock %} + {% endembed %} +{% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Gender/new.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Gender/new.html.twig new file mode 100644 index 000000000..7c204dddd --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Gender/new.html.twig @@ -0,0 +1,11 @@ +{% extends '@ChillMain/CRUD/Admin/index.html.twig' %} + +{% block title %} + {% include('@ChillMain/CRUD/_new_title.html.twig') %} +{% endblock %} + +{% block admin_content %} + {% embed '@ChillMain/CRUD/_new_content.html.twig' %} + {% block content_form_actions_save_and_show %}{% endblock %} + {% endembed %} +{% endblock admin_content %} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20240925133053.php b/src/Bundle/ChillMainBundle/migrations/Version20240925133053.php new file mode 100644 index 000000000..4767ff3bd --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20240925133053.php @@ -0,0 +1,28 @@ +addSql('CREATE SEQUENCE chill_main_gender_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE chill_main_gender (id INT NOT NULL, label JSON NOT NULL, active BOOLEAN NOT NULL, isGrammatical BOOLEAN NOT NULL, icon VARCHAR(255) NOT NULL, ordering DOUBLE PRECISION DEFAULT \'0.0\', PRIMARY KEY(id))'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP SEQUENCE chill_main_gender_id_seq CASCADE'); + $this->addSql('DROP TABLE chill_main_gender'); + } +} diff --git a/src/Bundle/ChillPersonBundle/Menu/AdminPersonMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/AdminPersonMenuBuilder.php index ee2dad9dc..c3d369f00 100644 --- a/src/Bundle/ChillPersonBundle/Menu/AdminPersonMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/AdminPersonMenuBuilder.php @@ -45,13 +45,17 @@ class AdminPersonMenuBuilder implements LocalMenuBuilderInterface 'route' => 'chill_crud_main_civility_index', ])->setExtras(['order' => 2010]); + $menu->addChild('Gender', [ + 'route' => 'chill_crud_main_gender_index', + ])->setExtras(['order' => 2020]); + $menu->addChild('Marital status', [ 'route' => 'chill_crud_person_marital-status_index', - ])->setExtras(['order' => 2020]); + ])->setExtras(['order' => 2030]); $menu->addChild('person_admin.person_resource_kind', [ 'route' => 'chill_crud_person_resource-kind_index', - ])->setExtras(['order' => 2030]); + ])->setExtras(['order' => 2040]); } public static function getMenuIds(): array From 94875d83b31453072a0cdc396af849df0d6cc83c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 26 Sep 2024 12:20:36 +0200 Subject: [PATCH 02/83] Create genderEnum, add genderTranslation property to Gender entity and new gender property to Person entity Also migrations were created to handle the changes in the database. --- src/Bundle/ChillMainBundle/Entity/Gender.php | 14 ++--- .../ChillMainBundle/Entity/GenderEnum.php | 11 ++++ .../migrations/Version20240926093955.php | 62 +++++++++++++++++++ .../ChillPersonBundle/Entity/Person.php | 25 ++++---- .../migrations/Version20240926100337.php | 41 ++++++++++++ 5 files changed, 135 insertions(+), 18 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Entity/GenderEnum.php create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20240926093955.php create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20240926100337.php diff --git a/src/Bundle/ChillMainBundle/Entity/Gender.php b/src/Bundle/ChillMainBundle/Entity/Gender.php index 8bc94e473..a14f433c8 100644 --- a/src/Bundle/ChillMainBundle/Entity/Gender.php +++ b/src/Bundle/ChillMainBundle/Entity/Gender.php @@ -25,9 +25,9 @@ class Gender #[ORM\Column(type: \Doctrine\DBAL\Types\Types::BOOLEAN)] private bool $active = true; - #[Serializer\Groups(['read'])] - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::BOOLEAN)] - private bool $isGrammatical = true; + #[Assert\NotNull(message: 'You must choose a gender translation')] + #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, enumType: GenderEnum::class)] + private GenderEnum $genderTranslation; #[Serializer\Groups(['read'])] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)] @@ -61,14 +61,14 @@ class Gender $this->active = $active; } - public function isGrammatical(): bool + public function getGenderTranslation(): GenderEnum { - return $this->isGrammatical; + return $this->genderTranslation; } - public function setIsGrammatical(bool $isGrammatical): void + public function setGenderTranslation(GenderEnum $genderTranslation): void { - $this->isGrammatical = $isGrammatical; + $this->$genderTranslation = $genderTranslation; } public function getIcon(): string diff --git a/src/Bundle/ChillMainBundle/Entity/GenderEnum.php b/src/Bundle/ChillMainBundle/Entity/GenderEnum.php new file mode 100644 index 000000000..d171ea343 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/GenderEnum.php @@ -0,0 +1,11 @@ +addSql('CREATE SEQUENCE chill_main_gender_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE chill_main_gender (id INT NOT NULL, label JSON NOT NULL, active BOOLEAN NOT NULL, genderTranslation VARCHAR(255) NOT NULL, icon VARCHAR(255) NOT NULL, ordering DOUBLE PRECISION DEFAULT \'0.0\', PRIMARY KEY(id))'); + + // Insert the four gender records into the chill_main_gender table + $this->addSql(" + INSERT INTO chill_main_gender (id, label, active, genderTranslation, icon, ordering) + VALUES + (nextval('chill_main_gender_id_seq'), + '{\"fr\": \"homme\", \"nl\": \"man\"}', + true, + 'man', + '', + 1.0 + ), + (nextval('chill_main_gender_id_seq'), + '{\"fr\": \"femme\", \"nl\": \"vrouw\"}', + true, + 'woman', + '', + 1.1 + ), + (nextval('chill_main_gender_id_seq'), + '{\"fr\": \"neutre\", \"nl\": \"neutraal\"}', + true, + 'neutral', + '', + 1.1 + ), + (nextval('chill_main_gender_id_seq'), + '{\"fr\": \"inconnu\", \"nl\": \"ongekend\"}', + true, + 'unknown', + '', + 1.2 + ) + "); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP SEQUENCE chill_main_gender_id_seq CASCADE'); + $this->addSql('DROP TABLE chill_main_gender'); + } +} diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 0b4b54681..c8ba84797 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -21,6 +21,7 @@ use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Entity\Country; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; +use Chill\MainBundle\Entity\Gender; use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\Language; use Chill\MainBundle\Entity\User; @@ -59,19 +60,11 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; #[HouseholdMembershipSequential(groups: ['household_memberships'])] class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateInterface, \Stringable { - final public const BOTH_GENDER = 'both'; - // have days in commun final public const ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD = 2; // where there exist final public const ERROR_PERIODS_ARE_COLLAPSING = 1; // when two different periods - final public const FEMALE_GENDER = 'woman'; - - final public const MALE_GENDER = 'man'; - - final public const NO_INFORMATION = 'unknown'; - /** * Accept receiving email. */ @@ -242,11 +235,11 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI private ?string $fullnameCanonical = ''; /** - * The person's gender. + * NEW column : The person's gender. */ #[Assert\NotNull(message: 'The gender must be set')] - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 9, nullable: true)] - private ?string $gender = null; + #[ORM\ManyToOne(targetEntity: Gender::class)] + private ?Gender $gender = null; /** * Comment on gender. @@ -1657,6 +1650,16 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this; } + public function getGenderKind(): ?Gender + { + return $this->genderKind; + } + + public function setGenderKind(?Gender $genderKind): void + { + $this->genderKind = $genderKind; + } + private function getCurrentCenterHistory(): ?PersonCenterHistory { if (0 === $this->centerHistory->count()) { diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20240926100337.php b/src/Bundle/ChillPersonBundle/migrations/Version20240926100337.php new file mode 100644 index 000000000..021533efd --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20240926100337.php @@ -0,0 +1,41 @@ +addSql('ALTER TABLE chill_person_person ADD gender_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_person ADD CONSTRAINT FK_BF210A14708A0E0 FOREIGN KEY (gender_id) REFERENCES chill_main_gender (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_BF210A14708A0E0 ON chill_person_person (gender_id)'); + + // transfer gender values to point to corresponding gender entity within new column + $this->addSql(" + UPDATE chill_person_person AS p + SET gender_id = g.id + FROM chill_main_gender AS g + WHERE g.genderTranslation = p.gender AND p.gender IN ('man', 'woman', 'unknown') + OR (g.genderTranslation = 'neutral' AND p.gender = 'both') + "); + + // delete old gender column + $this->addSql('ALTER TABLE chill_person_person DROP gender'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_person ADD gender VARCHAR(9) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_person DROP gender_id'); + } +} From e831cb1656fb0c006d402c8a4cf0af669f8d531a Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 26 Sep 2024 13:24:30 +0200 Subject: [PATCH 03/83] Change PickGenderType form field to use in Person creation form --- .../ChillMainBundle/Form/GenderType.php | 11 ++-- .../Resources/views/Gender/index.html.twig | 11 +--- .../migrations/Version20240925133053.php | 28 ---------- .../ChillPersonBundle/Entity/Person.php | 14 +---- .../Form/CreationPersonType.php | 4 +- .../ChillPersonBundle/Form/PersonType.php | 4 +- .../Form/Type/GenderType.php | 44 --------------- .../Form/Type/PickGenderType.php | 53 +++++++++++++++++++ .../Resources/views/Entity/person.html.twig | 2 +- .../translations/messages+intl-icu.fr.yaml | 2 +- 10 files changed, 69 insertions(+), 104 deletions(-) delete mode 100644 src/Bundle/ChillMainBundle/migrations/Version20240925133053.php delete mode 100644 src/Bundle/ChillPersonBundle/Form/Type/GenderType.php create mode 100644 src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php diff --git a/src/Bundle/ChillMainBundle/Form/GenderType.php b/src/Bundle/ChillMainBundle/Form/GenderType.php index 2f188ba58..d6a95e803 100644 --- a/src/Bundle/ChillMainBundle/Form/GenderType.php +++ b/src/Bundle/ChillMainBundle/Form/GenderType.php @@ -3,6 +3,7 @@ namespace Chill\MainBundle\Form; use Chill\MainBundle\Entity\Gender; +use Chill\MainBundle\Entity\GenderEnum; use Chill\MainBundle\Form\Type\TranslatableStringFormType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -20,11 +21,11 @@ class GenderType extends AbstractType 'required' => true, ]) ->add('icon', TextType::class) - ->add('isGrammatical', ChoiceType::class, [ - 'choices' => [ - 'Grammatical' => true, - 'Not grammatical' => false, - ], + ->add('genderTranslation', ChoiceType::class, [ + 'choices' => GenderEnum::cases(), + 'choice_label' => fn(GenderEnum $enum) => ucfirst(strtolower($enum->name)), + 'choice_value' => fn(?GenderEnum $enum) => $enum ? $enum->value : null, + 'data_class' => null, ]) ->add('active', ChoiceType::class, [ 'choices' => [ diff --git a/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig index 82994aaa4..a46fbee56 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig @@ -6,7 +6,7 @@ id {{ 'gender.label'|trans }} {{ 'gender.icon'|trans }} - {{ 'gender.isGrammatical'|trans }} + {{ 'gender.genderTranslation'|trans }} {{ 'gender.active'|trans }} {{ 'gender.ordering'|trans }} @@ -16,15 +16,8 @@ {{ entity.id }} {{ entity.label|localize_translatable_string }} -{# todo: decide which icon source to use#} - - {%- if entity.isGrammatical -%} - - {%- else -%} - - {%- endif -%} - + {{ entity.genderTranslation.value }} {%- if entity.active -%} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20240925133053.php b/src/Bundle/ChillMainBundle/migrations/Version20240925133053.php deleted file mode 100644 index 4767ff3bd..000000000 --- a/src/Bundle/ChillMainBundle/migrations/Version20240925133053.php +++ /dev/null @@ -1,28 +0,0 @@ -addSql('CREATE SEQUENCE chill_main_gender_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE chill_main_gender (id INT NOT NULL, label JSON NOT NULL, active BOOLEAN NOT NULL, isGrammatical BOOLEAN NOT NULL, icon VARCHAR(255) NOT NULL, ordering DOUBLE PRECISION DEFAULT \'0.0\', PRIMARY KEY(id))'); - } - - public function down(Schema $schema): void - { - $this->addSql('DROP SEQUENCE chill_main_gender_id_seq CASCADE'); - $this->addSql('DROP TABLE chill_main_gender'); - } -} diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index c8ba84797..aa59948df 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -996,7 +996,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->fullnameCanonical; } - public function getGender(): ?string + public function getGender(): ?Gender { return $this->gender; } @@ -1525,7 +1525,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this; } - public function setGender(?string $gender): self + public function setGender(?Gender $gender): self { $this->gender = $gender; @@ -1650,16 +1650,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this; } - public function getGenderKind(): ?Gender - { - return $this->genderKind; - } - - public function setGenderKind(?Gender $genderKind): void - { - $this->genderKind = $genderKind; - } - private function getCurrentCenterHistory(): ?PersonCenterHistory { if (0 === $this->centerHistory->count()) { diff --git a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php index 9bfb75e31..bb40c6c35 100644 --- a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php @@ -20,8 +20,8 @@ use Chill\MainBundle\Form\Type\PickCenterType; use Chill\MainBundle\Form\Type\PickCivilityType; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; use Chill\PersonBundle\Entity\Person; -use Chill\PersonBundle\Form\Type\GenderType; use Chill\PersonBundle\Form\Type\PersonAltNameType; +use Chill\PersonBundle\Form\Type\PickGenderType; use Chill\PersonBundle\Security\Authorization\PersonVoter; use libphonenumber\PhoneNumberType; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; @@ -60,7 +60,7 @@ final class CreationPersonType extends AbstractType 'label' => 'Civility', 'placeholder' => 'choose civility', ]) - ->add('gender', GenderType::class, [ + ->add('gender', PickGenderType::class, [ 'required' => true, 'placeholder' => null, ]) ->add('birthdate', ChillDateType::class, [ diff --git a/src/Bundle/ChillPersonBundle/Form/PersonType.php b/src/Bundle/ChillPersonBundle/Form/PersonType.php index 21717a25b..0f4fbd8e4 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonType.php @@ -24,9 +24,9 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\PersonPhone; -use Chill\PersonBundle\Form\Type\GenderType; use Chill\PersonBundle\Form\Type\PersonAltNameType; use Chill\PersonBundle\Form\Type\PersonPhoneType; +use Chill\PersonBundle\Form\Type\PickGenderType; use Chill\PersonBundle\Form\Type\Select2MaritalStatusType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\CallbackTransformer; @@ -80,7 +80,7 @@ class PersonType extends AbstractType 'input' => 'datetime_immutable', 'widget' => 'single_text', ]) - ->add('gender', GenderType::class, [ + ->add('gender', PickGenderType::class, [ 'required' => true, ]) ->add('genderComment', CommentType::class, [ diff --git a/src/Bundle/ChillPersonBundle/Form/Type/GenderType.php b/src/Bundle/ChillPersonBundle/Form/Type/GenderType.php deleted file mode 100644 index 2989b3ec4..000000000 --- a/src/Bundle/ChillPersonBundle/Form/Type/GenderType.php +++ /dev/null @@ -1,44 +0,0 @@ - Person::MALE_GENDER, - Person::FEMALE_GENDER => Person::FEMALE_GENDER, - Person::BOTH_GENDER => Person::BOTH_GENDER, - ]; - - $resolver->setDefaults([ - 'choices' => $a, - 'expanded' => true, - 'multiple' => false, - 'placeholder' => null, - ]); - } - - public function getParent() - { - return ChoiceType::class; - } -} diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php new file mode 100644 index 000000000..4d4552caf --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php @@ -0,0 +1,53 @@ +setDefault('label', 'Gender') + ->setDefault( + 'choice_label', + fn (Gender $gender): string => $this->translatableStringHelper->localize($gender->getLabel()) + ) + ->setDefault( + 'query_builder', + static fn (EntityRepository $er): QueryBuilder => $er->createQueryBuilder('g') + ->where('g.active = true') + ->orderBy('g.order'), + ) + ->setDefault('placeholder', 'choose gender') + ->setDefault('class', Gender::class); + } + + public function getParent() + { + return EntityType::class; + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index 5c606e737..bd3ff0ff1 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -106,7 +106,7 @@ {%- endif -%} {%- elseif person.birthdate is not null -%} {%- if options['addAge'] -%} diff --git a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml index 9b2edf573..c65e8ccdd 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml +++ b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml @@ -2,7 +2,7 @@ Born the date: >- {gender, select, man {Né le {birthdate}} woman {Née le {birthdate}} - other {Né·e le {birthdate}} + neutral {Né·e le {birthdate}} } Requestor: >- From de914f4f17969e9725864c715310261f95213069 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 26 Sep 2024 15:45:44 +0200 Subject: [PATCH 04/83] wip: use GenderIconEnum to allow user to select bootstrap icon --- src/Bundle/ChillMainBundle/Entity/Gender.php | 8 ++++---- src/Bundle/ChillMainBundle/Entity/GenderIconEnum.php | 12 ++++++++++++ src/Bundle/ChillMainBundle/Form/GenderType.php | 9 ++++++++- .../Resources/public/module/bootstrap/index.js | 3 ++- .../Resources/views/Entity/person.html.twig | 6 +----- .../translations/messages+intl-icu.fr.yaml | 5 +++-- 6 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Entity/GenderIconEnum.php diff --git a/src/Bundle/ChillMainBundle/Entity/Gender.php b/src/Bundle/ChillMainBundle/Entity/Gender.php index a14f433c8..bd8b26b68 100644 --- a/src/Bundle/ChillMainBundle/Entity/Gender.php +++ b/src/Bundle/ChillMainBundle/Entity/Gender.php @@ -30,8 +30,8 @@ class Gender private GenderEnum $genderTranslation; #[Serializer\Groups(['read'])] - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)] - private string $icon = ''; + #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, enumType: GenderIconEnum::class)] + private GenderIconEnum $icon; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::FLOAT, name: 'ordering', nullable: true, options: ['default' => '0.0'])] private float $order = 0; @@ -71,12 +71,12 @@ class Gender $this->$genderTranslation = $genderTranslation; } - public function getIcon(): string + public function getIcon(): GenderIconEnum { return $this->icon; } - public function setIcon(string $icon): void + public function setIcon(GenderIconEnum $icon): void { $this->icon = $icon; } diff --git a/src/Bundle/ChillMainBundle/Entity/GenderIconEnum.php b/src/Bundle/ChillMainBundle/Entity/GenderIconEnum.php new file mode 100644 index 000000000..da8c2221e --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/GenderIconEnum.php @@ -0,0 +1,12 @@ +add('label', TranslatableStringFormType::class, [ 'required' => true, ]) - ->add('icon', TextType::class) + ->add('icon', ChoiceType::class, [ + 'choices' => GenderIconEnum::cases(), + 'expanded' => true, + 'multiple' => false, + 'mapped' => true, + 'label' => 'Select Gender Icon', + ]) ->add('genderTranslation', ChoiceType::class, [ 'choices' => GenderEnum::cases(), 'choice_label' => fn(GenderEnum $enum) => ucfirst(strtolower($enum->name)), diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/index.js b/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/index.js index a9d34e01d..91d66416a 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/index.js @@ -10,6 +10,7 @@ import Modal from 'bootstrap/js/dist/modal'; import Collapse from 'bootstrap/js/src/collapse'; import Carousel from 'bootstrap/js/src/carousel'; import Popover from 'bootstrap/js/src/popover'; +import 'bootstrap-icons/font/bootstrap-icons.css'; // // Carousel: ACHeaderSlider is a small slider used in banner of AccompanyingCourse Section @@ -59,4 +60,4 @@ const popoverList = triggerList.map(function (el) { return new Popover(el, { html: true, }); -}); \ No newline at end of file +}); diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index bd3ff0ff1..7c3c02abe 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -85,12 +85,8 @@ {%- endif -%} {%- if options['addInfo'] -%} - {% set gender = (person.gender == 'woman') ? 'fa-venus' : - (person.gender == 'man') ? 'fa-mars' : (person.gender == 'both') ? 'fa-neuter' : 'fa-genderless' %} - {% set genderTitle = (person.gender == 'woman') ? 'woman' : - (person.gender == 'man') ? 'man' : (person.gender == 'both') ? 'both' : 'Not given'|trans %}

    - + {%- if person.deathdate is not null -%} {%- if person.birthdate is not null -%} diff --git a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml index c65e8ccdd..eaeaf137d 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml +++ b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml @@ -3,13 +3,14 @@ Born the date: >- man {Né le {birthdate}} woman {Née le {birthdate}} neutral {Né·e le {birthdate}} + other {Né·e le {birthdate}} } Requestor: >- {gender, select, man {Demandeur} woman {Demandeuse} - other {Demandeur·euse} + neutral {Demandeur·euse} } person: @@ -17,7 +18,7 @@ person: {gender, select, man {et lui-même} woman {et elle-même} - other {et lui·elle-même} + neutral {et lui·elle-même} } from_the: depuis le From 43dd94dad6847b0293f176f6564682b9bb4f7b58 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 1 Oct 2024 11:36:00 +0200 Subject: [PATCH 05/83] Use renderInterface to render gender icons in twig --- .../Resources/views/Gender/index.html.twig | 2 +- .../Entity/ChillGenderIconRender.php | 37 +++++++++++++++++++ .../config/services/templating.yaml | 2 + .../Resources/views/Entity/person.html.twig | 3 +- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Templating/Entity/ChillGenderIconRender.php diff --git a/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig index a46fbee56..b93d8ba90 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig @@ -16,7 +16,7 @@ {{ entity.id }} {{ entity.label|localize_translatable_string }} - + {{ entity.icon|chill_entity_render_box }} {{ entity.genderTranslation.value }} {%- if entity.active -%} diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/ChillGenderIconRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/ChillGenderIconRender.php new file mode 100644 index 000000000..7494908cb --- /dev/null +++ b/src/Bundle/ChillMainBundle/Templating/Entity/ChillGenderIconRender.php @@ -0,0 +1,37 @@ + + */ +final readonly class ChillGenderIconRender implements ChillEntityRenderInterface +{ + public function renderBox($icon, array $options): string + { + return + ''; + } + + public function renderString($icon, array $options): string + { + return $icon->value; + } + + public function supports($icon, array $options): bool + { + return $icon instanceof GenderIconEnum; + } +} diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index 0baa91b69..dc21b07f5 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -49,6 +49,8 @@ services: Chill\MainBundle\Templating\Entity\NewsItemRender: ~ + Chill\MainBundle\Templating\Entity\ChillGenderIconRender: ~ + Chill\MainBundle\Templating\Entity\UserRender: ~ Chill\MainBundle\Templating\Listing\: diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index 7c3c02abe..776d87132 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -86,7 +86,8 @@ {%- if options['addInfo'] -%}

    - + {{ person.gender.icon|chill_entity_render_box }} +{# #} {%- if person.deathdate is not null -%} {%- if person.birthdate is not null -%} From d61c090cee9672561913f269ddbf7cdffa0b7fef Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 1 Oct 2024 11:38:20 +0200 Subject: [PATCH 06/83] Remove 'unknown' gender enum --- src/Bundle/ChillMainBundle/Entity/GenderEnum.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Entity/GenderEnum.php b/src/Bundle/ChillMainBundle/Entity/GenderEnum.php index d171ea343..e8af76293 100644 --- a/src/Bundle/ChillMainBundle/Entity/GenderEnum.php +++ b/src/Bundle/ChillMainBundle/Entity/GenderEnum.php @@ -7,5 +7,4 @@ enum GenderEnum : string case MALE = 'man'; case FEMALE = 'woman'; case NEUTRAL = 'neutral'; - case UNKNOWN = 'unknown'; } From e6bfcddae243e2c4c66453e3523fca61c9dad7be Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 1 Oct 2024 11:38:43 +0200 Subject: [PATCH 07/83] Use EnumType in form instead of ChoiceType for field genderTranslation --- .../ChillMainBundle/Form/GenderType.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/GenderType.php b/src/Bundle/ChillMainBundle/Form/GenderType.php index cf49d24aa..76d2a4345 100644 --- a/src/Bundle/ChillMainBundle/Form/GenderType.php +++ b/src/Bundle/ChillMainBundle/Form/GenderType.php @@ -8,6 +8,7 @@ use Chill\MainBundle\Entity\GenderIconEnum; use Chill\MainBundle\Form\Type\TranslatableStringFormType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\EnumType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; @@ -21,18 +22,25 @@ class GenderType extends AbstractType ->add('label', TranslatableStringFormType::class, [ 'required' => true, ]) +/* ->add('icon', EnumType::class, [ + 'class' => GenderIconEnum::class, + 'label_html' => true, + 'expanded' => false, + 'mapped' => true, + ])*/ ->add('icon', ChoiceType::class, [ 'choices' => GenderIconEnum::cases(), 'expanded' => true, 'multiple' => false, 'mapped' => true, - 'label' => 'Select Gender Icon', + 'choice_label' => fn(GenderIconEnum $enum) => '', + 'choice_value' => fn(?GenderIconEnum $enum) => $enum ? $enum->value : null, + 'label' => 'gender.admin.Select Gender Icon', + 'label_html' => true, ]) - ->add('genderTranslation', ChoiceType::class, [ - 'choices' => GenderEnum::cases(), - 'choice_label' => fn(GenderEnum $enum) => ucfirst(strtolower($enum->name)), - 'choice_value' => fn(?GenderEnum $enum) => $enum ? $enum->value : null, - 'data_class' => null, + ->add('genderTranslation', EnumType::class, [ + 'class' => GenderEnum::class, + 'label' => 'gender.admin.Select Gender Translation', ]) ->add('active', ChoiceType::class, [ 'choices' => [ From 236e8117d42a1ff9e8b9cff12a9f4054a20b853c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 1 Oct 2024 11:39:10 +0200 Subject: [PATCH 08/83] Fix display of icon field in gender admin form --- .../Resources/views/Gender/edit.html.twig | 70 +++++++++++++++++- .../Resources/views/Gender/new.html.twig | 74 ++++++++++++++++++- 2 files changed, 138 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/views/Gender/edit.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Gender/edit.html.twig index 4d55c480c..39f01e519 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Gender/edit.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Gender/edit.html.twig @@ -4,8 +4,72 @@ {% include('@ChillMain/CRUD/_edit_title.html.twig') %} {% endblock %} +{% form_theme form _self %} + +{% block _gender_icon_widget %} + {% for child in form %} +

    + + + +
    + {% endfor %} +{% endblock %} + {% block admin_content %} - {% embed '@ChillMain/CRUD/_edit_content.html.twig' %} - {% block content_form_actions_save_and_show %}{% endblock %} - {% endembed %} + {% set formId = crudMainFormId|default('crud_main_form') %} + + {% block crud_content_header %} +

    {{ ('crud.'~crud_name~'.title_edit')|trans }}

    + {% endblock crud_content_header %} + + {% block crud_content_form %} + {{ form_start(form, { 'attr' : { 'id': formId } }) }} + + {{ form_row(form.label) }} + {{ form_row(form.genderTranslation) }} + {{ form_row(form.icon) }} + {{ form_row(form.active) }} + {{ form_row(form.order) }} + + {{ form_end(form) }} + {% block crud_content_after_form %}{% endblock %} + + {% block crud_content_form_actions %} +
      + {% block content_form_actions_back %} +
    • + {# #} + {# {{ 'Cancel'|trans }}#} + {# #} +
    • + {% endblock %} + {% block content_form_actions_before %}{% endblock %} + {% block content_form_actions_delete %} + {% if chill_crud_action_exists(crud_name, 'delete') %} + {% if is_granted(chill_crud_config('role', crud_name, 'delete'), entity) %} +
    • + +
    • + {% endif %} + {% endif %} + {% endblock content_form_actions_delete %} + {% block content_form_actions_save_and_close %} +
    • + +
    • + {% endblock %} + {% block content_form_actions_after %}{% endblock %} +
    + {% endblock %} + + {% endblock %} {% endblock admin_content %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Gender/new.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Gender/new.html.twig index 7c204dddd..a07ebfa9d 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Gender/new.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Gender/new.html.twig @@ -4,8 +4,76 @@ {% include('@ChillMain/CRUD/_new_title.html.twig') %} {% endblock %} +{% form_theme form _self %} + +{% block _gender_icon_widget %} + {% for child in form %} +
    + + + +
    + {% endfor %} +{% endblock %} + {% block admin_content %} - {% embed '@ChillMain/CRUD/_new_content.html.twig' %} - {% block content_form_actions_save_and_show %}{% endblock %} - {% endembed %} + {% set formId = crudMainFormId|default('crud_main_form') %} + + {% block crud_content_header %} +

    {{ ('crud.' ~ crud_name ~ '.title_new')|trans({'%crud_name%' : crud_name }) }}

    + {% endblock crud_content_header %} + + {% block crud_content_form %} + {{ form_start(form, { 'attr' : { 'id': formId } }) }} + {{ form_row(form.label) }} + {{ form_row(form.genderTranslation) }} + {{ form_row(form.icon) }} + {{ form_row(form.active) }} + {{ form_row(form.order) }} + {{ form_end(form) }} + + {% block crud_content_after_form %}{% endblock %} + + {% block crud_content_form_actions %} +
      + {% block content_form_actions_back %} +
    • + + {{ 'Cancel'|trans }} + +
    • + {% endblock %} + {% block content_form_actions_save_and_close %} +
    • + +
    • + {% endblock %} + {% block content_form_actions_save_and_show %} +
    • + +
    • + {% endblock %} + {% block content_form_actions_save_and_new %} +
    • + +
    • + {% endblock %} +
    + {% endblock %} + + {{ form_end(form) }} + {% endblock %} + {% endblock admin_content %} From 406eba80d2d0f57c64fc27109cf3095a1d5cf477 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 1 Oct 2024 11:41:19 +0200 Subject: [PATCH 09/83] Create gender API and adjust serialization of gender property --- .../Controller/GenderApiController.php | 15 +++++++++++++++ .../DependencyInjection/ChillMainExtension.php | 16 ++++++++++++++++ src/Bundle/ChillMainBundle/Entity/Gender.php | 2 +- .../Resources/public/vuejs/_api/OnTheFly.js | 7 +++++++ .../Normalizer/PersonJsonNormalizer.php | 7 +++++-- 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Controller/GenderApiController.php diff --git a/src/Bundle/ChillMainBundle/Controller/GenderApiController.php b/src/Bundle/ChillMainBundle/Controller/GenderApiController.php new file mode 100644 index 000000000..567756ba7 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/GenderApiController.php @@ -0,0 +1,15 @@ +addOrderBy('e.order', 'ASC'); + } +} \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index b406f56f1..ca293cdd3 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Controller\CivilityApiController; use Chill\MainBundle\Controller\CivilityController; use Chill\MainBundle\Controller\CountryApiController; use Chill\MainBundle\Controller\CountryController; +use Chill\MainBundle\Controller\GenderApiController; use Chill\MainBundle\Controller\GenderController; use Chill\MainBundle\Controller\GeographicalUnitApiController; use Chill\MainBundle\Controller\LanguageController; @@ -813,6 +814,21 @@ class ChillMainExtension extends Extension implements ], ], ], + [ + 'class' => Gender::class, + 'name' => 'gender', + 'base_path' => '/api/1.0/main/gender', + 'base_role' => 'ROLE_USER', + 'controller' => GenderApiController::class, + 'actions' => [ + '_index' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true, + ], + ], + ], + ], [ 'class' => GeographicalUnitLayer::class, 'controller' => GeographicalUnitApiController::class, diff --git a/src/Bundle/ChillMainBundle/Entity/Gender.php b/src/Bundle/ChillMainBundle/Entity/Gender.php index bd8b26b68..2c4667e46 100644 --- a/src/Bundle/ChillMainBundle/Entity/Gender.php +++ b/src/Bundle/ChillMainBundle/Entity/Gender.php @@ -6,7 +6,7 @@ use Chill\MainBundle\Repository\GenderRepository; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; - +#[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['chill_main_gender' => Gender::class])] #[ORM\Entity(repositoryClass: GenderRepository::class)] #[ORM\Table(name: 'chill_main_gender')] class Gender diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js index c9c77991f..3c58b67e9 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js @@ -24,6 +24,12 @@ const getCivilities = () => throw Error('Error with request resource response'); }); +const getGenders = () => + fetch('/api/1.0/main/gender.json').then(response => { + if (response.ok) { return response.json(); } + throw Error('Error with request resource response'); + }); + const getCentersForPersonCreation = () => makeFetch('GET', '/api/1.0/person/creation/authorized-centers', null); /* @@ -67,6 +73,7 @@ export { getPerson, getPersonAltNames, getCivilities, + getGenders, postPerson, patchPerson }; diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index d39a69d73..88c38cfbb 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Serializer\Normalizer; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Civility; +use Chill\MainBundle\Entity\Gender; use Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension; @@ -112,7 +113,9 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar break; case 'gender': - $person->setGender($data[$item]); + $gender = $this->denormalizer->denormalize($data[$item], Gender::class, $format, []); + + $person->setGender($gender); break; @@ -199,7 +202,7 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar 'phonenumber' => $this->normalizer->normalize($person->getPhonenumber(), $format, $context), 'mobilenumber' => $this->normalizer->normalize($person->getMobilenumber(), $format, $context), 'email' => $person->getEmail(), - 'gender' => $person->getGender(), + 'gender' => $this->normalizer->normalize($person->getGender(), $format, $context), 'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context), ]; From 726cdb385fddd9a3f33353859f4ec8a9d1d4e320 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 1 Oct 2024 12:15:31 +0200 Subject: [PATCH 10/83] Implement gender icon renderbox for vue components --- .../vuejs/_components/Entity/GenderIconRenderBox.vue | 11 +++++++++++ .../vuejs/_components/Entity/PersonRenderBox.vue | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Entity/GenderIconRenderBox.vue diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Entity/GenderIconRenderBox.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Entity/GenderIconRenderBox.vue new file mode 100644 index 000000000..2aeb123c7 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Entity/GenderIconRenderBox.vue @@ -0,0 +1,11 @@ + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue index 100dc9caf..732efd689 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue @@ -37,8 +37,8 @@

    - - + + @@ -180,6 +180,7 @@ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue index 100dc9caf..732efd689 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue @@ -37,8 +37,8 @@

    - - + + @@ -180,6 +180,7 @@