Ejemplo 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 = '';
     $notification = new LRNotification();
     $notification->setLeaveRequest($resource);
     $receiver = $resource->getGeneralManager();
     $message .= 'leave request ';
     call_user_func(array($notification, 'set' . Utils::getClassBasename($resource)), $resource);
     if (strpos('approved', $resourceStatus) !== false || strpos('rejected', $resourceStatus) !== false) {
         $message .= ' has been ' . $resourceStatus . '.';
         $message = ucfirst($message);
     } else {
         $message = 'Status of ' . $message;
         $message .= 'changed to ' . $resourceStatus . '.';
     }
     if (false === $toGeneralManager) {
         $receiver = $this->entityManager->getRepository('OpitOpitHrmUserBundle:User')->findOneByEmployee($resource->getEmployee());
     }
     $notification->setMessage($message);
     $notification->setReceiver($receiver);
     $notification->setDateTime(new \DateTime('now'));
     $notification = $this->setNotificationStatus($notification);
     $this->entityManager->persist($notification);
     $this->entityManager->flush();
 }
Ejemplo n.º 2
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();
 }