Skip to content
Snippets Groups Projects
Commit 456f707c authored by Kurniandha Sukma Yunastrian's avatar Kurniandha Sukma Yunastrian
Browse files

add grade save and show

parent 4e7ef27d
Branches
2 merge requests!8Finalize,!5Integration
...@@ -4,6 +4,7 @@ namespace App\Http\Controllers; ...@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Google_Client; use Google_Client;
class AutograderController extends Controller class AutograderController extends Controller
...@@ -40,18 +41,21 @@ class AutograderController extends Controller ...@@ -40,18 +41,21 @@ class AutograderController extends Controller
$results = AutograderController::grade($keys, $answers); $results = AutograderController::grade($keys, $answers);
echo ' echo '
<table class="table"> <table class="table table-hover">
<thead> <thead>
<tr> <tr>
<th scope="col">Cell</th> <th scope="col">Cell</th>
<th scope="col">Kunci</th> <th scope="col">Kunci</th>
<th scope="col">Jawaban</th> <th scope="col">Jawaban</th>
<th scope="col">Skor</th> <th scope="col">Skor</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
'; ';
$score = 0;
for ($i=0; $i<count($results); $i++) { for ($i=0; $i<count($results); $i++) {
$score = $score + $results[$i]*100;
echo '<tr>'; echo '<tr>';
echo '<th>' . $cells_temp[$i] . '</th>'; echo '<th>' . $cells_temp[$i] . '</th>';
echo '<td>' . $keys[$i] . '</td>'; echo '<td>' . $keys[$i] . '</td>';
...@@ -60,10 +64,28 @@ class AutograderController extends Controller ...@@ -60,10 +64,28 @@ class AutograderController extends Controller
echo '</tr>'; echo '</tr>';
} }
echo ' echo '
<tr>
<td></td>
<td></td>
<th class="table-primary">Skor Akhir</th>
<th class="table-primary">' . $score/count($results) . '</th>
</tr>
</tbody> </tbody>
</table> </table>
<a href="/course/ ' . $id_course . '" style="float: right;" class="btn btn-primary" role="button">Kembali ke Kelas</a> <a href="/course/' . $id_course . '" style="float: right;" class="btn btn-primary" role="button">Kembali ke Kelas</a>
'; ';
DB::table('grades')->where([
['id_topic', '=' ,$id_topic],
['id_user', '=', Auth::id()]
])->delete();
DB::table('grades')->insert([
'id_course' => $id_course,
'id_user' => Auth::id(),
'id_topic' => $id_topic,
'grade' => $score/count($results)
]);
} }
/** /**
......
...@@ -38,8 +38,22 @@ class CourseController extends Controller ...@@ -38,8 +38,22 @@ class CourseController extends Controller
$students[] = $temp->name; $students[] = $temp->name;
} }
} }
return view('course', ['topics' => $topics, 'students' => $students, 'teacher' => $teacher]); $scores = [];
foreach($topics as $topic) {
$grades = DB::table('grades')->where([
['id_topic', '=' ,$topic->id],
['id_user', '=', Auth::id()]
])->first();
if (empty($grades)) {
$scores[] = '-';
} else {
$scores[] = $grades->grade;
}
}
return view('course', ['scores' => $scores, 'topics' => $topics, 'students' => $students, 'teacher' => $teacher]);
} }
/** /**
......
function submit(id_spreadsheet, url) { function submit(id_spreadsheet, url) {
document.getElementById("submit").disabled = true; document.getElementById("submit").disabled = true;
document.getElementById("back").disabled = true;
var xmlhttp = new XMLHttpRequest(); var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() { xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) { if (this.readyState == 4 && this.status == 200) {
......
...@@ -96,9 +96,22 @@ ...@@ -96,9 +96,22 @@
<div class="card"> <div class="card">
<div class="card-header">Progress</div> <div class="card-header">Progress</div>
<div class="card-body"> <div class="card-body">
@foreach($topics as $index => $topic) <table class="table table-hover">
Topik {{ $index + 1 }}: 100/100 <br/> <thead>
@endforeach <tr>
<th scope="col">Materi</th>
<th scope="col">Skor</th>
</tr>
</thead>
<tbody>
@foreach($scores as $index => $score)
<tr>
<td>Materi {{ $index + 1 }}</td>
<td>{{ $score }}</td>
</tr>
@endforeach
</tbody>
</table>
</div> </div>
</div> </div>
<br/> <br/>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
frameBorder="0" frameBorder="0"
src="https://docs.google.com/spreadsheets/d/<?php echo $id_spreadsheet; ?>/edit?usp=drivesdk&rm=embedded"> src="https://docs.google.com/spreadsheets/d/<?php echo $id_spreadsheet; ?>/edit?usp=drivesdk&rm=embedded">
</iframe> </iframe>
<a href="/course/<?php echo $id_course; ?>" class="btn btn-primary" role="button">Kembali ke Kelas</a> <a href="/course/<?php echo $id_course; ?>" class="btn btn-primary" id="back" role="button">Kembali ke Kelas</a>
<button id="submit" style="float: right;" type="text" onclick="submit('<?php echo $id_spreadsheet; ?>', '<?php echo Request::url(); ?>/submit')" class="btn btn-success"><b>Submit</b></button> <button id="submit" style="float: right;" type="text" onclick="submit('<?php echo $id_spreadsheet; ?>', '<?php echo Request::url(); ?>/submit')" class="btn btn-success"><b>Submit</b></button>
</div> </div>
<div id="result" class="col-lg-10" style="margin-top: 1rem; display:none"> <div id="result" class="col-lg-10" style="margin-top: 1rem; display:none">
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment