WIP: Extend and improve profile editing

This commit is contained in:
Björn Fromme
2023-10-01 16:39:32 +02:00
parent 6595fbec8a
commit d776d37cd5
27 changed files with 553 additions and 375 deletions
+3 -3
View File
@@ -2,7 +2,7 @@
namespace App\Form;
use App\BusProNet\ApiClient;
use App\BusProNet\DataProvider\Countries;
use App\Form\ChoiceLoader\BpnCountryChoiceLoader;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\ChoiceList;
@@ -12,7 +12,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class BpnCountryType extends AbstractType
{
public function __construct(private readonly ApiClient $apiClient)
public function __construct(private readonly Countries $countries)
{}
public function getParent(): string
@@ -29,7 +29,7 @@ class BpnCountryType extends AbstractType
'choice_loader' => function (Options $options) {
return ChoiceList::loader(
$this,
new BpnCountryChoiceLoader($this->apiClient, $options['property']),
new BpnCountryChoiceLoader($this->countries, $options['property']),
[$options['property']]
);
},
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Form;
use App\BusProNet\DataProvider\Pickups;
use App\Form\ChoiceLoader\BpnPickupsChoiceLoader;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class BpnPickupType extends AbstractType
{
public function __construct(private readonly Pickups $pickups)
{}
public function getParent(): string
{
return ChoiceType::class;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'choice_loader' => new BpnPickupsChoiceLoader($this->pickups),
]);
}
}
@@ -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;
}
}
+27
View File
@@ -8,6 +8,7 @@ use App\Service\Upload\UploadHandler;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
@@ -79,6 +80,32 @@ class TeamerProfileType extends AbstractType
'label' => false,
'error_bubbling' => false,
])
->add('pickups', CollectionType::class, [
'label' => 'Zustiege',
'entry_type' => BpnPickupType::class,
'allow_add' => true,
'allow_delete' => true,
])
->add('language', TextType::class, [
'label' => 'Sprache(n)',
])
->add('size', ChoiceType::class, [
'label' => 'Klamottengröße',
'choices' => [
'S' => 'S',
'M' => 'M',
'L' => 'L',
'XL' => 'XL',
'XXL' => 'XXL',
],
])
->add('status', ChoiceType::class, [
'label' => 'Status',
'choices' => [
'Neuteamer' => Teamer::STATUS_NEW,
'Bestandsteamer' => Teamer::STATUS_EXISTING,
],
])
;
}