Example #1
0
 /**
  * Sends the Notification Mail.
  *
  * @param ApplicationEvent $event
  */
 public function sendMail(ApplicationEvent $event)
 {
     if (!$event->isPostRequest()) {
         return;
     }
     $this->application = $event->getApplicationEntity();
     $status = $event->getStatus();
     $user = $event->getUser();
     $post = $event->getPostData();
     $settings = $user->getSettings('Applications');
     $recipient = $this->getRecipient($this->application, $status);
     /* @var \Applications\Mail\StatusChange $mail */
     $mail = $this->mailService->get('Applications/StatusChange');
     $mail->setSubject($post['mailSubject']);
     $mail->setBody($post['mailText']);
     $mail->setTo($recipient);
     if ($from = $this->application->getJob()->getContactEmail()) {
         $mail->setFrom($from, $this->application->getJob()->getCompany());
     }
     if ($settings->mailBCC) {
         $mail->addBcc($user->getInfo()->getEmail(), $user->getInfo()->getDisplayName());
     }
     $job = $this->application->getJob();
     $jobUser = $job->getUser();
     if ($jobUser->getId() != $user->getId()) {
         $jobUserSettings = $jobUser->getSettings('Applications');
         if ($jobUserSettings->getMailBCC()) {
             $mail->addBcc($jobUser->getInfo()->getEmail(), $jobUser->getInfo()->getDisplayName(false));
         }
     }
     $org = $job->getOrganization()->getParent(true);
     $orgUser = $org->getUser();
     if ($orgUser->getId() != $user->getId() && $orgUser->getId() != $jobUser->getId()) {
         $orgUserSettings = $orgUser->getSettings('Applications');
         if ($orgUserSettings->getMailBCC()) {
             $mail->addBcc($orgUser->getInfo()->getEmail(), $orgUser->getInfo()->getDisplayName(false));
         }
     }
     $this->mailService->send($mail);
     $historyText = sprintf($this->translator->translate('Mail was sent to %s'), key($recipient) ?: $recipient[0]);
     $this->application->changeStatus($status, $historyText);
     $event->setNotification($historyText);
 }
 protected function sendRecruiterMails()
 {
     /* @var Settings $adminSettings */
     $job = $this->application->getJob();
     $org = $job->getOrganization()->getParent(true);
     $workflow = $org->getWorkflowSettings();
     $admin = $org->getUser();
     $adminSettings = $admin->getSettings('Applications');
     $mailBcc = $adminSettings->getMailBCC();
     if ($workflow->getAcceptApplicationByDepartmentManager()) {
         /* Send mail to department manager, if there is at least one. */
         $managers = $org->getEmployeesByRole(EmployeeInterface::ROLE_DEPARTMENT_MANAGER);
         if (count($managers)) {
             foreach ($managers as $employee) {
                 /* @var EmployeeInterface $employee */
                 $this->mailService->send('Applications/NewApplication', ['job' => $job, 'user' => $employee->getUser(), 'bcc' => $adminSettings->getMailBCC() ? [$admin] : null]);
             }
             return;
         }
     }
     $recruiter = $job->getUser();
     /* @var \Applications\Entity\Settings $settings */
     $settings = $recruiter->getSettings('Applications');
     if ($settings->getMailAccess()) {
         $this->mailService->send('Applications/NewApplication', ['job' => $this->application->getJob(), 'user' => $recruiter, 'bcc' => $adminSettings->getMailBCC() ? [$admin] : null]);
     }
     if ($settings->getAutoConfirmMail()) {
         $ackBody = $settings->getMailConfirmationText();
         if (empty($ackBody)) {
             $ackBody = $settings->getMailConfirmationText();
         }
         if (!empty($ackBody)) {
             /* confirmation mail to the applicant */
             $ackMail = $this->mailService->get('Applications/Confirmation', ['application' => $this->application, 'body' => $ackBody, 'bcc' => $adminSettings->getMailBCC() ? [$admin] : null]);
             // Must be called after initializers in creation
             $ackMail->setSubject('Application confirmation');
             $ackMail->setFrom($recruiter->getInfo()->getEmail(), $recruiter->getInfo()->getDisplayName(false));
             $this->mailService->send($ackMail);
             $this->application->changeStatus(StatusInterface::CONFIRMED, sprintf('Mail was sent to %s', $this->application->getContact()->getEmail()));
         }
     }
 }