From 71f7a6d11b306295ba802177f15ca0f27fe49e7a Mon Sep 17 00:00:00 2001 From: Gwildor Sok Date: Sun, 19 May 2024 14:15:11 +0200 Subject: [PATCH] [145] Make min and max age of signup configurable --- config/instances/ds.yaml | 3 +++ config/instances/rood.yaml | 3 +++ src/Controller/MemberController.php | 2 ++ src/DataFixtures/MemberFixtures.php | 2 ++ src/Form/MembershipApplicationType.php | 31 +++++++++++++++++++++++--- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/config/instances/ds.yaml b/config/instances/ds.yaml index 246f642..6dc77c5 100644 --- a/config/instances/ds.yaml +++ b/config/instances/ds.yaml @@ -4,3 +4,6 @@ contribution: description: Studenten en werklozen - amount: null description: "Werkenden: 0,5% van het netto inkomen (minimaal €15 per kwartaal)" +signup: + min_age: 16 + max_age: null diff --git a/config/instances/rood.yaml b/config/instances/rood.yaml index 493492c..07e3422 100644 --- a/config/instances/rood.yaml +++ b/config/instances/rood.yaml @@ -8,3 +8,6 @@ contribution: description: €3500 bruto en daarboven - amount: null description: ik betaal een hogere contributie, namelijk: +signup: + min_age: 14 + max_age: 27 diff --git a/src/Controller/MemberController.php b/src/Controller/MemberController.php index 4ebeeaa..0e7c244 100644 --- a/src/Controller/MemberController.php +++ b/src/Controller/MemberController.php @@ -94,6 +94,8 @@ public function apply(Request $request): Response { $membershipApplication->setRegistrationTime(new \DateTime()); $membershipApplication->setContributionPeriod(Member::PERIOD_QUARTERLY); $form = $this->createForm(MembershipApplicationType::class, $membershipApplication, [ + 'min_age' => $org_config['signup']['min_age'], + 'max_age' => $org_config['signup']['max_age'], 'use_middle_name' => $this->getParameter('app.useMiddleName'), 'privacy_policy_url' => $this->getParameter('app.privacyPolicyUrl'), 'organization_name' => $this->getParameter('app.organizationName'), diff --git a/src/DataFixtures/MemberFixtures.php b/src/DataFixtures/MemberFixtures.php index c513fc9..33a2517 100644 --- a/src/DataFixtures/MemberFixtures.php +++ b/src/DataFixtures/MemberFixtures.php @@ -29,6 +29,7 @@ public function load(ObjectManager $manager) $divisionNooderhaaks = new Division(); $divisionNooderhaaks->setName("Noorderhaaks"); $divisionNooderhaaks->setPostCode("1234AB"); + $divisionNooderhaaks->setCanBeSelectedOnApplication(true); $contactNooderhaaks = new Member(); $contactNooderhaaks->setId(1338); @@ -45,6 +46,7 @@ public function load(ObjectManager $manager) $divisionAchterhoek = new Division(); $divisionAchterhoek->setName("Achterhoek"); $divisionAchterhoek->setPostCode("4321BA"); + $divisionAchterhoek->setCanBeSelectedOnApplication(true); $contactAchterhoek = new Member(); $contactAchterhoek->setId(8673); diff --git a/src/Form/MembershipApplicationType.php b/src/Form/MembershipApplicationType.php index a17c079..a94aa44 100644 --- a/src/Form/MembershipApplicationType.php +++ b/src/Form/MembershipApplicationType.php @@ -25,14 +25,31 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('lastName', null, ['label' => 'Achternaam', 'error_bubbling' => true, 'constraints' => [new NotBlank()]]) ->add('email', null, ['label' => 'E-mailadres', 'error_bubbling' => true, 'constraints' => [new NotBlank()]]) - ->add('phone', null, ['label' => 'Telefoonnummer', 'error_bubbling' => true, 'constraints' => [new NotBlank()]]) + ->add('phone', null, ['label' => 'Telefoonnummer', 'error_bubbling' => true, 'constraints' => [new NotBlank()]]); + + if ($options['max_age']) { + $age_constraint = new Age([ + 'min' => $options['min_age'], + 'max' => $options['max_age'], + 'message' => 'Je moet tussen de {{ min }} en {{ max }} jaar oud zijn om lid te worden van ' . $options['organization_name'] . '.' + ]); + } else { + $age_constraint = new Age([ + 'min' => $options['min_age'], + 'message' => 'Je moet minimaal {{ min }} jaar oud zijn om lid te worden van ' . $options['organization_name'] . '.' + ]); + } + + $builder ->add('dateOfBirth', null, [ 'label' => 'Geboortedatum', 'required' => true, 'widget' => 'single_text', - 'constraints' => [new NotBlank(), new Age(['min' => 14, 'max' => 27, 'message' => 'Je moet tussen de {{ min }} en {{ max }} jaar oud zijn om lid te worden van ROOD.'])], + 'constraints' => [new NotBlank(), $age_constraint], 'error_bubbling' => true - ]) + ]); + + $builder // ->add('iban', null, ['label' => 'IBAN-rekeningnummer', 'error_bubbling' => true]) ->add('address', null, ['label' => 'Adres', 'error_bubbling' => true, 'constraints' => [new NotBlank()]]) ->add('city', null, ['label' => 'Plaats', 'error_bubbling' => true, 'constraints' => [new NotBlank()]]) @@ -83,5 +100,13 @@ public function configureOptions(OptionsResolver $resolver) $resolver->setRequired([ 'contribution' ]); + + $resolver->setRequired([ + 'min_age' + ]); + + $resolver->setRequired([ + 'max_age' + ]); } }