/**
  * Handle job application by applicant
  */
 public function applyForJob()
 {
     $extractor = new EXTRACTOR_JobApplication();
     $jobApplication = $extractor->parseData($_POST);
     try {
         $jobApplication->save();
         $result = true;
     } catch (JobApplicationException $e) {
         $result = false;
     }
     // Send mail notifications
     $notifier = new RecruitmentMailNotifier();
     $notifier->sendApplicationReceivedEmailToManager($jobApplication);
     // We only need to display result of email sent to applicant
     $mailResult = $notifier->sendApplicationReceivedEmailToApplicant($jobApplication);
     $path = '/templates/recruitment/applicant/jobApplicationStatus.php';
     $objs['application'] = $jobApplication;
     $objs['vacancy'] = JobVacancy::getJobVacancy($jobApplication->getVacancyId());
     $objs['result'] = $result;
     $objs['mailResult'] = $mailResult;
     $template = new TemplateMerger($objs, $path);
     $template->display();
 }
 /**
  * Test case for sendApplicationReceivedEmailToApplicant().
  */
 public function testSendApplicationReceivedEmailToApplicant()
 {
     $jobApplication = $this->jobApplications[1];
     $notifier = new RecruitmentMailNotifier();
     $mockMailer = new MockMailer();
     $notifier->setMailer($mockMailer);
     // Check successfull email
     $result = $notifier->sendApplicationReceivedEmailToApplicant($jobApplication);
     $this->assertTrue($result);
     $to = $mockMailer->getTo();
     $this->assertEquals(1, count($to));
     $this->assertEquals('*****@*****.**', $to[0]);
     $subject = $this->_getTemplateFile(RecruitmentMailNotifier::SUBJECT_RECEIVED_APPLICANT);
     $body = $this->_getTemplateFile(RecruitmentMailNotifier::TEMPLATE_RECEIVED_APPLICANT);
     $search = array(RecruitmentMailNotifier::VARIABLE_JOB_TITLE, RecruitmentMailNotifier::VARIABLE_TO);
     $replace = array('Manager', 'Janaka Kulathunga');
     $body = str_replace($search, $replace, $body);
     $subject = str_replace($search, $replace, $subject);
     $subject = str_replace(array("\r", "\n"), array("", ""), $subject);
     $this->assertEquals($subject, $mockMailer->getSubject());
     $this->assertEquals($body, $mockMailer->getBodyText());
     // without to email address - should fail
     $jobApplication->setEmail(null);
     $mockMailer = new MockMailer();
     $notifier->setMailer($mockMailer);
     $result = $notifier->sendApplicationReceivedEmailToApplicant($jobApplication);
     $this->assertFalse($result);
 }
 /**
  * Handle job application by applicant
  */
 public function applyForJob()
 {
     $extractor = new EXTRACTOR_JobApplication();
     $jobApplication = $extractor->parseData($_POST);
     $objs['error']['resumeUploadError'] = '';
     $objs['error']['resumeCompatibleError'] = '';
     $objs['error']['applicantEmailError'] = '';
     $objs['savingStatus'] = null;
     $correctResume = null;
     /* Handling uploaded resume */
     if (!empty($jobApplication->resumeData['error'])) {
         // If there was an error in upload, don't execute the rest
         $correctResume = false;
         $objs['error']['resumeUploadError'] = $jobApplication->resumeData['error'];
         $extractor->saveToSession($_POST);
     } else {
         // This means resume has either successfully uploaded or no resume has been uploaded
         if ($jobApplication->resumeData['size'] > 0) {
             // If a resume has been uploaded
             if ($jobApplication->isResumeCompatible()) {
                 $correctResume = true;
             } else {
                 $correctResume = false;
                 $objs['error']['resumeCompatibleError'] = $jobApplication->resumeData['error'];
                 // isResumeCompatible() sets this error
                 $extractor->saveToSession($_POST);
             }
         }
     }
     /* Saving job application */
     if (is_null($correctResume) || $correctResume) {
         // Try saving only if resume is compatible or no resume has been uploaded
         try {
             $jobApplication->save();
             // Throws exceptions on failiures
             $extractor->removeFromSession();
             /* Send mail notifications */
             $notifier = new RecruitmentMailNotifier();
             $notifier->sendApplicationReceivedEmailToManager($jobApplication);
             if (!$notifier->sendApplicationReceivedEmailToApplicant($jobApplication)) {
                 $objs['error']['applicantEmailError'] = 'Emailing applicant failed';
             }
             $objs['savingStatus'] = true;
         } catch (JobApplicationException $e) {
             $objs['savingStatus'] = false;
             $extractor->saveToSession($_POST);
         }
     }
     $path = '/templates/recruitment/applicant/jobApplicationStatus.php';
     $objs['application'] = $jobApplication;
     $objs['vacancy'] = JobVacancy::getJobVacancy($jobApplication->getVacancyId());
     $template = new TemplateMerger($objs, $path);
     $template->display();
 }