Skip to content

Commit

Permalink
[Admin] Update adherent export
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi authored and Rémi committed Feb 27, 2025
1 parent f21d0de commit c7d902c
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions src/Admin/AbstractAdherentAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Intl\Countries;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Service\Attribute\Required;
use Symfony\Contracts\Translation\TranslatorInterface;
Expand Down Expand Up @@ -1038,24 +1039,29 @@ protected function configureExportFields(): array

try {
return [
'ID' => $adherent->getId(),
'UUID' => $adherent->getUuid()->toString(),
'PID' => $adherent->getPublicId(),
'Email' => $adherent->getEmailAddress(),
'Civilité' => $this->translator->trans(array_search($adherent->getGender(), Genders::CIVILITY_CHOICES, true)),
'Prénom' => $adherent->getFirstName(),
'Nom' => $adherent->getLastName(),
'Date de naissance' => $adherent->getBirthdate()?->format('d/m/Y'),
'Adresse email' => $adherent->getEmailAddress(),
'Téléphone' => PhoneNumberUtils::format($adherent->getPhone()),
'Préférences de notifications' => implode(', ', array_map(function (SubscriptionType $subscriptionType): string {
return $subscriptionType->getLabel();
}, $adherent->getSubscriptionTypes())),
'Comité' => (string) $adherent->getCommitteeMembership()?->getCommittee(),
'Adresse postale' => $adherent->getAddress(),
'Complément d\'adresse' => $adherent->getAdditionalAddress(),
'Code postal' => $adherent->getPostalCode(),
'Code INSEE' => $adherent->getInseeCode(),
'Ville' => $adherent->getCityName(),
'Pays' => $adherent->getCountry(),
'Labels' => implode(', ', array_map([$this->tagTranslator, 'trans'], $adherent->tags)),
'Pays' => Countries::getName($adherent->getCountry()),
'Comité' => (string) $adherent->getCommitteeMembership()?->getCommittee(),
'Circonscription' => implode(', ', array_map(function (Zone $zone): string {
return $zone->getCode().' - '.$zone->getName();
}, $adherent->getZonesOfType(Zone::DISTRICT))),
'Département' => implode(', ', array_map(function (Zone $zone): string {
return $zone->getCode().' - '.$zone->getName();
}, $adherent->getZonesOfType(Zone::DEPARTMENT))),
'Région' => implode(', ', array_map(function (Zone $zone): string {
return $zone->getCode().' - '.$zone->getName();
}, $adherent->getZonesOfType(Zone::REGION))),
'Rôles' => implode(', ', array_map(function (AdherentZoneBasedRole $role): string {
return \sprintf(
'%s [%s]',
Expand All @@ -1069,6 +1075,23 @@ protected function configureExportFields(): array
}, $role->getZones()->toArray()))
);
}, $adherent->getZoneBasedRoles())),
'Labels militants' => implode(', ', array_filter(array_map(function (string $tag): ?string {
if (!\in_array($tag, TagEnum::getAdherentTags(), true)) {
return null;
}

return $this->tagTranslator->trans($tag);
}, $adherent->tags))),
'Labels Élus' => implode(', ', array_filter(array_map(function (string $tag): ?string {
if (!\in_array($tag, TagEnum::getElectTags(), true)) {
return null;
}

return $this->tagTranslator->trans($tag);
}, $adherent->tags))),
'Déclaration de mandats' => implode(', ', array_map(function (string $declaredMandate): string {
return $this->translator->trans("adherent.mandate.type.$declaredMandate");
}, $adherent->getMandates())),
'Mandats' => implode(', ', array_map(function (ElectedRepresentativeAdherentMandate $mandate): string {
$str = $this->translator->trans('adherent.mandate.type.'.$mandate->mandateType);

Expand All @@ -1082,6 +1105,19 @@ protected function configureExportFields(): array

return $str;
}, $adherent->getElectedRepresentativeMandates())),
'Labels divers' => implode(', ', array_filter(array_map(function (string $tag): ?string {
if (\in_array($tag, array_merge(TagEnum::getAdherentTags(), TagEnum::getElectTags()), true)) {
return null;
}

return $this->tagTranslator->trans($tag);
}, $adherent->tags))),
'Labels statiques' => implode(', ', array_map(function (AdherentStaticLabel $label): string {
return $label->label;
}, $adherent->getStaticLabels()->toArray())),
'Préférences de notifications' => implode(', ', array_map(function (SubscriptionType $subscriptionType): string {
return $subscriptionType->getLabel();
}, $adherent->getSubscriptionTypes())),
'Date de création de compte' => $adherent->getRegisteredAt()?->format('d/m/Y H:i:s'),
'Date de première cotisation' => $adherent->getFirstMembershipDonation()?->format('d/m/Y H:i:s'),
'Date de dernière cotisation' => $adherent->getLastMembershipDonation()?->format('d/m/Y H:i:s'),
Expand Down

0 comments on commit c7d902c

Please sign in to comment.