feat: pickup selection depending on bus chaperon
This commit is contained in:
1 parent
5b93ce421c
commit
cf90ffcd19
13 files changed
+207
-58
No files matched your search
@@ -6,6 +6,7 @@ use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Form\TeamerDispositionType;
|
||||
use App\Model\UploadSessionDto;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -36,18 +37,21 @@ class DetailController extends AbstractController
|
||||
#[IsGranted('VIEW', subject: 'disposition')]
|
||||
public function index(Disposition $disposition, Request $request): Response
|
||||
{
|
||||
$isUploadContract = $this->workflow->can($disposition, 'upload_contract');
|
||||
$isUploadInvoice = $this->workflow->can($disposition, 'upload_invoice');
|
||||
|
||||
// Create dummy form without fields to generate POST requests
|
||||
$form = $this->createFormBuilder()->getForm();
|
||||
$form = $this->createForm(TeamerDispositionType::class, $disposition, ['enable_pickup' => $isUploadContract]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$uploadSession = $this->uploadHandler->getUploadSession();
|
||||
|
||||
if (0 < $uploadSession->getCount()) {
|
||||
if (true === $this->workflow->can($disposition, 'upload_contract')) {
|
||||
if (true === $isUploadContract) {
|
||||
$this->uploadContract($disposition, $uploadSession);
|
||||
}
|
||||
if (true === $this->workflow->can($disposition, 'upload_invoice')) {
|
||||
if (true === $isUploadInvoice) {
|
||||
$this->uploadInvoice($disposition, $uploadSession);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ class Application implements TimestampableEntityInterface
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $requests = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $pickup = null;
|
||||
|
||||
#[ORM\Column(length: 64)]
|
||||
private ?string $status;
|
||||
|
||||
@@ -97,6 +100,18 @@ class Application implements TimestampableEntityInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPickup(): ?int
|
||||
{
|
||||
return $this->pickup;
|
||||
}
|
||||
|
||||
public function setPickup(?int $pickup): static
|
||||
{
|
||||
$this->pickup = $pickup;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): ?string
|
||||
{
|
||||
return $this->status;
|
||||
|
||||
@@ -42,6 +42,9 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf
|
||||
#[ORM\ManyToOne(inversedBy: 'dispositions')]
|
||||
private ?Teamer $teamer;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $pickup = null;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $remarks;
|
||||
|
||||
@@ -58,6 +61,7 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf
|
||||
$this->status = static::STATUS_NEW;
|
||||
$this->assignment = $application->getAssignment();
|
||||
$this->teamer = $application->getTeamer();
|
||||
$this->pickup = $application->getPickup();
|
||||
$this->documents = new ArrayCollection();
|
||||
}
|
||||
|
||||
@@ -107,6 +111,18 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPickup(): ?int
|
||||
{
|
||||
return $this->pickup;
|
||||
}
|
||||
|
||||
public function setPickup(?int $pickup): static
|
||||
{
|
||||
$this->pickup = $pickup;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRemarks(): ?string
|
||||
{
|
||||
return $this->remarks;
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Form;
|
||||
use App\Entity\Application;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
@@ -27,32 +28,36 @@ class TeamerApplicationType extends AbstractType
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
/** @var Application $application */
|
||||
$application = $event->getData();
|
||||
$form = $event->getForm();
|
||||
|
||||
if (null === $application) {
|
||||
return;
|
||||
}
|
||||
|
||||
$assignment = $application->getAssignment();
|
||||
|
||||
if (0 === (int) $assignment->getPickup()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$teamer = $application->getTeamer();
|
||||
|
||||
if (in_array($assignment->getPickup(), $teamer->getPickups())) {
|
||||
return;
|
||||
if (0 === (int) $assignment->getPickup()) {
|
||||
$pickupChoices = [];
|
||||
foreach ($assignment->getDestination()->getPickups() as $pickup) {
|
||||
$pickupChoices[$pickup['city']] = $pickup['busProId'];
|
||||
}
|
||||
ksort($pickupChoices);
|
||||
$form->add('pickup', ChoiceType::class, [
|
||||
'label' => 'Zustieg in',
|
||||
'choices' => $pickupChoices,
|
||||
]);
|
||||
} elseif (false === in_array($assignment->getPickup(), $teamer->getPickups())) {
|
||||
$form->add('confirmPickup', CheckboxType::class, [
|
||||
'label' => 'Ich bestätige den abweichenden Buszustieg',
|
||||
'mapped' => false,
|
||||
'constraints' => [
|
||||
new IsTrue([
|
||||
'message' => 'Deine Bestätigung ist erforderlich',
|
||||
]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$event->getForm()->add('confirmPickup', CheckboxType::class, [
|
||||
'label' => 'Ich bestätige den abweichenden Buszustieg',
|
||||
'mapped' => false,
|
||||
'constraints' => [
|
||||
new IsTrue([
|
||||
'message' => 'Deine Bestätigung ist erforderlich',
|
||||
]),
|
||||
],
|
||||
]);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Disposition;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TeamerDispositionType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
if (true === $options['enable_pickup']) {
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
/** @var Disposition $disposition */
|
||||
$disposition = $event->getData();
|
||||
$assignment = $disposition->getAssignment();
|
||||
|
||||
// Add pickup select field only to assignments that are not including bus chaperon
|
||||
if (0 === (int) $assignment->getPickup()) {
|
||||
$pickupChoices = [];
|
||||
foreach ($assignment->getDestination()->getPickups() as $pickup) {
|
||||
$pickupChoices[$pickup['city']] = $pickup['busProId'];
|
||||
}
|
||||
ksort($pickupChoices);
|
||||
$event->getForm()->add('pickup', ChoiceType::class, [
|
||||
'label' => 'Zustieg in',
|
||||
'choices' => $pickupChoices,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Disposition::class,
|
||||
'enable_pickup' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user