WIP: Implement profile editing
This commit is contained in:
@@ -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 doesn‘t 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' => [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
],
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user