108 lines
2.9 KiB
PHP
108 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\DataSoalModel;
|
|
use App\Models\TestSessionsModel;
|
|
use Illuminate\Http\Request;
|
|
|
|
class HalamanUjianController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
|
|
$id_session = null;
|
|
if(session('id_test_sessions') != null) {
|
|
$id_session = session('id_test_sessions');
|
|
} else if($request->id_test_sessions != null) {
|
|
$id_session = $request->id_test_sessions;
|
|
} else {
|
|
return redirect()->route('cek-status.index')->with('error', 'Data sesi tes tidak ditemukan. Silakan mulai tes terlebih dahulu.');
|
|
}
|
|
|
|
$data_session = TestSessionsModel::where('id_test_sessions', $id_session)->first();
|
|
if($data_session != null) {
|
|
if($data_session->status_session != '1') {
|
|
return redirect()->route('cek-status.index')->with('error', 'Data sesi tes belum dimulai atau telah usai. Silahkan cek status dengan kode untuk informasi lebih lanjut.');
|
|
}
|
|
} else {
|
|
return redirect()->route('cek-status.index')->with('error', 'Data sesi tes tidak ditemukan. Silakan mulai tes terlebih dahulu.');
|
|
}
|
|
|
|
$question_number = null;
|
|
$data_question = null;
|
|
if(session('question') != null) {
|
|
$question_number = session('question');
|
|
} else if($request->question != null) {
|
|
$question_number = $request->question;
|
|
} else {
|
|
$question_number = 1;
|
|
}
|
|
|
|
$data_question = DataSoalModel::all();
|
|
$total_question = null;
|
|
$is_last_question = false;
|
|
if($question_number <= 0 || $question_number > count($data_question)) {
|
|
$question_number = 1;
|
|
}
|
|
if(count($data_question) == $question_number) {
|
|
$is_last_question = true;
|
|
}
|
|
$total_question = count($data_question);
|
|
$data_question = $data_question[$question_number - 1];
|
|
|
|
return view("user.pages.ujian.index", compact('data_session', 'data_question', 'total_question', 'is_last_question', 'question_number'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
//
|
|
}
|
|
}
|