feat: reject potential other applications on contract confirmation
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Upload;
|
||||
use App\Event\ApplicationStatusEvent;
|
||||
use App\Event\DocumentConfirmedEvent;
|
||||
use App\Model\ApplicationStatusDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
#[AsEventListener(event: DocumentConfirmedEvent::NAME, method: 'onDocumentConfirmed')]
|
||||
class RejectApplicationListener
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function onDocumentConfirmed(DocumentConfirmedEvent $event): void
|
||||
{
|
||||
$document = $event->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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user