From e33fe5a6b7d3a14f002c9db43a5b711e3b46d0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 13 Nov 2024 10:03:48 +0100 Subject: [PATCH] feat: match pickups by name --- src/Service/Teamer/PickupResolver.php | 40 +++++++++++++++++++ src/Twig/AppExtension.php | 1 + src/Twig/AppRuntime.php | 7 ++++ .../_assignment_requirements_info.html.twig | 2 +- .../teamer/modal_info.html.twig | 4 ++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/Service/Teamer/PickupResolver.php diff --git a/src/Service/Teamer/PickupResolver.php b/src/Service/Teamer/PickupResolver.php new file mode 100644 index 0000000..2542dc3 --- /dev/null +++ b/src/Service/Teamer/PickupResolver.php @@ -0,0 +1,40 @@ +pickupDataProvider->get($pickupId); + + if (null === $pickup) { + return false; + } + + $teamerPickups = array_map(function (int $id) { + return $this->pickupDataProvider->get($id); + }, $teamer->getPickups()); + + foreach ($teamerPickups as $teamerPickup) { + $teamerPickupCity = trim($teamerPickup->getCity()); + $pickupCity = trim($pickup->getCity()); + if ($teamerPickupCity === $pickupCity) { + return true; + } + } + + return false; + } +} \ No newline at end of file diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 291b6c2..af7a2e1 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -32,6 +32,7 @@ class AppExtension extends AbstractExtension new TwigFunction('is_current_route', [AppRuntime::class, 'isCurrentRoute']), new TwigFunction('return_url', [AppRuntime::class, 'getEncodedReturnUrl']), new TwigFunction('qa_attribute', [AppRuntime::class, 'renderQaAttribute'], ['is_safe' => ['html']]), + new TwigFunction('has_pickup', [AppRuntime::class, 'hasPickup']), ]; } } diff --git a/src/Twig/AppRuntime.php b/src/Twig/AppRuntime.php index b92b1e8..d3afdfd 100644 --- a/src/Twig/AppRuntime.php +++ b/src/Twig/AppRuntime.php @@ -6,6 +6,7 @@ use App\BusProNet\DataProvider\CountryDataProvider; use App\BusProNet\DataProvider\PickupDataProvider; use App\Entity\Teamer; use App\Entity\Upload; +use App\Service\Teamer\PickupResolver; use Carbon\Carbon; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Contracts\Translation\TranslatorInterface; @@ -21,6 +22,7 @@ class AppRuntime implements RuntimeExtensionInterface private readonly TranslatorInterface $translator, private readonly CountryDataProvider $countries, private readonly PickupDataProvider $pickups, + private readonly PickupResolver $pickupResolver, private readonly string $environment ) { } @@ -86,6 +88,11 @@ class AppRuntime implements RuntimeExtensionInterface return 'ab '.$pickup->getCity(); } + public function hasPickup(?int $pickupId, Teamer $teamer): bool + { + return $this->pickupResolver->hasPickup($pickupId, $teamer); + } + public function fileIconFilter(Environment $environment, string $mimeType, ?string $classes = 'w-4 h-4'): string { $icon = match ($mimeType) { diff --git a/templates/_partials/_assignment_requirements_info.html.twig b/templates/_partials/_assignment_requirements_info.html.twig index 46331c9..cd17d5b 100644 --- a/templates/_partials/_assignment_requirements_info.html.twig +++ b/templates/_partials/_assignment_requirements_info.html.twig @@ -3,7 +3,7 @@
  • Busbegleitung ab {{ assignment.destination.pickup(assignment.pickup).city }} - {% if teamer.hasPickup(assignment.pickup) %} + {% if has_pickup(assignment.pickup, teamer) %} {{ icon('check', 'w-5 h-5 text-green-500 shrink-0') }} {% else %} {{ icon('close', 'w-5 h-5 text-red-500 shrink-0') }} diff --git a/templates/administrative/teamer/modal_info.html.twig b/templates/administrative/teamer/modal_info.html.twig index 087ee6a..07dd158 100644 --- a/templates/administrative/teamer/modal_info.html.twig +++ b/templates/administrative/teamer/modal_info.html.twig @@ -15,6 +15,10 @@
  • {{ pickup|bpn_pickup_label }}
  • + {% else %} +
  • + - +
  • {% endfor %}