Skip to content

Instantly share code, notes, and snippets.

@nathanaelphilip
Created November 26, 2019 01:07
Show Gist options
  • Save nathanaelphilip/bd020635589d6df233ded30bcf1c0b17 to your computer and use it in GitHub Desktop.
Save nathanaelphilip/bd020635589d6df233ded30bcf1c0b17 to your computer and use it in GitHub Desktop.
<?php
$api = new API;
$data = $_POST['data'];
$query = '&count=3&query=firstName:"'. $data['first_name'] .'" AND lastName:"'. $data['last_name'] .'"AND email:"'. $data['email'] .'"&fields=id,firstName,lastName,email';
$candidates = $api->get('search/Candidate', $query);
if (empty($candidates)) {
$dataCandidate = [
'name' => $data['first_name'] . ' ' . $data['last_name'],
'firstName' => $data['first_name'],
'lastName' => $data['last_name'],
'email' => $data['email'],
'mobile' => $data['phone'],
'source' => 'Website (Delta)',
'customTextBlock2' => 'Website (Delta) - '. strtoupper($data['bu']) .' Website'
];
$candidate = $api->put('entity/Candidate', $dataCandidate);
}
if (!empty($candidates)) {
$candidate = $candidates[0];
}
$candidate_id = isset($candidate->changedEntityId) ? $candidate->changedEntityId : $candidate->id;
// 1. Get the Job Title
// 2. Compare that Title to the array of Skills
// 3. Return the ID of that skill
// 4. Assign that Skill to the Candidate
$skills = get_transient('bullhorn_skills');
if (!$skills) {
$skills = $api->get('options/Skill', '&fields=*&count=300&start=0');
set_transient('bullhorn_skills', $skills, HOUR_IN_SECONDS * 24);
}
foreach ($skills as $skill) {
if ($skill->label === $data['job_title']) {
$match = $skill;
}
}
if (isset($match) && !empty($match) && $candidate_id) {
$primarySkills = $api->put('entity/Candidate/'. $candidate_id .'/primarySkills/' . $match->value, []);
}
$submission = $api->put('entity/JobSubmission', [
'candidate' => ['id' => $candidate_id],
'jobOrder' => ['id' => $data['job_id']],
'status' => 'New Lead',
'dateWebResponse' => time()*1000
]);
if ($_FILES['resume'] && $candidate && $candidate_id) {
$file = $_FILES['resume'];
$filedata = [
'externalID' => $file['name'],
'fileContent' => base64_encode(file_get_contents($file['tmp_name'])),
'fileType' => 'SAMPLE',
'name' => $file['name']
];
$upload = $api->put('file/Candidate/' . $candidate_id, $filedata);
}
// Email to Applicant
$toApplicant = $this->send_email($data['email'], 'Application Received', $_POST['message']);
// Email to Recruiter 'pdept@thedeltacompanies.com'
$toRecruiter = $this->send_email($data['recruiter'], 'Application Created', 'A new provider application for '. $data['job_id'] .' has been submitted for review.');
wp_send_json([
'candidates' => $candidates,
'candidate' => $candidate->data ? $candidate->data : $candidate,
'submission' => $submission->data,
'primarySkills' => $primarySkills,
'specialties' => $specialties,
'upload' => $upload,
'status' => 'success',
'toApplicant' => $toApplicant,
'toRecruiter' => $toRecruiter
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment