/**
  * Method to add a notification
  * 
  * @param TravelRequest/TravelExpense $resource
  * @param integer $toGeneralManager
  */
 public function addNewTravelNotification($resource, $toGeneralManager, $status)
 {
     // get last status name from resource
     $resourceStatus = strtolower($status->getName());
     $message = '';
     if ($resource instanceof TravelRequest) {
         $notification = new TRNotification();
         $notification->setTravelRequest($resource);
         $receiver = $resource->getGeneralManager();
         $message .= 'travel request (' . $resource->getTravelRequestId() . ') ';
     } elseif ($resource instanceof TravelExpense) {
         $notification = new TENotification();
         $notification->setTravelExpense($resource);
         $receiver = $resource->getTravelRequest()->getGeneralManager();
         $message .= 'travel expense ';
     }
     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 = $resource->getUser();
     }
     $notification->setMessage($message);
     $notification->setReceiver($receiver);
     $notification->setDateTime(new \DateTime('now'));
     $notification = $this->setNotificationStatus($notification);
     $this->entityManager->persist($notification);
     $this->entityManager->flush();
 }
Esempio n. 2
0
 /**
  * Add notifications
  *
  * @param \Opit\OpitHrm\TravelBundle\Entity\TRNotification $notifications
  * @return TravelRequest
  */
 public function addNotification(\Opit\OpitHrm\TravelBundle\Entity\TRNotification $notifications)
 {
     $this->notifications[] = $notifications;
     $notifications->setTravelRequest($this);
     return $this;
 }