Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

use Phinx\Db\Adapter\MysqlAdapter;
use Phinx\Migration\AbstractMigration;

final class AddGenreToUsersSpeakersAndTickets extends AbstractMigration
{
public function change(): void
{
$this->table('afup_personnes_physiques')
->addColumn('genre', 'string', [
'null' => true,
'after' => 'civilite',
'limit' => MysqlAdapter::TEXT_TINY,
])
->save();

$this->query(<<<SQL
UPDATE afup_personnes_physiques
SET genre = CASE civilite
WHEN 'Mme' THEN 'femme'
WHEN 'M.' THEN 'homme'
WHEN '0' THEN 'homme'
WHEN '1' THEN 'femme'
WHEN '2' THEN 'femme'
ELSE NULL
END;
SQL);

$this->table('afup_conferenciers')
->addColumn('genre', 'string', [
'null' => true,
'after' => 'civilite',
'limit' => MysqlAdapter::TEXT_TINY,
])
->save();

$this->query(<<<SQL
UPDATE afup_conferenciers
SET genre = CASE civilite
WHEN 'Mme' THEN 'femme'
WHEN 'M.' THEN 'homme'
WHEN 'M' THEN 'homme'
ELSE NULL
END;
SQL);

$this->table('afup_inscription_forum')
->addColumn('genre', 'string', [
'null' => true,
'after' => 'civilite',
'limit' => MysqlAdapter::TEXT_TINY,
])
->save();

$this->query(<<<SQL
UPDATE afup_inscription_forum
SET genre = CASE civilite
WHEN 'Mme' THEN 'femme'
WHEN 'M.' THEN 'homme'
WHEN 'M' THEN 'homme'
ELSE NULL
END;
SQL);
}
}
7 changes: 4 additions & 3 deletions db/seeds/Conferenciers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use AppBundle\Association\Genre;
use Phinx\Seed\AbstractSeed;

class Conferenciers extends AbstractSeed
Expand All @@ -14,7 +15,7 @@ public function run(): void
[
'conferencier_id' => self::ID_CONFERENCIER,
'id_forum' => Event::ID_FORUM,
'civilite' => 'M.',
'genre' => Genre::Homme->value,
'nom' => 'Bachelet',
'prenom' => 'Geoffrey',
'email' => 'foo@bar.baz',
Expand All @@ -34,7 +35,7 @@ public function run(): void
[
'conferencier_id' => 2,
'id_forum' => Event::ID_FORUM,
'civilite' => 'M.',
'genre' => Genre::Homme->value,
'nom' => 'Gallou',
'prenom' => 'Adrien',
'email' => 'foo@bar.baz',
Expand All @@ -54,7 +55,7 @@ public function run(): void
[
'conferencier_id' => 3,
'id_forum' => Event::ID_FORUM,
'civilite' => 'M.',
'genre' => Genre::Homme->value,
'nom' => 'Doe',
'prenom' => 'John',
'email' => 'john.do@bar.baz',
Expand Down
17 changes: 9 additions & 8 deletions db/seeds/Inscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use AppBundle\Association\Genre;
use AppBundle\Association\MemberType;
use AppBundle\Event\Model\Ticket;
use Phinx\Seed\AbstractSeed;
Expand All @@ -17,7 +18,7 @@ public function run(): void
'reference' => 'REF-TEST-001',
'type_inscription' => Tarif::TYPE_2_DAYS['id'],
'montant' => Tarif::TYPE_2_DAYS['default_price'],
'civilite' => 'Mme',
'genre' => Genre::Femme->value,
'nom' => 'Michu',
'prenom' => 'Bernadette',
'email' => 'bernadette@yahoo.fr',
Expand All @@ -34,7 +35,7 @@ public function run(): void
'reference' => 'REF-TEST-002',
'type_inscription' => Tarif::TYPE_2_DAYS['id'],
'montant' => Tarif::TYPE_2_DAYS['default_price'],
'civilite' => 'Mme',
'genre' => Genre::Femme->value,
'nom' => 'Jean',
'prenom' => 'Maurice',
'email' => 'jean@yahoo.fr',
Expand All @@ -51,7 +52,7 @@ public function run(): void
'reference' => 'REF-TEST-003',
'type_inscription' => Tarif::TYPE_2_DAYS['id'],
'montant' => Tarif::TYPE_2_DAYS['default_price'],
'civilite' => 'Mme',
'genre' => Genre::Femme->value,
'nom' => 'Kirk',
'prenom' => 'James Tiberius',
'email' => 'james@starfleet.fr',
Expand All @@ -68,7 +69,7 @@ public function run(): void
'reference' => 'REF-TEST-004',
'type_inscription' => Tarif::TYPE_2_DAYS_AFUP['id'],
'montant' => Tarif::TYPE_2_DAYS_AFUP['default_price'],
'civilite' => 'Mme',
'genre' => Genre::Femme->value,
'nom' => 'Sans',
'prenom' => 'Cotisation',
'email' => 'sans@cotisation.fr',
Expand All @@ -85,7 +86,7 @@ public function run(): void
'reference' => 'REF-TEST-005',
'type_inscription' => Tarif::TYPE_2_DAYS_AFUP['id'],
'montant' => Tarif::TYPE_2_DAYS_AFUP['default_price'],
'civilite' => 'M',
'genre' => Genre::Homme->value,
'nom' => 'Personne',
'prenom' => 'Paul',
'email' => 'paul.personne@mycorp.fr',
Expand All @@ -103,7 +104,7 @@ public function run(): void
'reference' => 'REF-TEST-006',
'type_inscription' => Tarif::TYPE_2_DAYS_AFUP['id'],
'montant' => Tarif::TYPE_2_DAYS_AFUP['default_price'],
'civilite' => 'M',
'genre' => Genre::Homme->value,
'nom' => 'Maurice',
'prenom' => 'Jean',
'email' => 'userexpire@yahoo.fr',
Expand All @@ -121,7 +122,7 @@ public function run(): void
'reference' => 'REF-TEST-007',
'type_inscription' => Tarif::TYPE_2_DAYS['id'],
'montant' => Tarif::TYPE_2_DAYS['default_price'],
'civilite' => 'Mme',
'genre' => Genre::Femme->value,
'nom' => 'Annulé',
'prenom' => 'Lepaiement',
'email' => 'annule@example.com',
Expand All @@ -138,7 +139,7 @@ public function run(): void
'reference' => 'REF-TEST-008',
'type_inscription' => Tarif::TYPE_ORGANIZATION['id'],
'montant' => Tarif::TYPE_ORGANIZATION['default_price'],
'civilite' => 'Mme',
'genre' => Genre::Femme->value,
'nom' => 'Super',
'prenom' => 'Bénévole',
'email' => 'benevole@example.com',
Expand Down
2 changes: 0 additions & 2 deletions db/seeds/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function run(): void
$data = [
[
'id' => self::ID_PERSONNE_MORALE_MY_CORP,
'civilite' => '1',
'nom' => 'Dupont',
'prenom' => 'Raoul',
'email' => 'raoul.dupont@mycorp.fr',
Expand All @@ -40,7 +39,6 @@ public function run(): void
],
[
'id' => self::ID_PERSONNE_MORALE_HELIOS_AEROSPACE,
'civilite' => '1',
'nom' => 'Ayesa',
'prenom' => 'Dev',
'email' => 'dev.ayesa@helios-aerospace.com',
Expand Down
1 change: 0 additions & 1 deletion sources/AppBundle/Association/Factory/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public function createForRegister(): User

return
$user
->setCivility(User::CIVILITE_M)
->setCountry('FR')
->setLevel(User::LEVEL_MEMBER)
->setStatus(User::STATUS_ACTIVE)
Expand Down
12 changes: 8 additions & 4 deletions sources/AppBundle/Association/Form/RegisterUserType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace AppBundle\Association\Form;

use AppBundle\Association\Genre;
use AppBundle\Association\Model\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
Expand All @@ -33,9 +34,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('nearestOffice', NearestOfficeChoiceType::class, [
'required' => false,
])
->add('civility', ChoiceType::class, [
'choices' => ['M.' => User::CIVILITE_M, 'Mme' => User::CIVILITE_MME],
'required' => true,
->add('genre', EnumType::class, [
'required' => false,
'class' => Genre::class,
'label' => 'Genre',
'placeholder' => 'Ne se prononce pas',
'choice_label' => fn(Genre $genre): string => $genre->label(),
])
;

Expand Down
5 changes: 2 additions & 3 deletions sources/AppBundle/Association/Form/UserEditFormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AppBundle\Association\Form;

use AppBundle\Association\Genre;
use AppBundle\Association\Model\Repository\UserRepository;
use AppBundle\Association\Model\User;
use AppBundle\Validator\Constraints as AppAssert;
Expand All @@ -15,9 +16,7 @@
class UserEditFormData
{
public $companyId;
#[Assert\NotBlank]
#[Assert\Choice(choices: ['M.', 'Mme'], strict: true)]
public $civility = 'M.';
public ?Genre $genre = null;
#[Assert\NotBlank]
public $lastname;
#[Assert\NotBlank]
Expand Down
13 changes: 8 additions & 5 deletions sources/AppBundle/Association/Form/UserEditType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
namespace AppBundle\Association\Form;

use Afup\Site\Utils\Pays;
use AppBundle\Association\Genre;
use AppBundle\Association\Model\Repository\CompanyMemberRepository;
use AppBundle\Association\Model\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
Expand All @@ -32,17 +34,18 @@ public function __construct(

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$civilities = ['M.', 'Mme'];
$builder
->add('companyId', ChoiceType::class, [
'label' => 'Personne morale',
'required' => false,
'choices' => array_flip($this->companyMemberRepository->getList()),
])
->add('civility', ChoiceType::class, [
'label' => 'Civilité',
'required' => true,
'choices' => array_combine($civilities, $civilities),
->add('genre', EnumType::class, [
'required' => false,
'class' => Genre::class,
'label' => 'Genre',
'placeholder' => 'Ne se prononce pas',
'choice_label' => fn(Genre $genre): string => $genre->label(),
])
->add('lastname', TextType::class, [
'label' => 'Nom',
Expand Down
21 changes: 21 additions & 0 deletions sources/AppBundle/Association/Genre.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace AppBundle\Association;

enum Genre: string
{
case Femme = 'femme';
case Homme = 'homme';
case NonBinaire = 'non-binaire';

public function label(): string
{
return match ($this) {
self::Femme => 'Femme',
self::Homme => 'Homme',
self::NonBinaire => 'Non-binaire',
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AppBundle\Association\Model\Repository;

use AppBundle\Association\Genre;
use AppBundle\Association\MemberType;
use AppBundle\Association\Model\CompanyMember;
use AppBundle\Association\Model\User;
Expand All @@ -15,6 +16,7 @@
use CCMBenchmark\Ting\Repository\Metadata;
use CCMBenchmark\Ting\Repository\MetadataInitializer;
use CCMBenchmark\Ting\Repository\Repository;
use CCMBenchmark\Ting\Serializer\BackedEnum;
use CCMBenchmark\Ting\Serializer\SerializerFactoryInterface;
use Exception;
use InvalidArgumentException;
Expand Down Expand Up @@ -375,7 +377,7 @@ private function getQueryBuilderWithCompleteUser()
->getQueryBuilderWithSubscriptions()
->cols([
'app.`id`', 'app.`id_personne_morale`', 'app.`login`', 'app.`mot_de_passe`', 'app.`niveau`',
'app.`niveau_modules`', 'app.`roles`', 'app.`civilite`', 'app.`nom`', 'app.`prenom`', 'app.`email`',
'app.`niveau_modules`', 'app.`roles`', 'app.`genre`', 'app.`nom`', 'app.`prenom`', 'app.`email`',
'app.`adresse`', 'app.`code_postal`', 'app.`ville`', 'app.`id_pays`', 'app.`telephone_fixe`',
'app.`telephone_portable`', 'app.`etat`', 'app.`date_relance`', 'app.`compte_svn`',
'app.`slack_invite_status`', 'app.`slack_alternate_email`', 'app.`needs_up_to_date_membership`',
Expand Down Expand Up @@ -508,9 +510,13 @@ public static function initMetadata(SerializerFactoryInterface $serializerFactor
'type' => 'string',
])
->addField([
'columnName' => 'civilite',
'fieldName' => 'civility',
'type' => 'string',
'columnName' => 'genre',
'fieldName' => 'genre',
'type' => 'enum',
'serializer' => BackedEnum::class,
'serializer_options' => [
'unserialize' => ['enum' => Genre::class],
],
])
->addField([
'columnName' => 'prenom',
Expand Down
Loading
Loading