/** * Bootstrap the application services. * * @return void */ public function boot() { // always returns $user whether logged in or not, null if not view()->composer(['layouts._rightnav', 'layouts.loginForm', 'tracks.index', 'skills.create', 'level.index', 'tracks.editForm', 'levels.editForm', 'difficulties.editForm'], function ($view) { $view->with('user', Auth::check() ? Auth::user()->firstname : null); }); view()->composer(['questions._questionform', 'skills.newform', 'skills._rowform'], function ($view) { $view->with(['tracks' => Track::lists('track', 'id'), 'levels' => Level::lists('description', 'id'), 'difficulties' => Difficulty::lists('difficulty', 'id'), 'skills' => Skill::lists('short_description', 'id'), 'user' => Auth::user()]); }); }
/** * Run the database seeds. * * @return void */ public function run() { Difficulty::create(['difficulty' => 1, 'short_description' => '1 - Knowledge and Comprehension', 'description' => 'Recall of information; Discovery; Observation; Listing; Locating; Naming + Understanding; Translating; Summarising; Demonstrating; Discussing']); Difficulty::create(['difficulty' => 2, 'short_description' => '2 - Application and Analysis', 'description' => 'Using and applying knowledge; Using problem solving methods; Manipulating; Designing; Experimenting + Identifying and analyzing patterns; Organization of ideas; recognizing trends']); Difficulty::create(['difficulty' => 3, 'short_description' => '3 - Synthesis and Evaluation', 'description' => 'Using old concepts to create new ideas; Design and Invention; Composing; Imagining; Inferring; Modifying; Predicting; COmbining; + Assessing theories, Comparison of ideas; Evaluating outcomes; Solving; Judging; Recommending; Rating']); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Difficulty $difficulty) { if (Request::ajax()) { return Difficulty::findOrFail($difficulty->id) ? Difficulty::destroy($difficulty->id) : null; } else { } Difficulty::findOrFail($difficulty->id) ? Difficulty::destroy($difficulty->id) : null; flash('Difficulty is deleted'); return redirect('difficulties'); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $row = \App\Difficulty::find($id); $row->update($request->all()); return redirect()->route('difficulty.index'); }
public function scopeDownlevel($query, $track, $level) { $query->whereDifficultyId(Difficulty::orderBy('difficulty', 'desc')->first()->id)->whereSkillId(Skill::whereTrackId($track)->where('level_id', '<', $level)->orderBy('level_id', 'desc')->orderByRaw("RAND()")->first()->id); }
/** * 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()]; } }