Skip to content

Commit

Permalink
[Alerts] multiple election alerts (#10895)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano authored Oct 21, 2024
1 parent 15ed82f commit 2682251
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/JeMengage/Alert/AlertProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 1 addition & 2 deletions src/JeMengage/Alert/Provider/AlertProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 6 additions & 4 deletions src/JeMengage/Alert/Provider/ElectionAlertProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ public function __construct(
) {
}

public function getAlert(Adherent $adherent): ?Alert
public function getAlerts(Adherent $adherent): array
{
$designations = $this->electionManager->findActiveDesignations(
$adherent,
[DesignationTypeEnum::LOCAL_POLL, DesignationTypeEnum::CONSULTATION, DesignationTypeEnum::VOTE],
);

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,
Expand All @@ -39,6 +41,6 @@ public function getAlert(Adherent $adherent): ?Alert
}
}

return null;
return $alerts;
}
}

0 comments on commit 2682251

Please sign in to comment.