Beispiel #1
0
 public function applyAction()
 {
     /** @var Request $request */
     $request = $this->getRequest();
     $result = ['status' => 'error', 'msg' => 'Unable to save application. Please try again later.'];
     try {
         if ($request->isPost() && $request->isXmlHttpRequest()) {
             /** @var \DDD\Service\Website\Job $jobService */
             $jobService = $this->getServiceLocator()->get('service_website_job');
             $form = new JobsForm('announcement-form');
             $inputs = $request->getPost()->toArray();
             $validateTags = ClassicValidator::checkScriptTags($inputs);
             if (!$validateTags) {
                 return new JsonModel(['status' => 'error', 'msg' => 'Unable to save application. Please try again later.']);
             }
             $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
             $form->setInputFilter(new JobsFilter());
             $form->setData($post);
             if ($form->isValid()) {
                 $data = $form->getData();
                 $filesObj = new Files($request->getFiles()->toArray());
                 $acceptedFileTypes = ['pdf', 'doc', 'docx', 'odt', 'rtf'];
                 $filenames = $filesObj->saveFiles('/ginosi/uploads/hr/applicants/' . date('Y/m/'), $acceptedFileTypes, false, true);
                 if ($filenames['cv']) {
                     $data['cv'] = $filenames['cv'];
                 } else {
                     unset($data['cv']);
                 }
                 $data['date_applied'] = date('Y-m-d H:i:s');
                 $applicantId = $jobService->saveApplicant($data);
                 if ($applicantId) {
                     /** @var \DDD\Dao\Recruitment\Job\Job $jobDao */
                     $jobDao = $this->getServiceLocator()->get('dao_recruitment_job_job');
                     /** @var \DDD\Domain\Recruitment\Job\Job $jobInfo */
                     $jobInfo = $jobDao->fetchOne(['id' => $data['job_id']]);
                     $hiringManager = $jobInfo->getHiringManagerId();
                     if ($jobInfo && $jobInfo->getNotifyManager() && $hiringManager && !is_null($hiringManager)) {
                         $notificationService = $this->getServiceLocator()->get('service_notifications');
                         $sender = NotificationService::$applicants;
                         $message = 'You have a new applicant for ' . $jobInfo->getTitle() . ' position - ' . $data['firstname'] . ' ' . $data['lastname'] . '. Applied on ' . date(Constants::GLOBAL_DATE_FORMAT . ' H:i', strtotime($data['date_applied']));
                         $url = '/recruitment/applicants/edit/' . $applicantId;
                         $notificationData = ['recipient' => $hiringManager, 'sender' => $sender, 'sender_id' => User::SYSTEM_USER_ID, 'message' => $message, 'url' => $url, 'show_date' => date('Y-m-d')];
                         $notificationService->createNotification($notificationData);
                     }
                 }
                 $result = ['status' => 'success', 'msg' => 'Application saved'];
             }
         }
     } catch (\Exception $ex) {
         $this->gr2logException($ex, 'Website: Job application saving process failed');
     }
     return new JsonModel($result);
 }
Beispiel #2
0
 public function ajaxUploadCvAction()
 {
     $applicantDao = $this->getServiceLocator()->get('dao_recruitment_applicant_applicant');
     $applicantService = $this->getServiceLocator()->get('service_recruitment_applicant');
     $request = $this->getRequest();
     $result = ['status' => 'error', 'msg' => TextConstants::SERVER_ERROR];
     try {
         if ($request->isPost() && $request->isXmlHttpRequest()) {
             $data = $request->getPost();
             $fileInfo = $request->getFiles()->toArray();
             $filename = $fileInfo['cv']['name'];
             $applicantInfo = $applicantDao->fetchOne(['id' => $data['id']]);
             $filesObj = new Files($fileInfo);
             $fileType = $filesObj->getFileType($filename);
             $acceptedFileTypes = ['pdf', 'doc', 'docx', 'odt', 'rtf'];
             $cvName = null;
             if (!in_array($fileType, $acceptedFileTypes)) {
                 $result = ['status' => 'error', 'msg' => TextConstants::FILE_TYPE_NOT_TRUE];
             } else {
                 $savedFile = $filesObj->saveFiles(DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_HR_APPLICANT_DOCUMENTS . date('Y/m/', strtotime($applicantInfo->getDateApplied())), $acceptedFileTypes, false, true);
                 if ($savedFile['cv']) {
                     $cvName = $savedFile['cv'];
                 }
                 if (!is_null($cvName)) {
                     $preApplicantInfo = $applicantService->getApplicantById($data['id']);
                     if ($preApplicantInfo->getCvFileName()) {
                         $filePath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_HR_APPLICANT_DOCUMENTS . $preApplicantInfo->getCvFileUrl();
                         if (is_readable($filePath)) {
                             @unlink($filePath);
                         }
                     }
                     $applicantDao->save(['cv' => $cvName], ['id' => $data['id']]);
                     $result = ['status' => 'success', 'msg' => TextConstants::SUCCESS_UPDATE];
                     Helper::setFlashMessage(['success' => TextConstants::SUCCESS_UPDATE]);
                 }
             }
         }
     } catch (\Exception $e) {
         // do nothing
     }
     return new JsonModel($result);
 }