From 2ebcb3cc99dc857ec2c1bfb5b0cfb076792b9dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 16 Dec 2024 16:32:18 +0100 Subject: [PATCH] feat: reject potential other applications on contract confirmation --- .../RejectApplicationListener.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/EventListener/RejectApplicationListener.php diff --git a/src/EventListener/RejectApplicationListener.php b/src/EventListener/RejectApplicationListener.php new file mode 100644 index 0000000..6d44ea2 --- /dev/null +++ b/src/EventListener/RejectApplicationListener.php @@ -0,0 +1,57 @@ +getDocument(); + if (Upload::TYPE_CONTRACT !== $document->getType()) { + return; + } + + $disposition = $document->getDisposition(); + $teamer = $disposition->getTeamer(); + $otherApplications = $disposition + ->getAssignment() + ->getApplications() + ->filter(function (Application $application) use ($teamer) { + return $application->getTeamer() !== $teamer; + }) + ; + + foreach ($otherApplications as $application) { + $application + ->setStatus(Application::STATUS_REJECTED) + ->setComment('Abgelehnt, da Einsatz bereits anderweitig besetzt') + ; + } + + $this->entityManager->flush(); + + foreach ($otherApplications as $application) { + $statusDto = new ApplicationStatusDto($application); + $this->eventDispatcher->dispatch( + new ApplicationStatusEvent($statusDto), + ApplicationStatusEvent::NAME + ); + } + } +}