コード例 #1
0
ファイル: ExamsController.php プロジェクト: bpikaar/cmgt_elo
 /**
  * GET
  * Course details
  */
 public function show($id)
 {
     $exam = Exam::find($id);
     $course = Course::find($exam->course_id);
     $feedback = DB::table('feedbacks')->join('results', 'feedbacks.result_id', '=', 'results.id')->join('exams', 'results.exam_id', '=', 'exams.id')->where('results.exam_id', $id)->where('feedbacks.student_id', Auth::user()->id)->select('feedbacks.*', 'exams.description')->orderBy('feedbacks.created_at', 'desc')->get();
     return view('exams.show', ['exam' => $exam, 'course' => $course, 'feedback' => $feedback]);
 }
コード例 #2
0
 public function __construct()
 {
     $this->middleware('auth');
     $this->userId = Auth::user()->id;
     $this->navbbs = DB::table('building_block_student')->join('building_blocks', 'building_blocks.id', '=', 'building_block_student.building_block_id')->where('building_block_student.user_id', $this->userId)->get();
     $this->currentCourse = Course::where('start_date', '<=', Carbon::now()->toDateString())->where('end_date', '>=', Carbon::now()->toDateString())->first();
 }
コード例 #3
0
 /**
  * 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]);
 }
コード例 #4
0
 /**
  * GET
  * Course details
  */
 public function show($id)
 {
     $course = Course::find($id);
     $exams = Exam::where('course_id', $id)->get();
     // Voor het opmaken van de tabel is het nodig om te weten
     // wat het maximum aantal resultaten van een toets zijn.
     // Zoveel rijen zullen er uiteindelijk in de tabel moeten komen
     // tel het aantal resultaten per toets van deze student
     $iterations = DB::select('SELECT MAX(a.amt) AS amount
             FROM
                 (SELECT
                   COUNT(results.id) AS amt,
                   exams.description,
                   exams.id
                 FROM
                   results
                 INNER JOIN
                   exams ON results.exam_id = exams.id
                 WHERE
                   exams.course_id = :course_id AND results.student_id = :student_id
                 GROUP BY
                   results.exam_id) a', ['course_id' => $course->id, 'student_id' => Auth::user()->id]);
     // Deze tabel wordt gevuld met resultaten. Een '-' als er geen resultaat is
     // De tabel wordt gebruikt om te tekenen op de site
     $resultTable = [];
     foreach ($exams as $index => $exam) {
         // Haal alle resultaten per toets op
         $results = DB::table('results')->where('exam_id', $exam->id)->where('student_id', Auth::user()->id)->orderBy('created_at')->get();
         $div = '<div class="panel-group" id="accordion' . $index . '" role="tablist" aria-multiselectable="true">';
         // doorloop het aantal iteraties voor het max aantal resultaten
         for ($i = 0; $i < $iterations[0]->amount; $i++) {
             if (!empty($results[$i])) {
                 $feedback = DB::table('feedbacks')->where('result_id', $results[$i]->id)->first();
                 if (!empty($feedback)) {
                     $feedback = $feedback->content;
                 } else {
                     $feedback = 'Er is geen feedback toegevoegd.';
                 }
                 $div .= '<div class="panel panel-default">
                             <div class="panel-heading" role="tab" id="heading' . $index . '_' . $i . '">
                               <h4 class="panel-title">
                                 <a role="button" data-toggle="collapse" data-parent="#accordion' . $index . '" href="#collapse' . $index . '_' . $i . '"';
                 // if this is the first feedback in the row, expand the panel
                 $div .= $i == 0 ? 'aria-expanded="true"' : 'aria-expanded="false"';
                 $div .= 'aria-controls="collapse' . $index . '_' . $i . '">';
                 $div .= $results[$i]->result . '</a>
                           </h4>
                         </div>
                         <div id="collapse' . $index . '_' . $i . '"';
                 $div .= $i == 0 ? 'class="panel-collapse collapse in"' : 'class="panel-collapse collapse"';
                 $div .= 'role="tabpanel" aria-labelledby="heading' . $index . '_' . $i . '">
                           <div class="panel-body">';
                 $div .= $feedback;
                 $div .= '</div>
                             </div>
                           </div>';
                 //$resultTable[$i][$index] = '<div>'.$results[$i]->result.'</div>';
             } else {
                 //$resultTable[$i][$index] = '-';
             }
         }
         $div .= '</div>';
         $resultTable[0][$index] = $div;
     }
     return view('courses.show', ['course' => $course, 'exams' => $exams, 'resultTable' => $resultTable]);
 }