WIP: Extend and improve profile editing

This commit is contained in:
Björn Fromme committed 2023-10-01 16:39:32 +02:00
1 parent 6595fbec8a
commit d776d37cd5
27 files changed
+553 -375

No files matched your search

@@ -2,29 +2,22 @@
namespace App\Form\ChoiceLoader;
use App\BusProNet\ApiClient;
use App\BusProNet\ApiClientException;
use App\BusProNet\Model\CountriesResponse;
use App\BusProNet\DataProvider\Countries;
use App\BusProNet\Model\Country;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
class BpnCountryChoiceLoader implements ChoiceLoaderInterface
{
public function __construct(private readonly ApiClient $apiClient, private readonly string $property)
public function __construct(private readonly Countries $countries, private readonly string $property)
{}
public function loadChoiceList(callable $value = null): ChoiceListInterface
{
try {
/** @var CountriesResponse $response */
$response = $this->apiClient->getCountries();
$countries = $response->getCountries();
} catch (ApiClientException $e) {
$countries = [];
}
$choices = [];
/** @var Country[] $countries */
$countries = $this->countries->getAll();
foreach ($countries as $country) {
$key = 'nationality' === $this->property ? $country->getNationality() : $country->getName();
@@ -0,0 +1,41 @@
<?php
namespace App\Form\ChoiceLoader;
use App\BusProNet\DataProvider\Pickups;
use App\BusProNet\Model\Pickup;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
class BpnPickupsChoiceLoader implements ChoiceLoaderInterface
{
public function __construct(private readonly Pickups $pickups)
{}
public function loadChoiceList(callable $value = null): ChoiceListInterface
{
$choices = [];
/** @var Pickup[] $pickups */
$pickups = $this->pickups->getAll();
foreach ($pickups as $pickup) {
$choices[$pickup->getCity()] = $pickup->getBusProId();
}
ksort($choices);
return new ArrayChoiceList($choices);
}
public function loadChoicesForValues(array $values, callable $value = null): array
{
return $values;
}
public function loadValuesForChoices(array $choices, callable $value = null): array
{
return $choices;
}
}