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 @@