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