feat: collect assignment and disposition events for statistics
This commit is contained in:
1 parent
e210021fe3
commit
2662d56ac1
26 files changed
+2557
-96
No files matched your search
@@ -22,6 +22,19 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AssignmentType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* The statuses an admin may move an assignment between at will.
|
||||
*
|
||||
* Calling off is deliberately absent: it has to go through the dedicated action, which
|
||||
* also cancels every disposition on the assignment. Choosing it here used to set the
|
||||
* assignment to called_off and leave its teamers holding a live placement on a
|
||||
* cancelled trip.
|
||||
*/
|
||||
private const STATUS_CHOICES = [
|
||||
'Entwurf' => Assignment::STATUS_DRAFT,
|
||||
'veröffentlicht' => Assignment::STATUS_PUBLISHED,
|
||||
];
|
||||
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager)
|
||||
{
|
||||
}
|
||||
@@ -29,14 +42,8 @@ class AssignmentType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('status', ChoiceType::class, [
|
||||
'label' => 'Status',
|
||||
'choices' => [
|
||||
'Entwurf' => Assignment::STATUS_DRAFT,
|
||||
'veröffentlicht' => Assignment::STATUS_PUBLISHED,
|
||||
'abgesagt' => Assignment::STATUS_CALLED_OFF,
|
||||
],
|
||||
])
|
||||
// status is added in PRE_SET_DATA, where the assignment behind the form is
|
||||
// known - an already called off one has to keep that value in the list.
|
||||
->add('availableDispositions', IntegerType::class, [
|
||||
'label' => 'zu vergeben',
|
||||
'required' => false,
|
||||
@@ -138,6 +145,9 @@ class AssignmentType extends AbstractType
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$form = $event->getForm();
|
||||
$data = $event->getData();
|
||||
|
||||
$this->addStatusField($data, $form);
|
||||
|
||||
$destination = $data->getDestination();
|
||||
|
||||
if (null === $destination) {
|
||||
@@ -170,6 +180,38 @@ class AssignmentType extends AbstractType
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* The statuses this form may set on a given assignment.
|
||||
*
|
||||
* An assignment that is already called off has to keep that value in the list, or the
|
||||
* form could not render it and any save would silently reset the status. It stays
|
||||
* switchable back to published, since there is no other way to undo a call-off made by
|
||||
* mistake - what is blocked is entering the state, not leaving it.
|
||||
*
|
||||
* ChoiceType validates a submission against whatever this returns, so it holds against
|
||||
* a hand-crafted POST too, not just the rendered select.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function statusChoices(?Assignment $assignment): array
|
||||
{
|
||||
$choices = self::STATUS_CHOICES;
|
||||
|
||||
if (null !== $assignment && Assignment::STATUS_CALLED_OFF === $assignment->getStatus()) {
|
||||
$choices['abgesagt'] = Assignment::STATUS_CALLED_OFF;
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
private function addStatusField(?Assignment $assignment, FormInterface $form): void
|
||||
{
|
||||
$form->add('status', ChoiceType::class, [
|
||||
'label' => 'Status',
|
||||
'choices' => self::statusChoices($assignment),
|
||||
]);
|
||||
}
|
||||
|
||||
private function addPickupField(Destination $destination, FormInterface $form): void
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
Reference in new issue
Block a user