/** * GET * Building blocks student * @return Response */ public function index() { $bbs = BuildingBlock::with('curators')->get(); $tempSprints = Sprint::where('course_id', $this->currentCourse->id)->get(); $sprints = []; $courseCompleted = 1; // default value foreach ($tempSprints as $index => $sprint) { $sprints[$index]['sprint'] = $sprint; $exams = Exam::where('sprint_id', $sprint->id)->get(); $sprintCompleted = 1; foreach ($exams as $index2 => $exam) { $sprints[$index]['exams'][$index2]['exam'] = $exam; // Resultaten per toets inclusief de feedback van alle resultaten. // In de front-end wordt alleen het laatst toegevoegd resultaat voorzien van feedback $sprints[$index]['exams'][$index2]['results'] = Result::leftJoin('feedbacks', 'feedbacks.result_id', '=', 'results.id')->where('results.exam_id', $exam->id)->where('results.student_id', $this->userId)->orderBy('results.created_at')->get(); // Checks if exam is completed $completed = Result::where('exam_id', $exam->id)->where('student_id', $this->userId)->where('result', 'v')->where('result', 'V')->orderBy('created_at')->get(); if ($completed->isEmpty()) { $examCompleted = 0; $sprintCompleted = 0; } else { $examCompleted = 1; } $sprints[$index]['exams'][$index2]['completed'] = $examCompleted; } if (!$sprintCompleted) { $courseCompleted = 0; } // alleen overschrijven als een sprint niet behaald is. $sprints[$index]['sprintCompleted'] = $sprintCompleted; } // dd($sprints); return view('student.index', ['bbs' => $bbs, 'navbbs' => $this->navbbs, 'course' => $this->currentCourse, 'sprints' => $sprints, 'courseCompleted' => $courseCompleted]); }
/** * Store all results and feedback for a course */ public function storeResults(Request $request) { $student = User::find($request->student_id); $course = Course::find($request->course_id); $exams = Exam::where('course_id', $course->id)->get(); // Validate when feedback is present and no result is entered $rules = []; $messages = []; foreach ($request->exams as $index => $exam) { if ($exam['result'] == '' && $exam['feedback'] != '') { $rules["exams.{$index}.result"] = 'required'; $messages[] = 'Er moet een resultaat ingevuld zijn als je feedback wilt geven.'; } } // Handle validation or store if (!empty($rules)) { $this->validate($request, $rules, $messages); } else { foreach ($request->exams as $index => $exam) { // Store result and feedback in DB if ($exam['result'] != '' && $exam['feedback'] != '') { // Save Result in db and get new id $result = new Result(); $result->exam_id = $exam['id']; $result->result = $exam['result']; $result->student_id = $student->id; $result->save(); // Save feedback with result id $feedback = new Feedback(); $feedback->result_id = $result->id; $feedback->content = $exam['feedback']; $feedback->student_id = $student->id; $feedback->save(); } } } return view('teacher.add_grade', ['student' => $student, 'course' => $course, 'exams' => $exams]); }