/** * Method to check if the status of a leave request can be changed * * @param \Symfony\Component\Security\Core\User\UserInterface $user * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $leaveRequest * @param type $isAdmin * @param type $isGeneralManager * @param type $leaveRequestStatusId * @return type */ protected function isLRStatusChangeable(UserInterface $user, $leaveRequest, $isAdmin, $isGeneralManager, $leaveRequestStatusId) { if (null === $leaveRequest->getId()) { return VoterInterface::ACCESS_DENIED; } if (in_array($leaveRequestStatusId, array(Status::APPROVED, Status::REJECTED))) { return VoterInterface::ACCESS_DENIED; } // If user is admin and status of lr is not approved allow status change if ($isAdmin) { return VoterInterface::ACCESS_GRANTED; } elseif ($isGeneralManager) { // Check if general manager is owner of leave request if ($user->getEmployee() === $leaveRequest->getEmployee()) { return VoterInterface::ACCESS_GRANTED; } else { // If user is gm only allow status change when lr status is for approval if (Status::FOR_APPROVAL === $leaveRequestStatusId) { return VoterInterface::ACCESS_GRANTED; } } } elseif ($user->getEmployee() === $leaveRequest->getEmployee()) { // If user is assigned employee and status is created or revice allow status change if (in_array($leaveRequestStatusId, array(Status::CREATED, Status::REVISE))) { return VoterInterface::ACCESS_GRANTED; } } return VoterInterface::ACCESS_DENIED; }