src/EventSubscriber/LeaveCancellationAcceptGuardSubscriber.php line 23
<?phpnamespace App\EventSubscriber;use App\Entity\Leave;use App\Entity\LeaveCancellationRequest;use App\Enum\LeaveCancellationRequestStatus;use App\WorkMonthManagement\WorkMonthChecker;use Symfony\Component\Workflow\Event\GuardEvent;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class LeaveCancellationAcceptGuardSubscriber implements EventSubscriberInterface{private WorkMonthChecker $workMonthChecker;public function __construct(WorkMonthChecker $workMonthChecker,){$this->workMonthChecker = $workMonthChecker;}public function guardAccept(GuardEvent $event): void{/** @var LeaveCancellationRequest $leaveCancellatioRequest */$leaveCancellationRequest = $event->getSubject();/** @var Leave $leave */$leave = $leaveCancellationRequest->getLeave();if ($this->workMonthChecker->isLockedWorkMonthIntersectingPeriod($leave->getEmployee(), $leave->getStartDate(), $leave->getEndDate())// $alreadyHasACancellationRequest// && (// $leaveCancellationRequest->getStatus() === LeaveCancellationRequestStatus::REQUESTED// || $leaveCancellationRequest->getStatus() === LeaveCancellationRequestStatus::ACCEPTED// )) {$event->setBlocked(true,'A cancellation request already exists for this leave, please accept it instead.');}$employee = $leave->getEmployee();$startDate = $leave->getStartDate();$endDate = $leave->getEndDate();if ($this->workMonthChecker->isLockedWorkMonthIntersectingPeriod($employee, $startDate, $endDate)) {$event->setBlocked(true,'The month the leave is in was already validated by a Project Admin.');}}public static function getSubscribedEvents(): array{$workflowName = 'leave_cancellation_request';$transitionName = 'accept';return ['workflow.' . $workflowName . '.guard.' . $transitionName => ['guardAccept'],];}}