예제 #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);
 }
예제 #2
0
 public function ajaxSearchAction()
 {
     /**
      * @var Request $request
      * @var Search $searchService
      */
     $request = $this->getRequest();
     $result = ['status' => 'success', 'result' => '', 'totalPages' => 1];
     try {
         if ($request->isXmlHttpRequest()) {
             $data = $request->getQuery()->toArray();
             $validateTags = ClassicValidator::checkScriptTags($data);
             if (!$validateTags) {
                 return new JsonModel(['status' => 'error', 'msg' => TextConstants::ERROR]);
             }
             array_walk($data, 'strip_tags');
             $searchService = $this->getSearchService();
             $searchResponse = $searchService->searchApartmentList($data);
             $hasDate = true;
             if ($searchResponse['status'] != 'success') {
                 $result['status'] = 'error';
                 $result['result'] = $searchResponse['msg'];
             } else {
                 if (empty($data['arrival']) && empty($data['departure'])) {
                     $hasDate = false;
                 }
                 $apartelList = $searchResponse['apartelList'];
                 $visitorLoc = $searchResponse['visitorLoc'];
                 $totalPages = $searchResponse['totalPages'];
                 $partial = $this->getServiceLocator()->get('viewhelpermanager')->get('partial');
                 $response = $partial('partial/search.phtml', ['apartelList' => $apartelList, 'options' => $searchResponse['options'], 'visitorLoc' => $visitorLoc, 'hasPagination' => true, 'sl' => $this->getServiceLocator(), 'hasDate' => $hasDate]);
                 $result['result'] = $response;
                 $result['totalPages'] = $totalPages;
                 $result['paginatinView'] = $searchResponse['paginatinView'];
             }
         }
     } catch (\Exception $e) {
         $result['status'] = 'error';
         $result['result'] = TextConstants::ERROR . $e->getMessage();
     }
     return new JsonModel($result);
 }