From f5e88b54181198aec8dd38f54f0512272cd9feab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 13 Oct 2023 15:17:11 +0200 Subject: [PATCH] Feat: Add more workflow guards --- .../DispositionWorkflowGuardSubscriber.php | 35 ++++++++++++++++++- translations/messages.de.yaml | 16 +++++---- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/EventListener/DispositionWorkflowGuardSubscriber.php b/src/EventListener/DispositionWorkflowGuardSubscriber.php index a602386..2a9852f 100644 --- a/src/EventListener/DispositionWorkflowGuardSubscriber.php +++ b/src/EventListener/DispositionWorkflowGuardSubscriber.php @@ -3,9 +3,10 @@ namespace App\EventListener; use App\Entity\Disposition; +use App\Entity\Upload; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Component\Workflow\Event\GuardEvent; +use Symfony\Contracts\Translation\TranslatorInterface; class DispositionWorkflowGuardSubscriber implements EventSubscriberInterface { @@ -15,11 +16,28 @@ class DispositionWorkflowGuardSubscriber implements EventSubscriberInterface public static function getSubscribedEvents(): array { return [ + 'workflow.disposition.guard.confirm_contract' => ['guardConfirmContract'], 'workflow.disposition.guard.upload_contract' => ['guardUploadContract'], 'workflow.disposition.guard.upload_invoice' => ['guardUploadInvoice'], + 'workflow.disposition.guard.confirm_invoice' => ['guardConfirmInvoice'], ]; } + public function guardConfirmContract(GuardEvent $event): void + { + /** @var Disposition $disposition */ + $disposition = $event->getSubject(); + $contractDocument = $disposition->getDocumentByType(Upload::TYPE_CONTRACT); + + if (null === $contractDocument || Upload::STATUS_CHECKED !== $contractDocument->getStatus()) { + $message = $this + ->translator + ->trans('message.confirm_contract.document_missing_or_not_checked') + ; + $event->setBlocked(true, $message); + } + } + public function guardUploadContract(GuardEvent $event): void { /** @var Disposition $disposition */ @@ -75,4 +93,19 @@ class DispositionWorkflowGuardSubscriber implements EventSubscriberInterface $event->setBlocked(true, $message); } } + + public function guardConfirmInvoice(GuardEvent $event): void + { + /** @var Disposition $disposition */ + $disposition = $event->getSubject(); + $invoiceDocument = $disposition->getDocumentByType(Upload::TYPE_INVOICE); + + if (null === $invoiceDocument || Upload::STATUS_CHECKED !== $invoiceDocument->getStatus()) { + $message = $this + ->translator + ->trans('message.confirm_invoice.document_missing_or_not_checked') + ; + $event->setBlocked(true, $message); + } + } } \ No newline at end of file diff --git a/translations/messages.de.yaml b/translations/messages.de.yaml index 5a10c9d..01e8bcd 100644 --- a/translations/messages.de.yaml +++ b/translations/messages.de.yaml @@ -23,18 +23,22 @@ label: error: Fehler message: + confirm_contract: + document_missing_or_not_checked: 'Der Honorarvertrag wurde noch nicht hochgeladen oder ist noch nicht geprüft worden.' upload_contract: - too_late: 'Die Frist für den Upload des Honorarvertrages ist abgelaufen (%date_from% - %date_to%). Bitte wende dich an deinen Ansprechpartner' + too_late: 'Die Frist für den Upload des Honorarvertrages ist abgelaufen (%date_from% - %date_to%). Bitte wende dich an deinen Ansprechpartner.' upload_invoice: too_early: 'Du kannst deine Honorarnote mit Beginn deines Einsatzes ab dem %date% einreichen.' too_late: 'Du hättest deine Honorarnote bis zum %date% einreichen müssen. Bitte wende dich an deinen Ansprechpartner.' + confirm_invoice: + document_missing_or_not_checked: 'Die Honorarnote wurde noch nicht hochgeladen oder ist noch nicht geprüft worden.' uploader: - drop_files: Dateien hier ablegen oder - click_here: hier klicken - file_too_big: Die maximale Dateigröße beträgt %maxFilesize%MB - invalid_file_type: Der Dateityp ist nicht erlaubt - max_files_exceeded: Die maximale Anzahl von Dateien is %maxFilesExceeded% + drop_files: 'Dateien hier ablegen oder' + click_here: 'hier klicken' + file_too_big: 'Die maximale Dateigröße beträgt %maxFilesize%MB' + invalid_file_type: 'Der Dateityp ist nicht erlaubt' + max_files_exceeded: 'Die maximale Anzahl von Dateien is %maxFilesExceeded%' paginator: previous: vorherige