Skip to content

Commit

Permalink
Added possibility to configure amount of required phone numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
theoboldt committed Oct 4, 2023
1 parent b88e0f3 commit 2e57bd8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ parameters:

# Set to true to enable newsletter feature
feature.newsletter: true

# Specify amount of phone numbers required per participation
required_participation_phone_number_count: 1
1 change: 1 addition & 0 deletions app/config/parameters_defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ parameters:
app.gender.exclude: ''
mailer_imap_host: null
feature.registration: true
required_participation_phone_number_count: 1
1 change: 1 addition & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ services:
arguments:
$featureRegistration: "%feature.registration%"
$featureNewsletter: '%feature.newsletter%'
$requiredParticipationPhoneNumberCount: '%required_participation_phone_number_count%'
tags: [ 'controller.service_arguments' ]

AppBundle\Controller\UserController:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class PublicParticipateController
* @var bool
*/
private bool $featureRegistration;

/**
* @var int
*/
private int $requiredParticipationPhoneNumberCount;

/**
* app.participation_manager
Expand All @@ -72,6 +77,7 @@ class PublicParticipateController
* @param SessionInterface $session
* @param string $featureNewsletter
* @param string $featureRegistration
* @param string $requiredParticipationPhoneNumberCount
* @param ParticipationManager $participationManager
*/
public function __construct(
Expand All @@ -84,6 +90,7 @@ public function __construct(
SessionInterface $session,
string $featureNewsletter,
string $featureRegistration,
string $requiredParticipationPhoneNumberCount,
ParticipationManager $participationManager
)
{
Expand All @@ -97,6 +104,7 @@ public function __construct(
$this->featureNewsletter = $featureNewsletter;
$this->featureRegistration = $featureRegistration;
$this->participationManager = $participationManager;
$this->requiredParticipationPhoneNumberCount = (int)$requiredParticipationPhoneNumberCount;
}

/**
Expand Down Expand Up @@ -132,6 +140,7 @@ public function participateAction(Event $event, Request $request)
[
ParticipationType::ACQUISITION_FIELD_PUBLIC => true,
ParticipationType::ACQUISITION_FIELD_PRIVATE => false,
ParticipationType::PHONE_NUMBER_MIN_COUNT => $this->requiredParticipationPhoneNumberCount,
]
);

Expand Down
4 changes: 2 additions & 2 deletions app/src/AppBundle/Entity/Participation.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class Participation implements EventRelatedEntity, SummandCausableInterface, Ent
* @Assert\Valid()
* @Assert\Count(
* min = "1",
* minMessage = "Bei einer Anmeldung muss mindestens eine Telefonnummer angegeben werden, unter der wir Sie in
* Notfällen erreichen können. Bitte fügen Sie mindestens noch eine Telefonnummer hinzu."
* minMessage = "Bei einer Anmeldung müssen Telefonnummern angegeben werden, unter der wir Sie in
* Notfällen erreichen können. Bitte fügen Sie Telefonnummern hinzu."
* )
*/
protected $phoneNumbers;
Expand Down
20 changes: 20 additions & 0 deletions app/src/AppBundle/Form/ParticipationBaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Count;

class ParticipationBaseType extends AbstractType
{

const PHONE_NUMBER_MIN_COUNT = 'phoneNumberMinCount';

const ACQUISITION_FIELD_PUBLIC = 'acquisitionFieldPublic';

const ACQUISITION_FIELD_PRIVATE = 'acquisitionFieldPrivate';
Expand All @@ -30,6 +34,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Participation $participation */
$participation = $options['data'] ?? null;

if ($options[self::PHONE_NUMBER_MIN_COUNT] > 1) {
$phoneNumberConstraints = [
new Count([
'min' => $options[self::PHONE_NUMBER_MIN_COUNT],
'minMessage' => 'Es müssen mindestens '.(int)$options[self::PHONE_NUMBER_MIN_COUNT].' Telefonnummern angegeben werden',
])
];
} else {
$phoneNumberConstraints = [];
}

$builder
->add(
Expand Down Expand Up @@ -90,6 +105,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'allow_delete' => true,
'attr' => ['aria-describedby' => 'help-info-phone-numbers'],
'required' => true,
'constraints' => $phoneNumberConstraints
]
)
->add(
Expand Down Expand Up @@ -130,6 +146,10 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setRequired(self::ACQUISITION_FIELD_PRIVATE);
$resolver->setAllowedTypes(self::ACQUISITION_FIELD_PRIVATE, 'bool');

$resolver->setRequired(self::PHONE_NUMBER_MIN_COUNT);
$resolver->setDefault(self::PHONE_NUMBER_MIN_COUNT, 1);
$resolver->setAllowedTypes(self::PHONE_NUMBER_MIN_COUNT, 'int');

$resolver->setDefaults(
[
'data_class' => Participation::class,
Expand Down

0 comments on commit 2e57bd8

Please sign in to comment.