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