0
1つの関数内に4つのクエリがあります。これは、再開を作成するためのnsertです。これには、教育、雇用、スキル、およびそれらに加わる主なCVが含まれます。すべてが実行されていない場合、複数のクエリからの成功メッセージを返す
CVを作成するときに、上記のもの(教育、仕事、スキル)を作成するために、必ずしもすべての異なるフォームに記入するわけではありませんが、1回の成功メッセージを返す必要があります。それ以外の場合、私は使用することはできません:行数にそれはそれらまたはnoneのすべての値を返しますので、どのように私はエコーすることができますので:
Alert::success('adding_resume', true);
一度にもそれらのいくつかのフォームが空の場合。
ちょうどそれのいずれかを確認せずにすべてを挿入しようと、あなたがこのについて移動するための奇妙な方法のように思えるが、あなたはこれを行うことができますpublic static function create_resume()
{
// Let's define the rules and filters
$rules = array(
'resume_title' => 'max_len,100|required',
'expected_level' => 'max_len,100|required',
'expected_salary' => 'required|max_len,12|integer',
'work_location' => 'max_len,100',
'year_experience' => 'max_len,100|integer'
);
//validate the info
$validated = FormValidation::is_valid($_POST, $rules);
// Check if validation was successful
if($validated !== TRUE):
//exit with an error
exit(Alert::error(false, true, $validated));
endif;
//initate db
$database = DatabaseFactory::getFactory()->getConnection();
//sql to run
$sql = "INSERT INTO resumes
(
resume_title,
resume_work_level,
resume_total_work_experience,
resume_salary,
resume_work_country,
resume_about,
resume_user,
resume_date_created
)
VALUES
(
?,
?,
?,
?,
?,
?,
?,
?
)";
//run the sql
$resume = $database->prepare($sql);
$resume->execute(array(Request::post('resume_title'), Request::post('expected_level'), Request::post('year_experience'),
Request::post('expected_salary'), Request::post('work_location'), Request::post('about'), Session::get('id'),
date("Y-m-d")));
//results?
if($resume->rowCount())
{
//resume id
$resume_id = $database->lastinsertid();
//create employment
$sql_employment = "INSERT INTO employment
(
employment_company,
employment_name,
employment_datestart,
employment_dateend,
employment_description,
employment_country,
employment_user,
employment_resume
)
VALUES
(
?,
?,
?,
?,
?,
?,
?,
?
)";
//run the sql
$employments = $database->prepare($sql_employment);
//if they have more than 1
foreach($_POST['experience'] as $employment):
$employments->execute(array($employment['company'], $employment['title'], date("Y-m-d", strtotime($employment['year_begin'])),
date("Y-m-d", strtotime($employment['year_finish'])), $employment['notes'], $employment['country'],
Session::get('id'), $resume_id));
endforeach;
if($employments->rowCount())
{
//sql to run
$education_sql = "INSERT INTO education
(
education_institute,
education_degree,
education_dateobtained,
education_dateexpires,
education_description,
education_user,
education_date,
education_resume
)
VALUES
(
?,
?,
?,
?,
?,
?,
?,
?
)";
//run the sql
$educations = $database->prepare($education_sql);
//for multiple education
foreach(Request::post('education') as $education):
$educations->execute(array($education['institution'], $education['degree'], date("Y-m-d", strtotime($education['year_begin'])),
date("Y-m-d", strtotime($education['year_finish'])), $education['about'], Session::get('id'), date("Y-m-d"),
$resume_id));
endforeach;
//results
if($educations->rowCount())
{
//sql to run
$sql_skill = "INSERT INTO skills
(
skill_type,
skill_percent,
skill_user,
skill_resume
)
VALUES
(
?,
?,
?,
?
)";
//run the sql
$skills = $database->prepare($sql_skill);
//for each skill
foreach(Request::post('skill') as $skill):
$skills->execute(array($skill['name'], $skill['percentage'], Session::get('id'), $resume_id));
endforeach;
//the results?
if($skills->rowCount())
{
Alert::success('adding_resume', true);
}else{
Alert::alert('adding_resume', true);
}
}else{
Alert::error('adding_resume', true);
}
}else{
Alert::error('adding_resume', true);
}
}else{
Alert::error('adding_resume', true);
}
}