Skip to content

Commit

Permalink
[143] Add middle names
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwildor committed Mar 10, 2024
1 parent 19cb0cd commit 466fa78
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 17 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ORGANIZATION_NAME_SHORT='ROOD'
ORG_LOGO='assets/image/logo.png'
PRIVACY_POLICY_URL='https://roodjongeren.nl/privacybeleid/'
LISTMONK_URL='https://listmonk.roodjongeren.nl/admin'
USE_MIDDLE_NAME=true

# Set to https in production environment
SECURE_SCHEME='http'
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ Go to `http://localhost:8080/` and you should be greeted by the MijnRood login p
You can log in with `admindebaas@example.com` as email, and `admin` as password.
Look at `src/DataFixtures/` to see an overview of all test data, including other accounts.

## Contributing

You can generate new migrations with:

`docker compose run --rm php82-service symfony console doctrine:migrations:diff`

Make sure the output is as you expected, and change it if necessary!

## License

This project is licensed under the EUPL, the license text in English can be found in the `LICENSE` file.
Expand Down
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ parameters:
app.orgLogo: '%env(ORG_LOGO)%'
app.privacyPolicyUrl: '%env(PRIVACY_POLICY_URL)%'
app.listmonkUrl: '%env(string:LISTMONK_URL)%'
app.useMiddleName: '%env(bool:USE_MIDDLE_NAME)%'
router.request_context.scheme: '%env(SECURE_SCHEME)%'
asset.request_context.secure: true

Expand Down
37 changes: 37 additions & 0 deletions migrations/Version20240305203045.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240305203045 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// Socialisten already has this column, so we're using IF NOT EXIST, and alter it again after update to set the default value
$this->addSql('ALTER TABLE admin_member ADD COLUMN IF NOT EXISTS middle_name VARCHAR(50) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE admin_membership_application ADD COLUMN IF NOT EXISTS middle_name VARCHAR(50) DEFAULT \'\' NOT NULL');
$this->addSql('UPDATE admin_member SET middle_name = \'\' WHERE middle_name IS NULL');
$this->addSql('UPDATE admin_membership_application SET middle_name = \'\' WHERE middle_name IS NULL');
$this->addSql('ALTER TABLE admin_member CHANGE middle_name middle_name VARCHAR(50) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE admin_membership_application CHANGE middle_name middle_name VARCHAR(50) DEFAULT \'\' NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE admin_member DROP middle_name');
$this->addSql('ALTER TABLE admin_membership_application DROP middle_name');
}
}
9 changes: 8 additions & 1 deletion src/Controller/Admin/MemberCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,20 @@ public function configureFields(string $pageName): iterable
->setFormTypeOptions(['attr' => ['placeholder' => 'Wordt automatisch bepaald']]),

TextField::new('firstName', 'Voornaam')->setDisabled(!$isAdmin),
];

if ($this->getParameter('app.useMiddleName')) {
$fields[] = TextField::new('middleName', 'Tussenvoegsel')->setDisabled(!$isAdmin)->setRequired(false);
}

array_push($fields,
TextField::new('lastName', 'Achternaam')->setDisabled(!$isAdmin),
DateField::new('dateOfBirth', 'Geboortedatum')->setDisabled(!$isAdmin)->hideOnIndex(),
DateField::new('registrationTime', 'Inschrijfdatum')
->setFormat(DateTimeField::FORMAT_SHORT)
->hideOnIndex(),
TextField::new('comments', 'Extra informatie'),
];
);

if ($isAdmin) {
$fields[] = AssociationField::new('currentMembershipStatus', 'Lidmaatschapstype');
Expand Down
17 changes: 13 additions & 4 deletions src/Controller/Admin/MembershipApplicationCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function acceptApplication(AdminContext $context)

$message = (new Email())
->subject("Welkom bij $organizationName!")
->to(new Address($member->getEmail(), $member->getFirstName() .' '. $member->getLastName()))
->to(new Address($member->getEmail(), $member->getFullName()))
->from(new Address($noreply,$organizationName))
->html(
$this->renderView('email/html/welcome.html.twig', ['member' => $member])
Expand All @@ -147,7 +147,7 @@ public function acceptApplication(AdminContext $context)
{
$message2 = (new Email())
->subject('Nieuw lid aangesloten bij je groep')
->to(new Address($contact->getEmail(), $contact->getFirstName() .' '. $contact->getLastName()))
->to(new Address($contact->getEmail(), $contact->getFullName()))
->from(new Address($noreply, $organizationName))
->html(
$this->renderView('email/html/contact_new_member.html.twig', [
Expand All @@ -174,8 +174,15 @@ public function acceptApplication(AdminContext $context)

public function configureFields(string $pageName): iterable
{
return [
$fields = [
TextField::new('firstName', 'Voornaam'),
];

if ($this->getParameter('app.useMiddleName')) {
$fields[] = TextField::new('middleName', 'Tussenvoegsel')->setRequired(false);
}

array_push($fields,
TextField::new('lastName', 'Achternaam'),
DateField::new('dateOfBirth', 'Geboortedatum')
->hideOnIndex(),
Expand Down Expand Up @@ -209,7 +216,9 @@ public function configureFields(string $pageName): iterable
->hideOnIndex(),

BooleanField::new('paid', 'Eerste contributie betaald')
];
);

return $fields;
}

public function configureFilters(Filters $filters): Filters
Expand Down
11 changes: 8 additions & 3 deletions src/Controller/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ public function apply(Request $request): Response {
$membershipApplication = new MembershipApplication();
$membershipApplication->setRegistrationTime(new \DateTime());
$membershipApplication->setContributionPeriod(Member::PERIOD_QUARTERLY);
$form = $this->createForm(MembershipApplicationType::class, $membershipApplication);
$form = $this->createForm(MembershipApplicationType::class, $membershipApplication, [
'use_middle_name' => $this->getParameter('app.useMiddleName'),
'privacy_policy_url' => $this->getParameter('app.privacyPolicyUrl'),
'organization_name' => $this->getParameter('app.organizationName')
]);

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
Expand All @@ -107,7 +111,7 @@ public function apply(Request $request): Response {
else
{
$customer = $this->mollieApiClient->customers->create([
'name' => $membershipApplication->getFirstName() . ' ' . $membershipApplication->getLastName(),
'name' => $membershipApplication->getFullName(),
'email' => $membershipApplication->getEmail()
]);

Expand All @@ -125,7 +129,8 @@ public function apply(Request $request): Response {

return $this->render('user/member/apply.html.twig', [
'success' => false,
'form' => $form->createView()
'form' => $form->createView(),
'useMiddleName' => $this->getParameter('app.useMiddleName')
]);
}

Expand Down
3 changes: 2 additions & 1 deletion src/DataFixtures/MemberFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public function load(ObjectManager $manager)
$newMember = new Member();
$newMember->setId(1339);
$newMember->setFirstName("Henk");
$newMember->setLastName("de Vries");
$newMember->setMiddleName("de");
$newMember->setLastName("Vries");
$newMember->setEmail("henkdevries@example.com");
$newMember->setContributionPerPeriodInEuros(5);
$newMember->setPasswordHash(password_hash("new_member", PASSWORD_DEFAULT));
Expand Down
13 changes: 12 additions & 1 deletion src/Entity/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Member implements UserInterface {
*/
private string $firstName = '';

/**
* @ORM\Column(type="string", length=50, options={"default": ""})
*/
private string $middleName = '';

/**
* @ORM\Column(type="string", length=100)
*/
Expand Down Expand Up @@ -184,11 +189,17 @@ public function setId(int $id): void { $this->id = $id; }
public function getFirstName(): string { return $this->firstName; }
public function setFirstName(string $firstName): void { $this->firstName = $firstName; }

public function getMiddleName(): string { return $this->middleName; }
public function setMiddleName(?string $middleName): void { $this->middleName = $middleName ? $middleName : ''; }

public function getLastName(): string { return $this->lastName; }
public function setLastName(string $lastName): void { $this->lastName = $lastName; }

public function getFullName(): string {
return $this->firstName. ' ' . $this->lastName;
if ($this->middleName === '') {
return $this->firstName. ' ' . $this->lastName;
}
return $this->firstName . ' ' . $this->middleName . ' ' . $this->lastName;
}

public function getAddress(): string { return $this->address; }
Expand Down
16 changes: 16 additions & 0 deletions src/Entity/MembershipApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class MembershipApplication {
*/
private string $firstName = '';

/**
* @ORM\Column(type="string", length=50, options={"default": ""})
*/
private string $middleName = '';

/**
* @ORM\Column(type="string", length=100)
*/
Expand Down Expand Up @@ -118,6 +123,7 @@ public function __toString() {
public function createMember(?string $mollieSubscriptionId): Member {
$member = new Member();
$member->setFirstName($this->getFirstName());
$member->setMiddleName($this->getMiddleName());
$member->setLastName($this->getLastName());
$member->setAddress($this->getAddress());
$member->setCity($this->getCity());
Expand All @@ -142,9 +148,19 @@ public function setId(int $id): void { $this->id = $id; }
public function getFirstName(): string { return $this->firstName; }
public function setFirstName(string $firstName): void { $this->firstName = $firstName; }

public function getMiddleName(): string { return $this->middleName; }
public function setMiddleName(?string $middleName): void { $this->middleName = $middleName ? $middleName : ''; }

public function getLastName(): string { return $this->lastName; }
public function setLastName(string $lastName): void { $this->lastName = $lastName; }

public function getFullName(): string {
if ($this->middleName === '') {
return $this->firstName. ' ' . $this->lastName;
}
return $this->firstName . ' ' . $this->middleName . ' ' . $this->lastName;
}

public function getAddress(): string { return $this->address; }
public function setAddress(string $address): void { $this->address = $address; }

Expand Down
23 changes: 20 additions & 3 deletions src/Form/MembershipApplicationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ class MembershipApplicationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('firstName', null, ['label' => 'Voornaam', 'error_bubbling' => true, 'constraints' => [new NotBlank()]]);

if ($options['use_middle_name']) {
$builder->add('middleName', null, ['label' => 'Tussenvoegsel', 'error_bubbling' => true]);
}

$builder
->add('firstName', null, ['label' => 'Voornaam', 'error_bubbling' => true, 'constraints' => [new NotBlank()]])
->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()]])
Expand Down Expand Up @@ -46,12 +51,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'error_bubbling' => true
])
->add('accept', CheckboxType::class, [
'label' => 'Ik heb het <a target="_blank" href="https://roodjongeren.nl/privacybeleid">privacybeleid</a> gelezen en ik ga daarmee akkoord.',
'label' => 'Ik heb het <a target="_blank" href="' . $options['privacy_policy_url'] . '">privacybeleid</a> gelezen en ik ga daarmee akkoord.',
'label_html' => true,
'mapped' => false,
'required' => true,
'error_bubbling' => true,
'constraints' => [new IsTrue(['message' => 'Je moet akkoord gaan met het privacybeleid van ROOD, tenzij je jonger bent dan 16.'])]
'constraints' => [new IsTrue(['message' => 'Je moet akkoord gaan met het privacybeleid van ' . $options['organization_name'] . ', tenzij je jonger bent dan 16.'])]
])
;
}
Expand All @@ -61,5 +66,17 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setDefaults([
'data_class' => MembershipApplication::class,
]);

$resolver->setRequired([
'use_middle_name'
]);

$resolver->setRequired([
'privacy_policy_url'
]);

$resolver->setRequired([
'organization_name'
]);
}
}
2 changes: 1 addition & 1 deletion templates/email/html/contact_new_member.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Beste {{ member.division.contact.firstName }} {{ member.division.contact.lastName }},
</p>
<p>
Onlangs heeft een nieuw lid zich aangemeld bij {{ organisatienaam }}: {{ member.firstName }} {{ member.lastName }}.
Onlangs heeft een nieuw lid zich aangemeld bij {{ organisatienaam }}: {{ member.getFullName }}.
Hun lidmaatschap is zojuist goedgekeurd door het bestuur van {{ organisatienaam }}. Bij het aanmelden heeft dit lid aangegeven
zich graag aan te sluiten bij de groep {{ member.division.name }}.
</p>
Expand Down
2 changes: 1 addition & 1 deletion templates/email/html/request_new_password.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% set url = url('set_new_password', { token: member.newPasswordToken }) %}
{% block content %}
<p>
Beste {{ member.firstName }} {{ member.lastName }},
Beste {{ member.getFullName }},
</p>
<p>
Je hebt in het ledenadministratiesysteem een verzoek gedaan om een nieuw wachtwoord in te stellen.
Expand Down
2 changes: 1 addition & 1 deletion templates/email/text/contact_new_member.txt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ r% extends 'email/text/layout.txt.twig' %}
{% block content %}
Beste {{ member.division.contact.firstName }} {{ member.division.contact.lastName }},

Onlangs heeft een nieuw lid zich aangemeld bij {{ organisatienaam }}: {{ member.firstName }} {{ member.lastName }}.
Onlangs heeft een nieuw lid zich aangemeld bij {{ organisatienaam }}: {{ member.getFullName }}.
Hun lidmaatschap is zojuist goedgekeurd door het bestuur van {{ organisatienaam }}. Bij het aanmelden heeft dit lid aangegeven zich graag aan te sluiten bij de groep {{ member.division.name }}.

Hun gegevens zijn toegevoegd aan het ledenoverzicht in het ledenadministratiesysteem. Klik op de onderstaande link om het te openen.
Expand Down
2 changes: 1 addition & 1 deletion templates/email/text/request_new_password.txt.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'email/text/layout.txt.twig' %}
{% set url = url('set_new_password', { token: member.newPasswordToken }) %}
{% block content %}
Beste {{ member.firstName }} {{ member.lastName }},
Beste {{ member.getFullName }},

Je hebt in het ledenadministratiesysteem een verzoek gedaan om een nieuw wachtwoord in te stellen.
Als je je niet kunt herinneren dat je dit gedaan hebt, kun je deze e-mail negeren.
Expand Down
5 changes: 5 additions & 0 deletions templates/user/member/apply.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
{{ form_label(form.firstName, 'Naam') }}
<div class="form-field-group">
{{ form_widget(form.firstName, { attr: { class: 'text-input', placeholder: 'Voornaam' } }) }}

{% if useMiddleName %}
{{ form_widget(form.middleName, { attr: { class: 'text-input', placeholder: 'Tussenvoegsel' } }) }}
{% endif %}

{{ form_widget(form.lastName, { attr: { class: 'text-input', placeholder: 'Achternaam' } }) }}
</div>
</div>
Expand Down

0 comments on commit 466fa78

Please sign in to comment.