feat: match pickups by name
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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']),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user