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;
}
}