コード例 #1
0
ファイル: Monster.php プロジェクト: lucy-udalykh/samples
 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;
 }
コード例 #2
0
 public function updateCompanyProfile(Request $request)
 {
     $input = $request->all();
     // remove all fields that we are not updatable
     $exclude = ['is_active', 'created_at', 'total_jobs', 'updated_at', 'keywords_processed'];
     $str_id = $input['data']['str_id'];
     foreach ($exclude as $field) {
         unset($input['data'][$field]);
     }
     $profile_changes = $input['data'];
     //we need to reprocess images
     if (!empty($profile_changes['new_img'])) {
         $s3_folder = 'company';
         //update logo
         if (!empty($profile_changes['new_img']['logo']['file'])) {
             // process logo image
             $file = $profile_changes['new_img']['logo']['file'];
             $file_name = $profile_changes['new_img']['logo']['fileName'];
             $ext = pathinfo($file_name, PATHINFO_EXTENSION);
             $new_file_name = $str_id . '.' . $ext;
             $img_url = uploadOnS3($s3_folder, $file, $new_file_name);
             $profile_changes['img_url'] = $img_url['url'];
             unset($profile_changes['new_img']['logo']['file']);
             unset($profile_changes['new_img']['logo']['fileName']);
             unset($profile_changes['new_img']['logo']);
         }
         //update background
         if (!empty($profile_changes['new_img']['background']['file'])) {
             // process  image
             $file = $profile_changes['new_img']['background']['file'];
             $file_name = $profile_changes['new_img']['background']['fileName'];
             $ext = pathinfo($file_name, PATHINFO_EXTENSION);
             $new_file_name = $str_id . '-bkgr.' . $ext;
             $img_url = uploadOnS3($s3_folder, $file, $new_file_name);
             $profile_changes['background_url'] = $img_url['url'];
             unset($profile_changes['new_img']['background']['file']);
             unset($profile_changes['new_img']['background']['fileName']);
             unset($profile_changes['new_img']['background']);
         }
         if (empty($profile_changes['new_img'])) {
             unset($profile_changes['new_img']);
         }
     }
     // process demographics
     $dm = $profile_changes['demographics'];
     if (!empty($dm)) {
         if (!empty($dm['ethnicity'])) {
             $ethnicity_list = [];
             arsort($dm['ethnicity']);
             foreach ($dm['ethnicity'] as $k => $v) {
                 if (!empty($v)) {
                     $ethnicity_list[$k] = $v;
                 } else {
                     unset($profile_changes['demographics']['ethnicity'][$k]);
                 }
             }
             if (!empty($ethnicity_list)) {
                 $profile_changes['demographics']['ethnicity'] = $ethnicity_list;
             } else {
                 unset($profile_changes['demographics']['ethnicity']);
             }
         }
         if (!empty($dm['gender'])) {
             $gender_list = [];
             arsort($dm['gender']);
             foreach ($dm['gender'] as $k => $v) {
                 if (!empty($v)) {
                     $gender_list[$k] = $v;
                 } else {
                     unset($profile_changes['demographics']['gender'][$k]);
                 }
             }
             if (!empty($gender_list)) {
                 $profile_changes['demographics']['gender'] = $gender_list;
             } else {
                 unset($profile_changes['demographics']['gender']);
             }
         }
         if (empty($profile_changes['demographics'])) {
             $profile_changes['demographics'] = null;
         } else {
             $profile_changes['demographics'] = $profile_changes['demographics'];
         }
     }
     \App\Company::saveInstance($profile_changes);
     return 'true';
 }