public function index(Request $request) { $exams = ["GRE", "GATE", "TOEFL", "CAT"]; $exam = $request->get('exam'); if (in_array($exam, $exams)) { $details = Exams::where("exam", "=", $exam)->paginate(10); } else { $details = Exams::paginate(10); $exam = "all"; } return view('Categories/exams', ['details' => $details, "exam" => $exam]); }
public function saveAnswerInteractivePractice(Request $request) { $input = Input::all(); $exam = Exams::where(['code' => $input['code']])->firstOrFail(); $user = User::find($request->user()->id); $correct = 0; foreach ($input['steps'] as $k => $v) { if ($k + 1 != $v) { break; } $correct++; } $assessment = User::find($user->id)->assessment()->where(['exam_id' => $exam->id, 'status' => 3])->get()->last(); $assessment->status = 2; $assessment->score = $correct / count($input['steps']); $assessment->save(); return redirect()->intended('/assessment/interactivepractice/' . $input['code'] . '/result'); }
public function qa($id, $q, Request $request) { $user = User::find($request->user()->id); $exam = Exams::where(['code' => $id])->firstOrFail(); $availableQuestions = $exam->questions()->count(); if ($availableQuestions < $exam->items) { $exam->items = $availableQuestions; } $this->data['exam'] = $exam; if ($q == 0) { $thisactivity = new Activity(); $thisactivity->createActivity($user, 'exam', 'took the Exam : ' . $exam->title, 0); $thisassess = $user->assessment()->create(['exam_id' => $exam->id, 'status' => 0]); $this->data['status'] = "start"; } else { $assesment = User::find($user->id)->assessment()->where(['exam_id' => $exam->id])->get()->last(); $questions = $exam->questions()->whereNotExists(function ($query) use($user, $assesment) { $query->select('answers.question_id')->from('answers')->whereRaw('answers.question_id = questions.id AND answers.exam_id = questions.exam AND answers.user_id = "' . $user->id . '" AND answers.assessment_id = "' . $assesment->id . '"'); })->get(); if (count($questions)) { $question = $questions->random(1)->toArray(); $this->data['status'] = "exam"; $question['questionid'] = $q; $ac = 0; $questionarray = json_decode($question['choices']); $question['choices'] = array_map(function ($k, $a) { $b = []; $b['text'] = $a; $b['id'] = $k; return $b; }, range(0, count($questionarray) - 1), $questionarray); shuffle($question['choices']); $this->data['assessment'] = $assesment->toArray(); $this->data['question'] = $question; } else { $this->data['status'] = "result"; $correct = Answers::where(['exam_id' => $exam->id, 'assessment_id' => $assesment->id, 'user_id' => $user->id, 'answer' => 0])->count(); $answered = Answers::where(['exam_id' => $exam->id, 'assessment_id' => $assesment->id, 'user_id' => $user->id])->count(); $this->data['score'] = ['total' => $exam->items, 'answered' => $answered, 'correct' => $correct]; $assessment = $assesment; $assessment->status = 1; if ($exam->items > 0) { $assessment->score = $correct / $exam->items; } else { $assessment->score = 0; } $assessment->save(); } } return view('home.questions', $this->data); }