From 84ca6942e04e6a4c55defe768bb878d85c6513e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gardien?= Date: Thu, 31 Oct 2024 16:43:16 +0100 Subject: [PATCH] Fix adherent year tag matching --- src/Entity/Adherent.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/Entity/Adherent.php b/src/Entity/Adherent.php index 2fefff85d5..9e73679383 100644 --- a/src/Entity/Adherent.php +++ b/src/Entity/Adherent.php @@ -2277,7 +2277,7 @@ public function getMissingMembershipYears(): array return []; } - $lastYear = $this->getLastAdherentYearTag(); + $lastYear = $this->getLastMembershipYearFromTags(); if (!$lastYear) { return [date('Y')]; @@ -2508,32 +2508,22 @@ public function hasTag(string $tag): bool return TagEnum::includesTag($tag, $this->tags ?? []); } - public function getLastAdherentYearTag(): ?string + public function getLastMembershipYearFromTags(): ?string { - $allTags = array_map( - fn (int $year) => TagEnum::getAdherentYearTag($year), - array_reverse(range(2022, date('Y'))) - ); - + $adherentTag = null; foreach ($this->tags as $tag) { - if (\in_array($tag, $allTags, true)) { - return $tag; + if (preg_match('/^adherent:a_jour_[\d]{4}/')) { + $adherentTag = $tag; + break; } } - return null; - } - - public function getLastMembershipYearFromTags(): ?string - { - $lastAdherentYearTag = $this->getLastAdherentYearTag(); - - if (!$lastAdherentYearTag) { + if (!$adherentTag) { return null; } $matches = []; - if (preg_match('/^adherent:a_jour_([\d]{4})$/', $lastAdherentYearTag, $matches)) { + if (preg_match('/^adherent:a_jour_([\d]{4})/', $lastAdherentYearTag, $matches)) { return $matches[1]; }