/** * * @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(); }
/** * 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(); }
/** * * @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(); }
/** * * @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(); }