public function upload(Request $request)
 {
     $entityBody = file_get_contents('php://input');
     Log::debug($entityBody);
     $formController = new \Stratum\Controller\FormController();
     Log::debug("parsing input data");
     $formResult = $formController->parse($entityBody);
     Log::Debug("parsed input data");
     //form has updated mappings for each question
     $candidate = new \Stratum\Model\Candidate();
     $candidateController = new \Stratum\Controller\CandidateController();
     $candidate = $candidateController->populate($candidate, $formResult);
     Log::debug("Form Completed for " . $candidate->getName());
     $controller = new \Stratum\Controller\BullhornController();
     //upload files from WorldApp to Bullhorn
     $controller->submit_files($candidate);
     //update availability Note in Bullhorn
     $availability = $formResult->findByWorldApp("Call Availability");
     Log::debug($availability);
     if ($availability) {
         $note['comments'] = "Call Availability: " . $availability['Call Availability']['value'];
         $note['action'] = 'Availability';
         Log::debug($note);
         $candidate->set("Note", $note);
         $controller->submit_note($candidate);
     }
     $cc = new CanCon();
     $c3 = $cc->load($candidate->get("id"));
     //Bullhorn Candidate record, from cache if available
     $owner = $c3->get("owner");
     /*
     array (
       'id' => 10237,
       'firstName' => 'Stratum',
       'lastName' => 'API',
     )
     */
     $cuser = new \Stratum\Model\CorporateUser();
     $cuser->set("id", $owner['id']);
     $cuser = $controller->loadCorporateUser($cuser);
     $to_email = $cuser->get("email");
     if (!$to_email) {
         $to_email = "*****@*****.**";
     }
     Log::debug("sending email to " . $cuser->getName() . " at " . $to_email . " about Form Submission");
     $maildata['candidateName'] = $candidate->getName();
     $maildata['candidateID'] = $candidate->get("id");
     $maildata['date'] = date(DATE_RFC2822);
     Mail::send('email.form_uploaded', $maildata, function ($m) use($to_email, $candidate) {
         $m->from('*****@*****.**', 'Plum Data Integration Service');
         $m->to($to_email)->subject('Form Submission from ' . $candidate->getName() . ' ' . $candidate->get("id"));
     });
     $controller->updateCandidateStatus($candidate, "Form Completed");
     //Now to store form results in local storage
     $entityBody = Storage::disk('local')->put($candidate->get("id") . ".txt", $entityBody);
 }
 private function loadCorporateUser()
 {
     $user = Auth::user();
     $id = $user->bullhorn_id;
     Log::debug("User has ID " . $id);
     $cuser = null;
     if (!$id) {
         //load by name
         $name = $user->name;
         Log::debug("User has name " . $name);
         $bc = new BullhornController();
         $cuser = $bc->findCorporateUserByName($name);
         $theId = $cuser->get("id");
         if ($theId) {
             $user->bullhorn_id = $theId;
             $user->save();
         }
     } else {
         //we have a bullhorn id
         $cuser = null;
         if (Cache::has("user" . $id)) {
             Log::debug("Loading corporate user from cache: " . $id);
             $cuser = Cache::get("user" . $id);
         } else {
             //load the corporate user data from Bullhorn
             $cuser = new \Stratum\Model\CorporateUser();
             $cuser->set("id", $id);
             $bc = new BullhornController();
             $cuser = $bc->loadCorporateUser($cuser);
         }
     }
     return $cuser;
 }
 public function findAssocCandidates(\Stratum\Model\CorporateUser $cuser)
 {
     $bullhornClient = $this->getClient();
     $id = $cuser->get("id");
     if (!$id) {
         return null;
     }
     $candidates = $bullhornClient->findAssocCandidatesIndexed($cuser);
     if ($candidates == null) {
         //error condition according to Stratum
     }
     return $candidates;
 }