/** * Method to check if a leave request can be deleted * * @param \Symfony\Component\Security\Core\User\UserInterface $user * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $leaveRequest * @param type $isAdmin * @param type $isGeneralManager * @return type */ protected function isLRDeleteable(UserInterface $user, $leaveRequest, $isAdmin, $isGeneralManager) { // If user is gm of lr or user is admin always allow delete if ($isGeneralManager || $isAdmin) { return VoterInterface::ACCESS_GRANTED; } elseif ($user->getEmployee() === $leaveRequest->getEmployee()) { // If lr is child of mlr do not allow to deletion if ($leaveRequest->getLeaveRequestGroup()) { return VoterInterface::ACCESS_DENIED; } else { $leaves = $leaveRequest->getLeaves(); $numberOfPastLeaves = 0; foreach ($leaves as $leave) { if ($leave->getStartDate()->format('Y-m-d') < date('Y-m-d')) { $numberOfPastLeaves++; } } if (0 === $numberOfPastLeaves) { return VoterInterface::ACCESS_GRANTED; } } } return VoterInterface::ACCESS_DENIED; }