public function setStatus(Request $request, $id)
 {
     $quiz = Quiz::findOrFail($id);
     $quiz->lead_status = 1;
     $quiz->save();
     return redirect()->back()->withInput();
 }
示例#2
0
 public function detachFrom(Request $request)
 {
     $this->validate($request, ['classroom_id' => 'required', 'quiz_id' => 'required'], ['required' => 'Kolom :attribute diperlukan']);
     $quiz = Quiz::findOrFail($request->quiz_id);
     $quiz->classrooms()->detach($request->classroom_id);
     \Flash::success('Quiz berhasil batalkan.');
     return redirect()->back();
 }
示例#3
0
 public function submitQuiz(Request $request)
 {
     $this->validate($request, ['classroom_id' => 'required|exists:classrooms,id', 'quiz_id' => 'required|exists:quizzes,id', 'answers' => 'required'], ['required' => 'Kolom :attribute diperlukan!', 'exists' => 'Kolom :attribute tidak ditemukan!']);
     $quiz = Quiz::findOrFail($request->quiz_id);
     $total = $quiz->multiplechoices->count();
     $realAnswer = $quiz->multiplechoices->pluck('correct_answer', 'id')->toArray();
     $userAnswer = $request->answers;
     ksort($realAnswer);
     ksort($userAnswer);
     $unanswered = count(array_diff_key($realAnswer, $userAnswer));
     $correct = count(array_intersect_assoc($realAnswer, $userAnswer));
     $wrong = count(array_diff_assoc($realAnswer, $userAnswer));
     $data = ['answer' => json_encode($request->answers), 'unanswered' => $unanswered, 'correct' => $correct, 'wrong' => $total - $correct, 'score' => $correct / $total * 100];
     if ($request->status) {
         $data['status'] = 'done';
     }
     $quiz->students()->sync([Auth::user()->id => $data], false);
     return response()->json(['redirect' => route('classrooms.quizzes', $request->classroom_id), 'unanswered' => $unanswered]);
 }
 public function create($quizId)
 {
     $quiz = Quiz::findOrFail($quizId);
     $page_title = 'Tambahkan Pertanyaan';
     return view('user.quizzes.create-mc', compact('quiz', 'page_title'));
 }