From 26822510496a87669bd4dda43357187792f044ab Mon Sep 17 00:00:00 2001 From: Dimitri Date: Mon, 21 Oct 2024 12:05:19 +0200 Subject: [PATCH] [Alerts] multiple election alerts (#10895) --- src/JeMengage/Alert/AlertProvider.php | 8 ++++---- .../Alert/Provider/AlertProviderInterface.php | 3 +-- src/JeMengage/Alert/Provider/ElectionAlertProvider.php | 10 ++++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/JeMengage/Alert/AlertProvider.php b/src/JeMengage/Alert/AlertProvider.php index 863a2f5cf18..c3f0be81212 100644 --- a/src/JeMengage/Alert/AlertProvider.php +++ b/src/JeMengage/Alert/AlertProvider.php @@ -14,14 +14,14 @@ public function __construct(private readonly iterable $providers) public function getAlerts(Adherent $adherent): array { - $alerts = []; + $allAlerts = []; foreach ($this->providers as $provider) { - if ($alert = $provider->getAlert($adherent)) { - $alerts[] = $alert; + if ($alerts = $provider->getAlerts($adherent)) { + $allAlerts = array_merge($allAlerts, $alerts); } } - return $alerts; + return $allAlerts; } } diff --git a/src/JeMengage/Alert/Provider/AlertProviderInterface.php b/src/JeMengage/Alert/Provider/AlertProviderInterface.php index 1b2d9de33cb..2c70c301ac9 100644 --- a/src/JeMengage/Alert/Provider/AlertProviderInterface.php +++ b/src/JeMengage/Alert/Provider/AlertProviderInterface.php @@ -3,9 +3,8 @@ namespace App\JeMengage\Alert\Provider; use App\Entity\Adherent; -use App\JeMengage\Alert\Alert; interface AlertProviderInterface { - public function getAlert(Adherent $adherent): ?Alert; + public function getAlerts(Adherent $adherent): array; } diff --git a/src/JeMengage/Alert/Provider/ElectionAlertProvider.php b/src/JeMengage/Alert/Provider/ElectionAlertProvider.php index ce374dda152..f2f79e2cd81 100644 --- a/src/JeMengage/Alert/Provider/ElectionAlertProvider.php +++ b/src/JeMengage/Alert/Provider/ElectionAlertProvider.php @@ -16,7 +16,7 @@ public function __construct( ) { } - public function getAlert(Adherent $adherent): ?Alert + public function getAlerts(Adherent $adherent): array { $designations = $this->electionManager->findActiveDesignations( $adherent, @@ -24,12 +24,14 @@ public function getAlert(Adherent $adherent): ?Alert ); if (!$designations) { - return null; + return []; } + $alerts = []; + foreach ($designations as $designation) { if ($designation->alertTitle && $designation->alertDescription) { - return new Alert( + $alerts[] = new Alert( 'Consultation / Élection', $designation->alertTitle, $designation->alertDescription, @@ -39,6 +41,6 @@ public function getAlert(Adherent $adherent): ?Alert } } - return null; + return $alerts; } }