本文整理汇总了PHP中app\Question::whereNotIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::whereNotIn方法的具体用法?PHP Question::whereNotIn怎么用?PHP Question::whereNotIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Question
的用法示例。
在下文中一共展示了Question::whereNotIn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Receive answer from test and format next question and test
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$user = Auth::user();
$question = Question::with('skill')->with('difficulty')->with('skill.level')->with('skill.track')->find($request->question_id);
// log
$question->tests()->updateExistingPivot($request->test_id, ['answered' => TRUE], false);
$user->tested_questions()->attach($request->question_id, ['correct' => $correct = $question->correct_answer == $request->answer]);
// initialize
$error_limit = Config::get('mathtest.error_test');
$success_limit = Config::get('mathtest.success_test');
$difficulty = $question->difficulty_id;
$skill = $question->skill;
$level = $skill->level;
$track = $skill->track;
$test = Test::find($request->test_id);
$maxile = 0;
// track if user has done questions of the same skill and difficulty
$test_record = $test->questions()->selectRaw('question_test.question_id as id')->lists('id');
$total_correct = $user->numberCorrect()->where('questions.difficulty_id', '=', $difficulty)->where('questions.skill_id', '=', $skill->id)->take(max($error_limit, $success_limit))->first()->total_correct;
// dd($total_correct);
// dd($question->correct_answer == $request->answer);
$new_question = new Question();
// return $track->users()->get();
if ($correct) {
//if answer is correct
// dd($correct);
if ($total_correct < $success_limit - 1) {
//cleared this difficulty
if ($new_question = Question::similar($difficulty, $skill->id)->whereNotIn('id', $test_record)->first()) {
// dd($correct);
}
} else {
$user->track_results()->attach($question->track, ['difficulty_id' => $question->difficulty_id, 'skill_id' => $question->skill_id, 'level_id' => $question->skill->level->id, 'track_id' => $question->skill->track->id, 'maxile' => intval($question->skill->level->starting_maxile_level + 100 * ($difficulty / Difficulty::max('difficulty')) * ($skill->skill / Skill::whereLevelId($level->id)->max('skill')))]);
if ($difficulty < Difficulty::max('difficulty')) {
$new_question = Question::harder($difficulty, $skill->id)->whereNotIn('id', $test_record)->first();
} elseif ($skill->skill < Skill::whereTrackId($track->id)->whereLevelId($level->id)->max('skill')) {
$new_question = Question::whereNotIn('id', $test_record)->upskill($skill, $track->id, $level->id)->first();
} elseif ($level->level < Level::max('level')) {
$new_question = Question::whereNotIn('id', $test_record)->whereSkillId(Skill::orderBy('skill', 'asc')->first()->id)->first();
} else {
return ['msg' => 'You have reached the maximum level and difficulty for all skills in this track.'];
}
}
// if answer is wrong
} elseif ($difficulty > Difficulty::min('difficulty')) {
$new_question = Question::easier($difficulty, $skill->id)->whereNotIn('id', $test_record)->first();
} elseif ($skill->skill > Skill::whereTrackId($track->id)->whereLevelId($level->id)->min('skill')) {
$new_question = Question::whereNotIn('id', $test_record)->downskill($skill, $track->id, $level->id)->first();
} elseif ($level->level > Level::min('level')) {
$new_question = Question::whereNotIn('id', $test_record)->whereSkillId(Skill::orderBy('skill', 'desc')->first()->id)->first();
} else {
return ['msg' => 'You have reached the minimum level and difficulty for all skills in this track.'];
}
// dd($new_question);
if (isset($new_question) and $new_question->id != null) {
$new_question->tests()->attach($request->test_id, ['answered' => FALSE]);
return $this->formatQuiz($new_question, $request->test_id);
} else {
return ['result' => Track::join('track_user', 'id', '=', 'track_id')->where('track_user.user_id', '=', $user->id)->select('tracks.track')->selectRaw('max(track_user.maxile) as max')->groupBy('tracks.track')->get()];
}
}