Пример #1
0
 public function save(Request $request, $id)
 {
     // Validate form
     $this->validate($request, ['quote_request_items_id' => 'required'], $messages = array('quote_request_items_id.required' => 'You should choose a quantity to proceed with'));
     $input = Input::all();
     $job = Job::firstOrNew(['quote_requests_id' => $id]);
     $job->quote_requests_id = $id;
     $job->quote_request_items_id = $input['quote_request_items_id'];
     $job->save();
     // Update status
     $quote_request = QuoteRequest::find($id);
     $quote_request->status = 4;
     $quote_request->save();
     return redirect('job/' . $id . '/edit')->with('message', 'Job has been stored successfully');
 }
Пример #2
0
 private static function prepareJobRecord($data)
 {
     $currentRecord = [];
     // VALIDATE DATA
     if (empty($data->external_job_id)) {
         ExportRecordFailure::create(['job_info' => json_encode($data), 'reason' => '[ external_job_id is missing ]', 'action' => '[ exiting process ]', 'calling_function' => __FUNCTION__]);
         return null;
     }
     if (empty($data->job_title)) {
         ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ title is missing ]', 'action' => '[ exiting process ]', 'calling_function' => __FUNCTION__]);
         return null;
     }
     $end_date = null;
     if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})T.*\$/", $data->job_end_date, $end_date_matches)) {
         $end_date_mm = $end_date_matches[2];
         $end_date_dd = $end_date_matches[3];
         $end_date_yyyy = $end_date_matches[1];
         $end_date = $end_date_yyyy . '-' . $end_date_mm . "-" . $end_date_dd;
     }
     if (empty($end_date)) {
         ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ end date is missing ]', 'action' => '[ exiting process ]', 'calling_function' => __FUNCTION__]);
         return null;
     } else {
         $jobObj = Job::firstOrNew(['external_job_id' => $data->external_job_id, 'source_id' => 1]);
         if (strtotime($end_date) < strtotime(date('Y-m-d'))) {
             if (!empty($jobObj->id)) {
                 $record_id = $jobObj->id;
                 $jobObj->delete();
                 ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ expired job ]', 'action' => '[ record deleted ][ record id: ' . $record_id . ' ] [ exiting process ]', 'calling_function' => __FUNCTION__]);
                 return $record_id;
             } else {
                 ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ expired job ] ', 'action' => '[ will not create a record ] [ exiting process ]', 'calling_function' => __FUNCTION__]);
                 $jobObj = null;
                 return 1;
             }
         }
     }
     if (!empty($data->job_state) && $data->job_state == 'expired') {
         if (!empty($jobObj->id)) {
             $record_id = $jobObj->id;
             $jobObj->delete();
             ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ expired job ]', 'action' => '[ record deleted ][ record id: ' . $record_id . ' ] [ exiting process ]', 'calling_function' => __FUNCTION__]);
             return $record_id;
         } else {
             ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ expired job ] ', 'action' => '[ will not create a record ] [ exiting process ]', 'calling_function' => __FUNCTION__]);
             $jobObj = null;
             return 1;
         }
     }
     // END OF DATA VALIDATION
     if (!empty($jobObj->id)) {
         $currentRecord = Job::getInfo($jobObj->id, ['JobState', 'JobCity', 'JobCompany', 'JobCategory', 'JobIndustry']);
     }
     $jobObj->source_id = 1;
     $jobObj->external_job_id = $data->external_job_id;
     if (!empty($data->job_name)) {
         $jobObj->name = self::cleanUpStr($data->job_name);
     }
     if (!empty($data->job_title)) {
         $jobObj->title = self::cleanUpStr($data->job_title);
     }
     if (!empty($data->org_name)) {
         $company_name = trim(str_replace("&apos;", "'", $data->org_name));
     } else {
         $company_name = 'Confidential';
     }
     if (empty($currentRecord) || $currentRecord['JobCompany'] != $company_name) {
         $company_obj = Company::saveInstance(['name' => $company_name]);
         $jobObj->company_id = $company_obj->id;
     }
     $jobObj->apply_url = 'http://jobview.monster.com/getjob.aspx?jobid=' . $data->external_job_id;
     if ($company_name == 'Comcast Cable Communications Management, LLC') {
         if (!empty($data->apply_url)) {
             $jobObj->apply_url = $data->apply_url;
         }
     }
     if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})T.*\$/", $data->job_begin_date, $begin_date_matches)) {
         $begin_date_mm = $begin_date_matches[2];
         $begin_date_dd = $begin_date_matches[3];
         $begin_date_yyyy = $begin_date_matches[1];
         $jobObj->begin_date = $begin_date_yyyy . '-' . $begin_date_mm . '-' . $begin_date_dd;
     }
     $jobObj->end_date = $end_date;
     if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})T.*\$/", $data->job_post_date, $post_date_matches)) {
         $post_date_mm = $post_date_matches[2];
         $post_date_dd = $post_date_matches[3];
         $post_date_yyyy = $post_date_matches[1];
         $jobObj->post_date = $post_date_yyyy . '-' . $post_date_mm . '-' . $post_date_dd;
     }
     if (!empty($data->job_category)) {
         if (empty($currentRecord) || $currentRecord['JobCategory'] != $data->job_category) {
             $cat_obj = Category::firstOrCreate(['name' => $data->job_category]);
             $jobObj->category_id = $cat_obj->id;
         }
     }
     if (!empty($data->job_industries[0])) {
         if (empty($currentRecord) || $currentRecord['JobIndustry'] != $data->job_industries[0]) {
             $ind_obj = Industry::firstOrCreate(['name' => $data->job_industries[0]]);
             $jobObj->industry_id = $ind_obj->id;
         }
     }
     if (isset($data->location) && !empty($data->location)) {
         $location = $data->location;
         if (!empty(trim($location->city))) {
             $jobObj->city = trim($location->city);
         }
         if (!empty(trim($location->state))) {
             $jobObj->state = trim($location->state);
         }
         if (!empty(trim($location->country))) {
             $jobObj->country = trim($location->country);
         }
         if (isset($location->zip) && !empty(trim($location->zip))) {
             if (trim($location->zip) == '00000') {
                 $jobObj->zip = null;
             } else {
                 $jobObj->zip = trim($location->zip);
             }
         }
         if (!empty($jobObj->city) && !empty($jobObj->state)) {
             if (empty($currentRecord) || $currentRecord['JobCity'] != $jobObj->city || $currentRecord['JobState'] != $jobObj->state) {
                 $dma_obj = DmaMap::where(['city' => $jobObj->city, 'state_abbr' => $jobObj->state])->first();
                 if (!empty($dma_obj)) {
                     $jobObj->dma_code = $dma_obj->code;
                 }
             }
         }
     }
     return $jobObj;
 }