Exemplo n.º 1
0
 /**
  *
  * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $resource
  * @param boolean $toGeneralManager
  * @param \Opit\OpitHrm\StatusBundle\Entity\Status $status
  */
 public function addNewLeaveNotification(LeaveRequest $resource, $toGeneralManager, Status $status)
 {
     // get last status name from resource
     $resourceStatus = strtolower($status->getName());
     $message = $resource->getLeaveRequestId();
     if (strpos('approved', $resourceStatus) !== false || strpos('rejected', $resourceStatus) !== false) {
         $message .= ' has been ' . $resourceStatus;
         $message = ucfirst($message);
     } else {
         $message .= ' changed to ' . $resourceStatus;
     }
     $message .= ' for ' . $resource->getEmployee()->getEmployeeName() . '.';
     $receiver = false === $toGeneralManager ? $this->entityManager->getRepository('OpitOpitHrmUserBundle:User')->findOneByEmployee($resource->getEmployee()) : $resource->getGeneralManager();
     $notification = new LRNotification();
     $notification->setLeaveRequest($resource);
     $notification->setMessage($message);
     $notification->setReceiver($receiver);
     $notification->setDateTime(new \DateTime('now'));
     $this->setNotificationStatus($notification);
     $this->entityManager->persist($notification);
     // Send notifications to additional recipients if status is set to approved
     if ($status->getId() === Status::APPROVED) {
         if ($teamManager = $resource->getTeamManager()) {
             $notificationsTM = clone $notification;
             $notificationsTM->setReceiver($teamManager);
             $this->entityManager->persist($notificationsTM);
         }
         $ccRecipients = $this->entityManager->getRepository('OpitOpitHrmUserBundle:Employee')->findNotificationRecipients($receiver);
         $notifications = array();
         foreach ($ccRecipients as $i => $employee) {
             $notifications[$i] = clone $notification;
             $notifications[$i]->setReceiver($employee->getUser());
             $this->entityManager->persist($notifications[$i]);
         }
     }
     $this->entityManager->flush();
 }
Exemplo n.º 2
0
 /**
  * Method to check if a leave request can be viewed
  *
  * @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 isLRViewable(UserInterface $user, $leaveRequest, $isAdmin, $isGeneralManager, $leaveRequestStatusId)
 {
     // Check if lr has an id
     if (null === $leaveRequest->getId()) {
         return VoterInterface::ACCESS_GRANTED;
     }
     $generalManagerId = $leaveRequest->getGeneralManager()->getId();
     // If user has admin role show lr
     if ($isAdmin) {
         return VoterInterface::ACCESS_GRANTED;
     } elseif ($isGeneralManager) {
         // If lr has not got the status created and gm is gm of it show lr
         if (Status::CREATED !== $leaveRequestStatusId && $generalManagerId === $user->getId()) {
             return VoterInterface::ACCESS_GRANTED;
         } elseif ($generalManagerId === $user->getId()) {
             // If user is owner of lr show it
             return VoterInterface::ACCESS_GRANTED;
         }
     } elseif ($leaveRequest->getEmployee() === $user->getEmployee()) {
         return VoterInterface::ACCESS_GRANTED;
     }
     return VoterInterface::ACCESS_DENIED;
 }
Exemplo n.º 3
0
 /**
  * Reject the leave requests related to leaves, send a notification and email about it
  *
  * @param array $leaves
  * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $lr
  */
 public function rejectLeavesLRs(array $leaves, LeaveRequest $lr)
 {
     foreach ($leaves as $leave) {
         $leaveRequest = $leave->getLeaveRequest();
         $leaveRequest->setIsOverlapped(true);
         $leaveRequest->setRejectedGmName($lr->getGeneralManager()->getEmployee()->getEmployeeName());
         $status = $this->entityManager->getRepository('OpitOpitHrmStatusBundle:Status')->find(Status::REJECTED);
         $this->leaveNotificationManager->addNewLeaveNotification($leaveRequest, false, $status);
         $this->statusManager->addStatus($leaveRequest, Status::REJECTED);
     }
 }