WIP: Implement profile editing

This commit is contained in:
Björn Fromme
2023-10-02 15:07:02 +02:00
parent 953aa9c8e0
commit d3a0021b7d
12 changed files with 311 additions and 47 deletions
+78
View File
@@ -0,0 +1,78 @@
<?php
namespace App\Form;
use App\Entity\JobProfile;
use App\Entity\Teamer;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Translation\TranslatableMessage;
class TeamerJobProfileType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$selectableProfiles = $options['selectable_job_profiles'];
$builder
->add('jobProfiles', EntityType::class, [
'label' => false,
'class' => JobProfile::class,
// Append potential training or license requirements to profile labels
'choice_label' => function($choice, string $key, mixed $value): TranslatableMessage|string {
$label = $choice->getName();
$requirements = [];
if (null !== $training = $choice->getRequiredTraining()) {
$requirements[].= $training->getName();
}
foreach ($choice->getRequiredLicenses() as $license) {
$requirements[] = sprintf('Offizielle %slehrer*innenlizenz', ucfirst($license));
}
if ($requirements) {
$label .= sprintf(' (%s: %s)', 1 === count($requirements) ?
'Voraussetzung' : 'Voraussetzungen', implode(', ', $requirements));
}
return $label;
},
// Set disabled attribute on profiles that require a training or licenses the teamer doesnt have
'choice_attr' => function($choice, string $key, mixed $value) use ($selectableProfiles) {
if (true === $selectableProfiles[$choice->getId()]) {
return [];
}
return ['disabled' => 'disabled'];
},
'expanded' => true,
'multiple' => true,
])
->add('status', ChoiceType::class, [
'label' => 'Status',
'choices' => [
'Neuteamer' => Teamer::STATUS_NEW,
'Bestandsteamer' => Teamer::STATUS_EXISTING,
],
])
->add('remarks', TextareaType::class, [
'label' => 'Wünsche/Anmerkungen',
'required' => false,
'attr' => [
'rows' => 3,
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Teamer::class,
'job_profiles' => [],
'selectable_job_profiles' => [],
]);
}
}
-14
View File
@@ -63,13 +63,6 @@ class TeamerProfileType extends AbstractType
'label' => 'Krankenversicherung',
'required' => false,
])
->add('remarks', TextareaType::class, [
'label' => 'Wünsche/Anmerkungen',
'required' => false,
'attr' => [
'rows' => 3,
],
])
->add('address', AddressType::class, [
'label' => false,
])
@@ -99,13 +92,6 @@ class TeamerProfileType extends AbstractType
'XXL' => 'XXL',
],
])
->add('status', ChoiceType::class, [
'label' => 'Status',
'choices' => [
'Neuteamer' => Teamer::STATUS_NEW,
'Bestandsteamer' => Teamer::STATUS_EXISTING,
],
])
;
}