/**
  * Test case for createEmployeeFromApplication
  */
 public function testCreateEmployeeFromApplication()
 {
     $jobApplication = JobApplication::getJobApplication(1);
     $empInfo = new EmpInfo();
     $before = $empInfo->countEmployee();
     $recController = new RecruitmentController();
     $empNum = $recController->createEmployeeFromApplication($jobApplication);
     $this->assertNotNull($empNum);
     // check employee count increased by 1
     $after = $empInfo->countEmployee();
     $this->assertEquals($before + 1, $after);
     // verify employee main details
     $empMain = $empInfo->filterEmpMain($empNum);
     $this->assertTrue(isset($empMain[0]));
     $this->assertEquals($empNum, $empMain[0][0]);
     $this->assertEquals($jobApplication->getLastName(), $empMain[0][1]);
     $this->assertEquals($jobApplication->getFirstName(), $empMain[0][2]);
     $this->assertEquals($jobApplication->getMiddleName(), $empMain[0][3]);
     // check that empId saved as well.
     $employeeId = str_pad($empNum, $empInfo->getEmployeeIdLength(), "0", STR_PAD_LEFT);
     $this->assertEquals($employeeId, $empMain[0][5]);
     // verify employee contact details
     $empContact = $empInfo->filterEmpContact($empNum);
     $this->assertTrue(isset($empContact[0]));
     $this->assertEquals($empNum, $empMain[0][0]);
     $this->assertEquals($jobApplication->getStreet1(), $empContact[0][1]);
     $this->assertEquals($jobApplication->getStreet2(), $empContact[0][2]);
     $this->assertEquals($jobApplication->getCity(), $empContact[0][3]);
     $this->assertEquals($jobApplication->getCountry(), $empContact[0][4]);
     $this->assertEquals($jobApplication->getProvince(), $empContact[0][5]);
     $this->assertEquals($jobApplication->getZip(), $empContact[0][6]);
     // Phone saved as home telephone
     $this->assertEquals($jobApplication->getPhone(), $empContact[0][7]);
     $this->assertEquals($jobApplication->getMobile(), $empContact[0][8]);
     // Email stored as other email.
     $this->assertEquals($jobApplication->getEmail(), $empContact[0][11]);
     // Job title
     $empJobInfo = $empInfo->filterEmpJobInfo($empNum);
     $this->assertTrue(isset($empJobInfo[0]));
     $this->assertEquals($empNum, $empJobInfo[0][0]);
     $vacancy = JobVacancy::getJobVacancy($jobApplication->getVacancyId());
     $this->assertEquals($vacancy->getJobTitleCode(), $empJobInfo[0][2]);
 }
 /**
  * Test method isAllowedToChangeEventStatus()
  */
 public function testIsAllowedToChangeEventStatus()
 {
     $authManager = new RecruitmentAuthManager();
     $app = JobApplication::getJobApplication(1);
     // Different users
     $admin = new authorize(null, authorize::YES);
     $hiring = new authorize('011', authorize::NO);
     $first = new authorize(13, authorize::NO);
     $second = new authorize(14, authorize::NO);
     $manager = new authorize(15, authorize::NO);
     $nonManager = new authorize(16, authorize::NO);
     // Admin, Hiring Manager and interviewer(owner) allowed to change status event when there are
     // no newer events.
     $app->setStatus(JobApplication::STATUS_FIRST_INTERVIEW_SCHEDULED);
     $app->save();
     $event = $app->getEventOfType(JobApplicationEvent::EVENT_SCHEDULE_FIRST_INTERVIEW);
     $this->assertTrue($authManager->isAllowedToChangeEventStatus($admin, $event));
     $this->assertTrue($authManager->isAllowedToChangeEventStatus($hiring, $event));
     $this->assertTrue($authManager->isAllowedToChangeEventStatus($first, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($second, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($manager, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($nonManager, $event));
     //Not allowed to change status when not current event.
     $app->setStatus(JobApplication::STATUS_SECOND_INTERVIEW_SCHEDULED);
     $app->save();
     $event = $app->getEventOfType(JobApplicationEvent::EVENT_SCHEDULE_FIRST_INTERVIEW);
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($admin, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($hiring, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($first, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($second, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($manager, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($nonManager, $event));
     //Not allowed to change status when not current event.
     $app->setStatus(JobApplication::STATUS_REJECTED);
     $app->save();
     $event = $app->getEventOfType(JobApplicationEvent::EVENT_SCHEDULE_SECOND_INTERVIEW);
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($admin, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($hiring, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($first, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($second, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($manager, $event));
     $this->assertFalse($authManager->isAllowedToChangeEventStatus($nonManager, $event));
 }
 /**
  * Test case for sendSeekApprovalToDirector().
  */
 public function testSendSeekApprovalToDirector()
 {
     $jobApplication = JobApplication::getJobApplication(2);
     $event = $jobApplication->getEventOfType(JobApplicationEvent::EVENT_SEEK_APPROVAL);
     $notifier = new RecruitmentMailNotifier();
     $mockMailer = new MockMailer();
     $notifier->setMailer($mockMailer);
     // Check successfull email
     $result = $notifier->sendSeekApprovalToDirector($jobApplication, $event);
     $this->assertTrue($result);
     $notifier->setMailer($mockMailer);
     $to = $mockMailer->getTo();
     $this->assertEquals(1, count($to));
     $this->assertEquals('*****@*****.**', $to[0]);
     $subject = $this->_getTemplateFile(RecruitmentMailNotifier::SUBJECT_SEEK_APPROVAL_DIRECTOR);
     $body = $this->_getTemplateFile(RecruitmentMailNotifier::TEMPLATE_SEEK_APPROVAL_DIRECTOR);
     $search = array(RecruitmentMailNotifier::VARIABLE_JOB_TITLE, RecruitmentMailNotifier::VARIABLE_TO, RecruitmentMailNotifier::VARIABLE_APPLICANT_FIRSTNAME, RecruitmentMailNotifier::VARIABLE_APPLICANT_MIDDLENAME, RecruitmentMailNotifier::VARIABLE_APPLICANT_LASTNAME, RecruitmentMailNotifier::VARIABLE_APPLICANT_STREET1, RecruitmentMailNotifier::VARIABLE_APPLICANT_STREET2, RecruitmentMailNotifier::VARIABLE_APPLICANT_CITY, RecruitmentMailNotifier::VARIABLE_APPLICANT_PROVINCE, RecruitmentMailNotifier::VARIABLE_APPLICANT_ZIP, RecruitmentMailNotifier::VARIABLE_APPLICANT_COUNTRY, RecruitmentMailNotifier::VARIABLE_APPLICANT_PHONE, RecruitmentMailNotifier::VARIABLE_APPLICANT_MOBILE, RecruitmentMailNotifier::VARIABLE_APPLICANT_EMAIL, RecruitmentMailNotifier::VARIABLE_APPLICANT_QUALIFICATIONS, RecruitmentMailNotifier::VARIABLE_SEEK_NOTES, RecruitmentMailNotifier::VARIABLE_FROM);
     $replace = array('Driver', 'John', $jobApplication->getFirstName(), $jobApplication->getMiddleName(), $jobApplication->getLastName(), $jobApplication->getStreet1(), $jobApplication->getStreet2(), $jobApplication->getCity(), $jobApplication->getProvince(), $jobApplication->getZip(), 'England', $jobApplication->getPhone(), $jobApplication->getMobile(), $jobApplication->getEmail(), $jobApplication->getQualifications(), $event->getNotes(), 'Saman Rajasinghe');
     $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
     $this->_runQuery("UPDATE hs_hr_employee SET emp_work_email=NULL where emp_number = 13");
     $mockMailer = new MockMailer();
     $notifier->setMailer($mockMailer);
     $result = $notifier->sendSeekApprovalToDirector($jobApplication, $event);
     $this->assertFalse($result);
 }
 private function _approve($event)
 {
     if ($this->authorizeObj->isAdmin() || $this->authorizeObj->isDirector() || $this->authorizeObj->isAcceptor()) {
         // TODO: Validate if Hiring manager or interview manager and in correct status
         $application = JobApplication::getJobApplication($event->getApplicationId());
         $application->setStatus(JobApplication::STATUS_HIRED);
         try {
             $application->save();
             $this->_saveApplicationEvent($event, JobApplicationEvent::EVENT_APPROVE);
             // Create employee in PIM
             $empId = $this->createEmployeeFromApplication($application);
             // Save new employee number in application for reference.
             $application->setEmpNumber($empId);
             $application->save();
             // Send email informing approval to hiring manager
             $notifier = new RecruitmentMailNotifier();
             $mailResult = $notifier->sendApprovalToHiringManager($application, $event);
             $message = 'UPDATE_SUCCESS';
         } catch (Exception $e) {
             $message = 'UPDATE_FAILURE';
         }
         $this->redirect($message, '?recruitcode=Application&action=List');
         //$this->_viewApplicationList();
     } else {
         $this->_notAuthorized();
     }
 }
 /**
  * Send a task to the interviewing manager, giving details of scheduled interview
  *
  * @param JobApplicationEvent $jobApplicationEvent Job Application Event object
  *
  * @return boolean True if mail sent, false otherwise
  */
 public function sendInterviewTaskToManager($jobApplicationEvent)
 {
     /* Get interview details */
     $intManagerId = $jobApplicationEvent->getOwner();
     if (empty($intManagerId)) {
         throw new RecruitmentMailNotifierException("Invalid parameters", RecruitmentMailNotifierException::INVALID_PARAMETER);
     }
     $intManagerEmail = $this->_getEmpAddress($intManagerId);
     if (empty($intManagerEmail)) {
         $this->_log("Interviewing manager {$intManagerId} does not have email address.");
         return false;
     }
     $intManagerName = $this->_getEmpName($intManagerId);
     $jobApplication = JobApplication::getJobApplication($jobApplicationEvent->getApplicationId());
     $applicantName = $jobApplication->getFirstName() . ' ' . $jobApplication->getLastName();
     $applicantEmail = $jobApplication->getEmail();
     $creatorName = $jobApplicationEvent->getCreatorName();
     $creatorEmail = $jobApplicationEvent->getCreatorEmail();
     $interviewTime = $jobApplicationEvent->getEventTime();
     $vacancy = JobVacancy::getJobVacancy($jobApplication->getVacancyId());
     /* Get summary and description from templates */
     $subject = $this->_getTemplate(self::SUBJECT_INTERVIEW_MANAGER_TASK);
     $body = $this->_getTemplate(self::TEMPLATE_INTERVIEW_MANAGER_TASK);
     // Replace placeholders in subject and body
     $search = array(self::VARIABLE_JOB_TITLE, self::VARIABLE_TO, self::VARIABLE_APPLICANT_FIRSTNAME, self::VARIABLE_APPLICANT_MIDDLENAME, self::VARIABLE_APPLICANT_LASTNAME, self::VARIABLE_APPLICANT_STREET1, self::VARIABLE_APPLICANT_STREET2, self::VARIABLE_APPLICANT_CITY, self::VARIABLE_APPLICANT_PROVINCE, self::VARIABLE_APPLICANT_ZIP, self::VARIABLE_APPLICANT_COUNTRY, self::VARIABLE_APPLICANT_PHONE, self::VARIABLE_APPLICANT_MOBILE, self::VARIABLE_APPLICANT_EMAIL, self::VARIABLE_APPLICANT_QUALIFICATIONS, self::VARIABLE_INTERVIEW_NOTES);
     $country = $this->_getCountryName($jobApplication->getCountry());
     $replace = array($vacancy->getJobTitleName(), $intManagerName['first'], $jobApplication->getFirstName(), $jobApplication->getMiddleName(), $jobApplication->getLastName(), $jobApplication->getStreet1(), $jobApplication->getStreet2(), $jobApplication->getCity(), $jobApplication->getProvince(), $jobApplication->getZip(), $country, $jobApplication->getPhone(), $jobApplication->getMobile(), $jobApplication->getEmail(), $jobApplication->getQualifications(), $jobApplicationEvent->getNotes());
     $summary = str_replace($search, $replace, $subject);
     $description = str_replace($search, $replace, $body);
     /* Create task */
     $message = $this->_getTask($summary, $description, $creatorName, $creatorEmail, $applicantName, $applicantEmail, $interviewTime);
     $mailer = $this->_getMailer();
     $attachment = $mailer->createAttachment($message);
     $attachment->type = 'text/calendar';
     $attachment->filename = 'interview.ics';
     /* Send Email with task attached */
     $to = "{$intManagerName['first']} {$intManagerName['last']}<{$intManagerEmail}>";
     $body = '';
     $notificationType = null;
     $attachments = array($attachment);
     $subject = $summary;
     $this->_sendMail($to, $subject, $body, $notificationType, $attachments);
 }
 /**
  * Checks if the given user is allowed to change the status of the given event
  *
  * @param authorize $authObj authorize class representing logged in user
  * @param JobApplicationEvent Job Application Event which needs to be edited
  *
  * @return bool True if action is allowed, false otherwise.
  */
 public function isAllowedToChangeEventStatus($authObj, $jobApplicationEvent)
 {
     if (!$this->isAllowedToEditEvent($authObj, $jobApplicationEvent)) {
         return false;
     }
     $application = JobApplication::getJobApplication($jobApplicationEvent->getApplicationId());
     $status = $application->getStatus();
     $eventType = $jobApplicationEvent->getEventType();
     switch ($eventType) {
         case JobApplicationEvent::EVENT_SCHEDULE_FIRST_INTERVIEW:
             return $status == JobApplication::STATUS_FIRST_INTERVIEW_SCHEDULED;
             break;
         case JobApplicationEvent::EVENT_SCHEDULE_SECOND_INTERVIEW:
             return $status == JobApplication::STATUS_SECOND_INTERVIEW_SCHEDULED;
             break;
         default:
             return false;
     }
 }