/**
  * 
  * @param \Opit\OpitHrm\StatusBundle\Entity\Status $status
  * @param array $nextStates
  * @param object $resource
  * @param integer $requiredStatus
  */
 protected function prepareEmail(Status $status, array $nextStates, $resource, $requiredStatus)
 {
     $this->removeTokens($resource->getId());
     $applicantToken = $this->setApplicantToken($resource->getId());
     $applicationName = $this->options['applicationName'];
     $templateVars = array();
     $templateVars['currentState'] = $status->getName();
     $templateVars['nextStates'] = $nextStates;
     $templateVars['applicant'] = $resource;
     $templateVars['stateChangeLinks'] = array();
     foreach ($nextStates as $key => $value) {
         if ($key !== $requiredStatus) {
             // Generate links that can be used to change the status of the travel request
             $templateVars['stateChangeLinks'][] = $this->router->generate('OpitOpitHrmHiringBundle_change_status', array('hmId' => $resource->getJobPosition()->getHiringManager()->getId(), 'status' => $key, 'token' => $applicantToken), true);
         }
     }
     $recipient = $resource->getJobPosition()->getHiringManager()->getEmail();
     $statusName = $status->getName();
     $this->mailer->setRecipient($recipient);
     if (Status::CREATED === $status->getId()) {
         $this->mailer->setSubject('[' . ($applicationName !== null && $applicationName != 'OPIT-HRM' ? $applicationName : 'OPIT-HRM') . '] - New applicant created (' . $resource->getName() . ')');
     } else {
         $this->mailer->setSubject('[' . ($applicationName !== null && $applicationName != 'OPIT-HRM' ? $applicationName : 'OPIT-HRM') . '] - Applicant status changed - ' . $statusName . ' (' . $resource->getName() . ')');
     }
     $this->mailer->setBodyByTemplate('OpitOpitHrmHiringBundle:Mail:applicant.html.twig', $templateVars);
     $this->mailer->sendMail();
 }
 /**
  *
  * @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();
 }
Esempio n. 3
0
 /**
  * Composes and send an email based on a status change
  *
  * @param Status  $status
  * @param mixed   $resource
  */
 public function prepareEmail(Status $status, $resource)
 {
     $applicationName = $this->options['applicationName'];
     // get template name by converting entity name first letter to lower
     $className = Utils::getClassBasename($resource);
     // lowercase first character of string
     $template = lcfirst($className);
     $statusName = $status->getName();
     $statusId = $status->getId();
     // split class name at uppercase letters
     $subjectType = preg_split('/(?=[A-Z])/', $className);
     // decide if resource is request or expense, if is expense get its request
     $travelRequest = $resource instanceof TravelExpense ? $resource->getTravelRequest() : $resource;
     $generalManager = $travelRequest->getGeneralManager();
     // call method located in travel expense service
     $estimatedCosts = $this->getTRCosts($travelRequest);
     // create string for email travel type e.g.(Travel expense, Travel request)
     $subjectTravelType = $subjectType[1] . ' ' . strtolower($subjectType[2]);
     $stateChangeLinks = array();
     if (Status::FOR_APPROVAL === $statusId) {
         $travelToken = $this->setTravelToken($resource->getId());
         // Exclude current status from next states to prepare the email
         $nextStates = $this->statusManager->getNextStates($status);
         unset($nextStates[$statusId]);
         foreach ($nextStates as $key => $value) {
             // Generate links that can be used to change the status of the travel request
             $stateChangeLinks[] = $this->router->generate('OpitOpitHrmTravelBundle_change_status', array('gmId' => $generalManager->getId(), 'travelType' => $resource::getType(), 'status' => $key, 'token' => $travelToken), true);
         }
         $recipient = $generalManager->getEmail();
         $templateVariables = array('nextStates' => $nextStates, 'stateChangeLinks' => $stateChangeLinks);
     } else {
         $recipient = $travelRequest->getUser()->getEmail();
         $templateVariables = array('currentState' => $statusName, 'url' => $this->router->generate('OpitOpitHrmUserBundle_security_login', array(), true));
         switch ($statusId) {
             case Status::APPROVED:
                 $templateVariables['isApproved'] = true;
                 break;
             case Status::REVISE:
                 $templateVariables['isRevised'] = true;
                 break;
             case Status::REJECTED:
                 $templateVariables['isRejected'] = true;
                 break;
             case Status::CREATED:
                 $templateVariables['isCreated'] = true;
                 break;
         }
     }
     // set estimated in HUF and EUR for template
     $templateVariables['estimatedCostsEUR'] = ceil($estimatedCosts['EUR']);
     $templateVariables['estimatedCostsHUF'] = ceil($estimatedCosts['HUF']);
     $templateVariables[$template] = $resource;
     $this->mailer->setRecipient($recipient);
     $this->mailer->setSubject('[' . ($applicationName !== null && $applicationName != 'OPIT-HRM' ? $applicationName : 'OPIT-HRM') . '] - ' . $subjectTravelType . ' status changed - ' . $statusName . ' (' . $travelRequest->getTravelRequestId() . ')');
     $this->mailer->setBodyByTemplate('OpitOpitHrmTravelBundle:Mail:' . $template . '.html.twig', $templateVariables);
     $this->mailer->sendMail();
 }
 /**
  * 
  * @param \Opit\OpitHrm\HiringBundle\Entity\Applicant $applicant
  */
 public function addNewApplicantNotification(Applicant $applicant, Status $status)
 {
     $statusName = strtolower($status->getName());
     $message = 'State of applicant (' . $applicant->getName() . ') changed to ' . $statusName . '.';
     $notification = new ApplicantNotification();
     $notification->setApplicant($applicant);
     $receiver = $applicant->getJobPosition()->getHiringManager();
     $notification->setMessage($message);
     $notification->setReceiver($receiver);
     $notification->setDateTime(new \DateTime('now'));
     $notification->setRead($this->entityManager->getRepository('OpitOpitHrmNotificationBundle:NotificationStatus')->find(NotificationStatus::UNREAD));
     $this->entityManager->persist($notification);
     $this->entityManager->flush();
 }
Esempio n. 5
0
 public function doLoad(ObjectManager $manager)
 {
     $created = new Status();
     $created->setId(Status::CREATED);
     $created->setName('Created');
     $manager->persist($created);
     $forApproval = new Status();
     $forApproval->setId(Status::FOR_APPROVAL);
     $forApproval->setName('For Approval');
     $manager->persist($forApproval);
     $revise = new Status();
     $revise->setId(Status::REVISE);
     $revise->setName('Revise');
     $manager->persist($revise);
     $approved = new Status();
     $approved->setId(Status::APPROVED);
     $approved->setName('Approved');
     $manager->persist($approved);
     $rejected = new Status();
     $rejected->setId(Status::REJECTED);
     $rejected->setName('Rejected');
     $manager->persist($rejected);
     $paid = new Status();
     $paid->setId(Status::PAID);
     $paid->setName('Paid');
     $manager->persist($paid);
     $manager->flush();
     $this->addReference('created', $created);
     // Created
     $this->addReference('forApproval', $forApproval);
     // For approval
     $this->addReference('revise', $revise);
     // Revise
     $this->addReference('approved', $approved);
     // Approved
     $this->addReference('rejected', $rejected);
     // Rejected
     $this->addReference('paid', $paid);
     // Paid
 }
Esempio n. 6
0
 public function doLoad(ObjectManager $manager)
 {
     $scheduledInterview = new Status();
     $scheduledInterview->setId(Status::SCHEDULE_INTERVIEW);
     $scheduledInterview->setName('Scheduled interview');
     $manager->persist($scheduledInterview);
     $interviewPassed = new Status();
     $interviewPassed->setId(Status::INTERVIEW_PASSED);
     $interviewPassed->setName('Interview passed');
     $manager->persist($interviewPassed);
     $interviewFailed = new Status();
     $interviewFailed->setId(Status::INTERVIEW_FAILED);
     $interviewFailed->setName('Interview failed');
     $manager->persist($interviewFailed);
     $scheduledWrittenExam = new Status();
     $scheduledWrittenExam->setId(Status::SCHEDULE_WRITTEN_EXAM);
     $scheduledWrittenExam->setName('Scheduled written exam');
     $manager->persist($scheduledWrittenExam);
     $writtenExamPassed = new Status();
     $writtenExamPassed->setId(Status::WRITTEN_EXAM_PASSED);
     $writtenExamPassed->setName('Written exam passed');
     $manager->persist($writtenExamPassed);
     $writtenExamFailed = new Status();
     $writtenExamFailed->setId(Status::WRITTEN_EXAM_FAILED);
     $writtenExamFailed->setName('Written exam failed');
     $manager->persist($writtenExamFailed);
     $hired = new Status();
     $hired->setId(Status::HIRED);
     $hired->setName('Hired');
     $manager->persist($hired);
     $manager->flush();
     $this->addReference('scheduledInterview', $scheduledInterview);
     $this->addReference('interviewPassed', $interviewPassed);
     $this->addReference('interviewFailed', $interviewFailed);
     $this->addReference('scheduledWrittenExam', $scheduledWrittenExam);
     $this->addReference('writtenExamPassed', $writtenExamPassed);
     $this->addReference('writtenExamFailed', $writtenExamFailed);
     $this->addReference('hired', $hired);
 }
 /**
  *
  * @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();
 }
Esempio n. 8
0
 /**
  *
  * @param \Opit\OpitHrm\StatusBundle\Entity\Status $status
  * @param array $nextStates
  * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $leaveRequest
  * @param type $requiredStatus
  */
 protected function prepareEmail(Status $status, array $nextStates, $leaveRequest)
 {
     $applicationName = $this->options['applicationName'];
     // get template name by converting entity name first letter to lower
     $className = Utils::getClassBasename($leaveRequest);
     $statusName = $status->getName();
     $statusId = $status->getId();
     // split class name at uppercase letters
     $subjectType = preg_split('/(?=[A-Z])/', $className);
     $generalManager = $leaveRequest->getGeneralManager();
     // create string for email travel type e.g.(Travel expense, Travel request)
     $subjectTravelType = $subjectType[1] . ' ' . strtolower($subjectType[2]);
     $stateChangeLinks = array();
     // Check if leave request status is for approval and send email to gm, if not send to employee
     if (Status::FOR_APPROVAL === $statusId) {
         $leaveToken = $this->setLeaveToken($leaveRequest->getId());
         foreach ($nextStates as $key => $value) {
             // Generate links that can be used to change the status of the travel request
             $stateChangeLinks[] = $this->router->generate('OpitOpitHrmLeaveBundle_change_status', array('gmId' => $generalManager->getId(), 'status' => $key, 'token' => $leaveToken), true);
         }
         $recipient = $generalManager->getEmail();
         $templateVariables = array('nextStates' => $nextStates, 'stateChangeLinks' => $stateChangeLinks);
     } else {
         $employee = $leaveRequest->getEmployee();
         $user = $this->entityManager->getRepository('OpitOpitHrmUserBundle:User')->findByEmployee($employee);
         $recipient = $user[0]->getEmail();
         $templateVariables = array('url' => $this->router->generate('OpitOpitHrmUserBundle_security_login', array(), true));
         switch ($statusId) {
             case Status::APPROVED:
                 $templateVariables['isApproved'] = true;
                 break;
             case Status::REVISE:
                 $templateVariables['isRevised'] = true;
                 break;
             case Status::REJECTED:
                 $templateVariables['isRejected'] = true;
                 break;
             case Status::CREATED:
                 $templateVariables['isCreated'] = true;
                 break;
         }
     }
     $templateVariables['currentState'] = $statusName;
     $templateVariables['employee'] = $leaveRequest->getEmployee();
     $templateVariables['leaveRequest'] = $leaveRequest;
     $this->mailer->setRecipient($recipient);
     $this->mailer->setSubject('[' . ($applicationName !== null && $applicationName != 'OPIT-HRM' ? $applicationName : 'OPIT-HRM') . '] - ' . $subjectTravelType . ' status changed - ' . $statusName . ' (' . $leaveRequest->getLeaveRequestId() . ')');
     $this->mailer->setBodyByTemplate('OpitOpitHrmLeaveBundle:Mail:leaveRequest.html.twig', $templateVariables);
     $this->mailer->sendMail();
 }
Esempio n. 9
0
 /**
  *
  * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $leaveRequest
  * @param \Opit\OpitHrm\StatusBundle\Entity\Status $currentStatus
  * @return array
  */
 public function setLeaveRequestAccessRights(LeaveRequest $leaveRequest, Status $currentStatus)
 {
     // Only usable if token is present
     $this->isAllowed();
     $isStatusLocked = true;
     // status can not be changed
     $unlockedStates = array();
     $currentEmployee = $this->tokenStorage->getToken()->getUser()->getEmployee();
     $isGeneralManager = $this->isUserGeneralManager($leaveRequest);
     if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
         if ($leaveRequest->getEmployee()->getId() === $currentEmployee->getId()) {
             if ($isGeneralManager) {
                 $unlockedStates = array(Status::FOR_APPROVAL);
             }
             if (in_array($currentStatus->getId(), array_merge(array(Status::CREATED, Status::REVISE), $unlockedStates))) {
                 $isStatusLocked = false;
             }
         } elseif ($isGeneralManager) {
             if (Status::FOR_APPROVAL === $currentStatus->getId()) {
                 $isStatusLocked = false;
             }
         }
     } else {
         $isStatusLocked = false;
         if (in_array($currentStatus->getId(), array(Status::REJECTED, Status::APPROVED))) {
             $isStatusLocked = true;
         }
     }
     return $isStatusLocked;
 }
Esempio n. 10
0
 /**
  * Set the status of the leave request, send an email about its summary and set the notification for it
  *
  * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $lr
  * @param \Opit\OpitHrm\UserBundle\Entity\Employee $employee
  * @param \Opit\OpitHrm\StatusBundle\Entity\Status $status
  * @param \Opit\OpitHrm\LeaveBundle\Model\LeaveRequestService $leaveRequestService
  */
 protected function setLRStatusSendNotificationEmail(LeaveRequest $lr, Employee $employee, Status $status, LeaveRequestService $leaveRequestService)
 {
     $this->get('opit.manager.leave_status_manager')->forceStatus($status->getId(), $lr);
     $leaveRequestService->prepareMassLREmail($lr, $employee->getUser()->getEmail(), array(), $status);
     // set a notification to the employee about the leave request
     $this->get('opit.manager.leave_notification_manager')->addNewLeaveNotification($lr, false, $status);
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  *
  * @param array $excludeIds
  *
  * @return array
  */
 public function getNextStates(Status $currentState, $excludeIds = array())
 {
     $statesToDisplay = array();
     $currentStateId = $currentState->getId();
     $nextStates = $this->entityManager->getRepository($this->getScope())->findAvailableStates($currentState, $excludeIds);
     $statesToDisplay[$currentStateId] = $currentState->getName();
     foreach ($nextStates as $nextState) {
         $status = $nextState->getStatus();
         $statesToDisplay[$status->getId()] = $status->getName();
     }
     return $statesToDisplay;
 }