db->prepare($sql); $result = $stmt->execute(["id" => $apply_id]); if($result) { return new UserApplyTmpEntity($stmt->fetch()); } } protected function _valid_save_update($application){ #if(isset($_GET['debug'])){ echo'
';var_dump($application);exit; }
// valid start
$ary_fields_which_are_varchar_and_inputed_by_user = array(
'name'=>['姓名',$application->getName()],
'gender'=>['性別',$application->getGender()],
'email'=>['信箱',$application->getEmail()],
'second_email'=>['第2信箱',$application->getSecondEmail()],
'phone'=>['電話',$application->getPhone()],
'second_phone'=>['手機',$application->getSecondPhone()],
'latest_company'=>['目前或最後一間公司名稱',$application->get_latest_company()],
'latest_job_title'=>['目前或最後一份工作職稱',$application->get_latest_job_title()],
'gradute_school'=>['畢業學校',$application->get_gradute_school()],
'gradute_master'=>['畢業科系',$application->get_gradute_master()],
'skill'=>['專業技能',$application->get_skill()],
'knowhow'=>['專業領域',$application->get_knowhow()],
'graduate_year'=>['畢業年份',$application->get_graduate_year()],
'age_year'=>['出生年份',$application->get_age_year()],
);
parent::_valid_save_update_base(self::TBL, $ary_fields_which_are_varchar_and_inputed_by_user);
// valid end
}
public function new_apply(UserEntity $application) {
# 20190904 here mihgt not need this line & what's the diff about `new_apply(` and `save(` function? $this->_valid_save_update($application);
$sql = "insert into users_application
(email,name,gender,second_email,second_phone,phone,english_ability_id, highest_education_id,graduate_year,age_year) values
(:email,:name,:gender,:second_email,:second_phone,:phone,:english_ability_id, :highest_education_id,:graduate_year,:age_year)";
$stmt = $this->db->prepare($sql);
$result = $stmt->execute([
"email"=> $application->getEmail(),
"name"=>$application->getName(),
"gender"=>'',#$application->getGender(),
"second_email"=>'',#$application->getSecondEmail(),
"second_phone"=>'',#$application->getSecondPhone(),
"phone"=>$application->getPhone(),
"english_ability_id" => 0,
"highest_education_id" => 0,
"graduate_year" => 0,
"age_year" => 0
]);
if(!$result) {
throw new Exception("could not new record");
}else{
$id = $this->db->lastInsertId();
return array('success'=>'成功新增履歷','id'=>$id);
}
}
public function save(UserApplyTmpEntity $application) {
$this->_valid_save_update($application);
$sql = "insert into users_application
(name,gender,second_email,second_phone, email, phone, latest_company, latest_job_title, gradute_school, gradute_master, skill, knowhow, experience, english_ability_id, other,highest_education_id,graduate_year,age_year,cv_path) values
(:name,:gender,:second_email,:second_phone, :email, :phone, :latest_company, :latest_job_title, :gradute_school, :gradute_master, :skill, :knowhow, :experience, :english_ability_id, :other,:highest_education_id,:graduate_year,:age_year,:cv_path)";
$stmt = $this->db->prepare($sql);
$a = [
"name" => $application->getName(),
"gender" => $application->getGender(),
"second_email" => $application->getSecondEmail(),
"second_phone" => $application->getSecondPhone(),
"email" => $application->getEmail(),
"phone" => $application->getPhone(),
"latest_company" => $application->get_latest_company(),
"latest_job_title" => $application->get_latest_job_title(),
"gradute_school" => $application->get_gradute_school(),
"gradute_master" => $application->get_gradute_master(),
"experience" => $application->get_experience(),
"english_ability_id" => $application->get_english_ability_id(),
"other" => $application->getOther(),
"highest_education_id" => $application->get_highest_education_id(),
"graduate_year" => $application->get_graduate_year(),
"age_year" => $application->get_age_year(),
"cv_path" => $application->getCVpath()
];
$a['skill'] = $application->get_skill();
$a['knowhow'] = $application->get_knowhow();
$result = $stmt->execute($a);
if(!$result) {
throw new Exception("could not save record");
}else{
$id = $this->db->lastInsertId();
return array('success'=>'成功新增履歷','id'=>$id);
}
}
public function update(UserApplyTmpEntity $application) {
$this->_valid_save_update($application);
$sql = "update users_application set
name = :name, gender = :gender, second_email = :second_email, second_phone = :second_phone, email = :email, phone= :phone,latest_company= :latest_company,latest_job_title= :latest_job_title,gradute_school= :gradute_school,gradute_master= :gradute_master,skill= :skill,knowhow= :knowhow,experience= :experience,english_ability_id= :english_ability_id,other= :other,highest_education_id=:highest_education_id,graduate_year=:graduate_year,age_year=:age_year,cv_path=:cv_path where id=".$application->getId();
$stmt = $this->db->prepare($sql);
$a = [
"name" => $application->getName(),
"gender" => $application->getGender(),
"second_email" => $application->getSecondEmail(),
"second_phone" => $application->getSEcondPhone(),
"email" => $application->getEmail(),
"phone" => $application->getPhone(),
"latest_company" => $application->get_latest_company(),
"latest_job_title" => $application->get_latest_job_title(),
"gradute_school" => $application->get_gradute_school(),
"gradute_master" => $application->get_gradute_master(),
"experience" => $application->get_experience(),
"english_ability_id" => $application->get_english_ability_id()>0 ? $application->get_english_ability_id() : 0, # HOTFIX
"other" => $application->getOther(),
"highest_education_id" => $application->get_highest_education_id()>0 ? $application->get_highest_education_id() : 0, #HOTFIX
"graduate_year" => $application->get_graduate_year(),
"age_year" => $application->get_age_year(),
"cv_path" => $application->getCVpath()
];
$a['skill'] = $application->get_skill();
$a['knowhow'] = $application->get_knowhow();
$result = $stmt->execute($a);
if(!$result) {
throw new Exception("could not update record");
}
}
}