1
0

add displaying of test results

This commit is contained in:
Rokas Puzonas 2023-11-25 23:46:42 +02:00
parent 2ad0115405
commit 699754236b
2 changed files with 25 additions and 0 deletions

View File

@ -7,6 +7,7 @@ use App\Models\MultipleChoiceAnswers;
use App\Models\SingleChoiceAnswer;
use App\Models\SingleQuestionAnswers;
use App\Models\Test;
use App\Models\TestResult;
use App\Models\User;
use Illuminate\Http\Request;
@ -101,11 +102,19 @@ class TestController extends Controller
array_push($assigned_students, $assigned_student);
}
$test_results = [];
foreach (TestResult::where("test_id", $test->id)->get() as $test_result) {
$student = User::where("id", $test_result->student_id)->first();
$test_result->student_name = $student->name;
array_push($test_results, $test_result);
}
return view("tests.edit", [
"test" => $test,
"questions" => $questions,
"students" => $students,
"assigned_students" => $assigned_students,
"test_results" => $test_results
]);
}

View File

@ -142,6 +142,22 @@
<hr class="mt-6 mb-6">
<div>
<h2 class="text-center text-lg font-medium">{{ __("Test results") }}</h2>
<table class="mt-6 border border-gray-300 w-full text-left">
<tr>
<th class="border border-gray-300 p-1">{{ __("Student") }}</th>
<th class="border border-gray-300 p-1">{{ __("Points") }}</th>
<th class="border border-gray-300 p-1">{{ __("Grade") }}</th>
</tr>
@foreach ($test_results as $test_result)
<tr>
<td class="border border-gray-300 p-1">{{ $test_result->student_name }}</td>
<td class="border border-gray-300 p-1">{{ $test_result->points }}</td>
<td class="border border-gray-300 p-1">{{ round($test_result->points / $test_result->max_points * 10, 2) }}</td>
</tr>
@endforeach
</table>
</div>
</div>
</x-app-layout>