feat: match pickups by name

This commit is contained in:
Björn Fromme
2024-11-13 10:03:48 +01:00
parent 5643f6fffb
commit e33fe5a6b7
5 changed files with 53 additions and 1 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace App\Service\Teamer;
use App\BusProNet\DataProvider\PickupDataProvider;
use App\Entity\Teamer;
class PickupResolver
{
public function __construct(private readonly PickupDataProvider $pickupDataProvider)
{
}
public function hasPickup(?int $pickupId, Teamer $teamer): bool
{
if (null === $pickupId) {
return false;
}
$pickup = $this->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;
}
}
+1
View File
@@ -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']),
];
}
}
+7
View File
@@ -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) {
@@ -3,7 +3,7 @@
<li class="py-2">
<div class="flex items-center justify-between">
<span class="flex-1">Busbegleitung ab {{ assignment.destination.pickup(assignment.pickup).city }}</span>
{% 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') }}
@@ -15,6 +15,10 @@
<li class="py-2">
{{ pickup|bpn_pickup_label }}
</li>
{% else %}
<li class="py-2">
-
</li>
{% endfor %}
</ul>
<h2 class="text-lg font-bold">