add: api quiz & get santri
This commit is contained in:
parent
ec4d21af1d
commit
08de48498d
|
@ -9,6 +9,7 @@
|
|||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class UserControler extends Controller
|
||||
{
|
||||
|
@ -97,4 +98,216 @@ public function logout(Request $request)
|
|||
|
||||
return ResponseFormatter::success($token, 'Token Revoked');
|
||||
}
|
||||
|
||||
public function getUsersByRole(Request $request)
|
||||
{
|
||||
try {
|
||||
// Ambil data user yang memiliki peran 'santri'
|
||||
$users = User::where('peran', 'santri')->get();
|
||||
|
||||
// Jika tidak ada user dengan peran 'santri'
|
||||
if ($users->isEmpty()) {
|
||||
return ResponseFormatter::error(
|
||||
null,
|
||||
"Tidak ada pengguna dengan peran santri",
|
||||
404
|
||||
);
|
||||
}
|
||||
|
||||
// Mengembalikan data pengguna dengan peran 'santri'
|
||||
return ResponseFormatter::success(
|
||||
$users,
|
||||
"Pengguna dengan peran santri berhasil ditemukan"
|
||||
);
|
||||
} catch (Exception $error) {
|
||||
return ResponseFormatter::error(
|
||||
['message' => 'Something went wrong', 'error' => $error->getMessage()],
|
||||
'Terjadi kesalahan',
|
||||
500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserInfoById($id)
|
||||
{
|
||||
// Mencari user berdasarkan ID
|
||||
$user = User::find($id);
|
||||
|
||||
// Jika pengguna tidak ditemukan, kembalikan response error
|
||||
if (!$user) {
|
||||
return ResponseFormatter::error(
|
||||
null,
|
||||
'User not found',
|
||||
404
|
||||
);
|
||||
}
|
||||
|
||||
// Mengembalikan data pengguna dalam format JSON menggunakan ResponseFormatter
|
||||
return ResponseFormatter::success(
|
||||
[
|
||||
'id' => $user->id,
|
||||
'nama_lengkap' => $user->nama_lengkap,
|
||||
'alamat' => $user->alamat,
|
||||
'usia' => $user->usia,
|
||||
'no_telp_wali' => $user->no_telp_wali,
|
||||
'email' => $user->email,
|
||||
'jenis_kelamin' => $user->jenis_kelamin,
|
||||
'jenjang_pendidikan' => $user->jenjang_pendidikan,
|
||||
],
|
||||
'User data retrieved successfully'
|
||||
);
|
||||
}
|
||||
|
||||
public function updateUserById(Request $request, $id)
|
||||
{
|
||||
// Validate the incoming data
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nama_lengkap' => 'required|string|max:255',
|
||||
'alamat' => 'required|string|max:255',
|
||||
'usia' => 'required|string|max:255',
|
||||
'no_telp_wali' => 'required|string|max:20',
|
||||
'email' => 'required|email|max:255',
|
||||
'jenjang_pendidikan' => 'required|string|max:255',
|
||||
'jenis_kelamin' => 'required|string|in:Laki-laki,Perempuan',
|
||||
]);
|
||||
|
||||
// If validation fails, return error response
|
||||
if ($validator->fails()) {
|
||||
return ResponseFormatter::error(
|
||||
null,
|
||||
'Validation Error',
|
||||
422
|
||||
);
|
||||
}
|
||||
|
||||
// Find the user by ID
|
||||
$user = User::find($id);
|
||||
|
||||
// If the user does not exist, return an error response
|
||||
if (!$user) {
|
||||
return ResponseFormatter::error(
|
||||
null,
|
||||
'User not found',
|
||||
404
|
||||
);
|
||||
}
|
||||
|
||||
// Update the user's details
|
||||
$user->nama_lengkap = $request->nama_lengkap;
|
||||
$user->alamat = $request->alamat;
|
||||
$user->usia = $request->usia;
|
||||
$user->no_telp_wali = $request->no_telp_wali;
|
||||
$user->email = $request->email;
|
||||
$user->jenjang_pendidikan = $request->jenjang_pendidikan;
|
||||
$user->jenis_kelamin = $request->jenis_kelamin;
|
||||
|
||||
// Save the updated user data
|
||||
$user->save();
|
||||
|
||||
// Return success response
|
||||
return ResponseFormatter::success(
|
||||
$user,
|
||||
'User updated successfully'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function tambahSantri(Request $request)
|
||||
{
|
||||
// Validasi input
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nama_lengkap' => 'required|string|max:255',
|
||||
'alamat' => 'required|string|max:255',
|
||||
'usia' => 'required|string|max:255',
|
||||
'no_telp_wali' => 'required|string|max:20',
|
||||
'email' => 'required|email|max:255',
|
||||
'jenis_kelamin' => 'required|string|in:Laki-laki,Perempuan',
|
||||
'jenjang_pendidikan' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
// Jika validasi gagal
|
||||
if ($validator->fails()) {
|
||||
return ResponseFormatter::error(
|
||||
null,
|
||||
'Validation Error',
|
||||
422
|
||||
);
|
||||
}
|
||||
|
||||
// Ambil data santri dari request
|
||||
$santri = $request->only([
|
||||
'nama_lengkap', 'alamat', 'usia', 'no_telp_wali', 'email', 'jenis_kelamin', 'jenjang_pendidikan'
|
||||
]);
|
||||
|
||||
// Simpan santri ke database
|
||||
$santriInserted = User::create([
|
||||
'nama_lengkap' => $santri['nama_lengkap'],
|
||||
'alamat' => $santri['alamat'],
|
||||
'usia' => $santri['usia'],
|
||||
'no_telp_wali' => $santri['no_telp_wali'],
|
||||
'email' => $santri['email'],
|
||||
'jenis_kelamin' => $santri['jenis_kelamin'],
|
||||
'jenjang_pendidikan' => $santri['jenjang_pendidikan'],
|
||||
'peran' => 'santri',
|
||||
'password' => bcrypt($santri['email']), // password = email (dihash)
|
||||
]);
|
||||
|
||||
// Respon sukses
|
||||
return ResponseFormatter::success(
|
||||
$santriInserted,
|
||||
'Santri data imported successfully'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// public function importSantri(Request $request)
|
||||
// {
|
||||
// // Validasi input
|
||||
// $validator = Validator::make($request->all(), [
|
||||
// 'santri' => 'required|array',
|
||||
// 'santri.*.nama_lengkap' => 'required|string|max:255',
|
||||
// 'santri.*.alamat' => 'required|string|max:255',
|
||||
// 'santri.*.usia' => 'required|string|max:255',
|
||||
// 'santri.*.no_telp_wali' => 'required|string|max:20',
|
||||
// 'santri.*.email' => 'required|email|max:255',
|
||||
// 'santri.*.jenis_kelamin' => 'required|string|in:Laki-laki,Perempuan',
|
||||
// 'santri.*.jenjang_pendidikan' => 'required|string|max:255',
|
||||
// ]);
|
||||
|
||||
// // Jika validasi gagal
|
||||
// if ($validator->fails()) {
|
||||
// return ResponseFormatter::error(
|
||||
// null,
|
||||
// 'Validation Error',
|
||||
// 422
|
||||
// );
|
||||
// }
|
||||
|
||||
// // Ambil data santri dari request
|
||||
// $santriData = $request->input('santri');
|
||||
// $santriInserted = [];
|
||||
|
||||
// // Simpan tiap santri ke database
|
||||
// foreach ($santriData as $santri) {
|
||||
// $santriInserted[] = User::create([
|
||||
// 'nama_lengkap' => $santri['nama_lengkap'],
|
||||
// 'alamat' => $santri['alamat'],
|
||||
// 'usia' => $santri['usia'],
|
||||
// 'no_telp_wali' => $santri['no_telp_wali'],
|
||||
// 'email' => $santri['email'],
|
||||
// 'jenis_kelamin' => $santri['jenis_kelamin'],
|
||||
// 'jenjang_pendidikan' => $santri['jenjang_pendidikan'],
|
||||
// 'peran' => 'santri',
|
||||
// 'password' => bcrypt($santri['email']), // password = email (dihash)
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// // Respon sukses
|
||||
// return ResponseFormatter::success(
|
||||
// $santriInserted,
|
||||
// 'Santri data imported successfully'
|
||||
// );
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helpers\ResponseFormatter;
|
||||
use App\Models\Quiz;
|
||||
use App\Models\QuizResult;
|
||||
use App\Models\QuizAnswer;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class QuizController extends Controller
|
||||
{
|
||||
public function getQuizByMateri($materiId)
|
||||
{
|
||||
// Mengambil 5 soal secara acak dari materi tertentu
|
||||
$quizzes = Quiz::where('id_materi', $materiId)
|
||||
->inRandomOrder()
|
||||
->limit(5) // Hanya ambil 5 soal
|
||||
->get();
|
||||
|
||||
if ($quizzes->isEmpty()) {
|
||||
return ResponseFormatter::error(
|
||||
null,
|
||||
'Quiz tidak ditemukan untuk materi ini',
|
||||
404
|
||||
);
|
||||
}
|
||||
|
||||
return ResponseFormatter::success(
|
||||
$quizzes,
|
||||
'Data quiz berhasil ditemukan'
|
||||
);
|
||||
}
|
||||
|
||||
public function checkAnswers(Request $request, $materiId)
|
||||
{
|
||||
try {
|
||||
Log::info('Authenticated User ID: ' . Auth::id());
|
||||
|
||||
// Validasi input
|
||||
$request->validate([
|
||||
'answers' => 'required|array',
|
||||
'answers.*.question_id' => 'required|exists:quiz,id',
|
||||
'answers.*.selected_option' => 'required|in:a,b,c,d',
|
||||
]);
|
||||
|
||||
$totalScore = 0;
|
||||
$correctAnswers = 0;
|
||||
|
||||
foreach ($request->answers as $answer) {
|
||||
$quiz = Quiz::find($answer['question_id']);
|
||||
|
||||
if ($quiz->correct_option === $answer['selected_option']) {
|
||||
$totalScore += $quiz->score;
|
||||
$correctAnswers++;
|
||||
}
|
||||
|
||||
QuizAnswer::create([
|
||||
'id_quiz' => $answer['question_id'],
|
||||
'id_user' => Auth::id(), // Make sure this returns the correct user ID
|
||||
'selected_option' => $answer['selected_option'],
|
||||
'status' => $quiz->correct_option === $answer['selected_option'] ? 'correct' : 'incorrect',
|
||||
]);
|
||||
}
|
||||
|
||||
$quizResult = QuizResult::create([
|
||||
'id_user' => Auth::id(),
|
||||
'id_materi' => $materiId,
|
||||
'total_score' => $totalScore,
|
||||
'status' => 'selesai',
|
||||
]);
|
||||
|
||||
return ResponseFormatter::success(
|
||||
['total_score' => $totalScore, 'correct_answers' => $correctAnswers],
|
||||
'Jawaban berhasil diperiksa dan hasil sudah dihitung'
|
||||
);
|
||||
} catch (Exception $error) {
|
||||
return ResponseFormatter::error(
|
||||
['message' => 'Something went wrong', 'error' => $error->getMessage()],
|
||||
'Terjadi kesalahan', 500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getQuizResult(Request $request, $materiId)
|
||||
{
|
||||
try {
|
||||
// Ambil id_user dari token autentikasi
|
||||
$userId = Auth::id();
|
||||
|
||||
// Ambil hasil quiz terakhir untuk user dan materi tersebut
|
||||
$quizResult = QuizResult::where('id_user', $userId)
|
||||
->where('id_materi', $materiId)
|
||||
->latest() // Mengambil hasil terbaru
|
||||
->first();
|
||||
|
||||
// Jika tidak ada hasil untuk user dan materi ini, return dengan nilai default
|
||||
if (!$quizResult) {
|
||||
return ResponseFormatter::success([
|
||||
'total_score' => 0,
|
||||
'status' => 'belum selesai',
|
||||
], 'Hasil Quiz Tidak Ditemukan');
|
||||
}
|
||||
|
||||
// Jika ada hasil, kembalikan data hasil quiz
|
||||
return ResponseFormatter::success([
|
||||
'total_score' => $quizResult->total_score,
|
||||
'status' => $quizResult->status,
|
||||
], 'Hasil Quiz Ditemukan');
|
||||
} catch (Exception $error) {
|
||||
return ResponseFormatter::error(
|
||||
['message' => 'Something went wrong', 'error' => $error->getMessage()],
|
||||
'Terjadi Kesalahan', 500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -24,4 +24,10 @@ public function kategori()
|
|||
{
|
||||
return $this->hasMany(Kategori::class);
|
||||
}
|
||||
|
||||
// Relasi dengan tabel quiz
|
||||
public function quizzes()
|
||||
{
|
||||
return $this->hasMany(Quiz::class, 'id_materi');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Quiz extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'quiz';
|
||||
|
||||
// Menentukan field yang dapat diisi (fillable)
|
||||
protected $fillable = [
|
||||
'id_materi',
|
||||
'question',
|
||||
'option_a',
|
||||
'option_b',
|
||||
'option_c',
|
||||
'option_d',
|
||||
'correct_option',
|
||||
'score',
|
||||
'status',
|
||||
];
|
||||
|
||||
// Relasi dengan tabel materi
|
||||
public function materi()
|
||||
{
|
||||
return $this->belongsTo(Materi::class, 'id_materi');
|
||||
}
|
||||
|
||||
// Relasi dengan tabel quiz_answers (jawaban pengguna)
|
||||
public function quizAnswers()
|
||||
{
|
||||
return $this->hasMany(QuizAnswer::class, 'id_quiz');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class QuizAnswer extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'quiz_answers';
|
||||
|
||||
// Menentukan field yang dapat diisi (fillable)
|
||||
protected $fillable = [
|
||||
'id_quiz',
|
||||
'id_user',
|
||||
'selected_option',
|
||||
'status',
|
||||
];
|
||||
|
||||
// Relasi dengan tabel quiz
|
||||
public function quiz()
|
||||
{
|
||||
return $this->belongsTo(Quiz::class, 'id_quiz');
|
||||
}
|
||||
|
||||
// Relasi dengan tabel users
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'id_user');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class QuizResult extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['id_user', 'id_materi', 'total_score', 'status'];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'id_user');
|
||||
}
|
||||
|
||||
public function materi()
|
||||
{
|
||||
return $this->belongsTo(Materi::class, 'id_materi');
|
||||
}
|
||||
}
|
|
@ -26,6 +26,9 @@ class User extends Authenticatable
|
|||
'peran',
|
||||
'email',
|
||||
'password',
|
||||
'usia',
|
||||
'jenis_kelamin',
|
||||
'jenjang_pendidikan',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('quiz', function (Blueprint $table) {
|
||||
$table->id(); // ID primary key
|
||||
$table->foreignId('id_materi')->constrained('materi')->onDelete('cascade'); // Relasi ke materi
|
||||
$table->text('question'); // Soal quiz
|
||||
$table->string('option_a'); // Pilihan jawaban A
|
||||
$table->string('option_b'); // Pilihan jawaban B
|
||||
$table->string('option_c'); // Pilihan jawaban C
|
||||
$table->string('option_d'); // Pilihan jawaban D
|
||||
$table->char('correct_option', 1); // Menyimpan jawaban yang benar (a, b, c, d)
|
||||
$table->integer('score'); // Skor soal
|
||||
$table->enum('status', ['answered', 'unanswered'])->default('unanswered'); // Status soal
|
||||
$table->timestamps(); // created_at dan updated_at
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('quiz');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('quiz_answers', function (Blueprint $table) {
|
||||
$table->id(); // ID primary key
|
||||
$table->foreignId('id_quiz')->constrained('quiz')->onDelete('cascade'); // Relasi ke tabel quiz
|
||||
$table->foreignId('id_user')->constrained('users')->onDelete('cascade'); // Relasi ke tabel users
|
||||
$table->char('selected_option', 1); // Jawaban yang dipilih oleh pengguna (a, b, c, d)
|
||||
$table->enum('status', ['correct', 'incorrect']); // Status jawaban (benar atau salah)
|
||||
$table->timestamps(); // created_at dan updated_at
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('quiz_answers');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('quiz_results', function (Blueprint $table) {
|
||||
$table->id(); // Auto increment primary key
|
||||
$table->foreignId('id_user')->constrained('users')->onDelete('cascade'); // Mengacu ke tabel users
|
||||
$table->foreignId('id_materi')->constrained('materi')->onDelete('cascade'); // Mengacu ke tabel materi
|
||||
$table->integer('total_score'); // Skor total yang didapat pengguna
|
||||
$table->enum('status', ['selesai', 'belum selesai'])->default('belum selesai'); // Status penyelesaian quiz
|
||||
$table->timestamps(); // created_at, updated_at
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('quiz_results');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('usia')->nullable(); // Menambahkan kolom 'usia' dengan tipe integer
|
||||
$table->enum('jenis_kelamin', ['Laki-laki', 'Perempuan'])->nullable(); // Menambahkan kolom 'jenis_kelamin' dengan tipe enum (L = Laki-laki, P = Perempuan)
|
||||
$table->string('jenjang_pendidikan')->nullable(); // Menambahkan kolom 'jenjang_pendidikan' dengan tipe string
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn(['usia', 'jenis_kelamin', 'jenjang_pendidikan']);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,257 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class QuizTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$questions = [
|
||||
// Soal 1
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Makharijul Huruf artinya .....',
|
||||
'option_a' => 'Tempat-tempat keluarnya huruf hijaiah',
|
||||
'option_b' => 'Tempat-tempat berubahnya huruf hijaiah',
|
||||
'option_c' => 'Tempat-tempat hilangnya huruf hijaiah',
|
||||
'option_d' => 'Tempat-tempat berkumpulnya huruf hijaiah',
|
||||
'correct_option' => 'a',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 2
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Jumlah makhraj-makhraj huruf menurut Ibnu Jazari adalah .....',
|
||||
'option_a' => '15 makhraj',
|
||||
'option_b' => '16 makhraj',
|
||||
'option_c' => '17 makhraj',
|
||||
'option_d' => '18 makhraj',
|
||||
'correct_option' => 'c',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 3
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Salah satu tempat keluarnya huruf adalah Al-Halqi. Halqi artinya .....',
|
||||
'option_a' => 'Lidah',
|
||||
'option_b' => 'Tenggorokan',
|
||||
'option_c' => 'Rongga hidung',
|
||||
'option_d' => 'Bibir',
|
||||
'correct_option' => 'b',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 4
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Huruf ain (ع) merupakan huruf yang keluar dari .....',
|
||||
'option_a' => 'Lidah bagian tengah',
|
||||
'option_b' => 'Tenggorokan bagian tengah',
|
||||
'option_c' => 'Lidah bagian ujung',
|
||||
'option_d' => 'Tenggorokan bagian atas',
|
||||
'correct_option' => 'b',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 5
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Jumlah huruf yang keluar lewat tenggorokan adalah .....',
|
||||
'option_a' => '5 huruf',
|
||||
'option_b' => '6 huruf',
|
||||
'option_c' => '7 huruf',
|
||||
'option_d' => '8 huruf',
|
||||
'correct_option' => 'b',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 6
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Berikut ini merupakan huruf yang keluar lewat tenggorokan, kecuali .....',
|
||||
'option_a' => 'Huruf ghain (غ)',
|
||||
'option_b' => 'Huruf hamzah (ء)',
|
||||
'option_c' => 'Huruf kha (خ)',
|
||||
'option_d' => 'Huruf nun (ن)',
|
||||
'correct_option' => 'd',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 7
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Berikut ini merupakan huruf yang memiliki makhraj sama dengan huruf jim (ج) adalah .....',
|
||||
'option_a' => 'Huruf syin (ش)',
|
||||
'option_b' => 'Huruf fa (ف)',
|
||||
'option_c' => 'Huruf lam (ل)',
|
||||
'option_d' => 'Huruf nun (ن)',
|
||||
'correct_option' => 'a',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 8
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Huruf qaf (ق) merupakan huruf yang keluar dari lidah bagian ....',
|
||||
'option_a' => 'Pangkal lidah',
|
||||
'option_b' => 'Ujung lidah',
|
||||
'option_c' => 'Tengah lidah',
|
||||
'option_d' => 'Tepi lidah',
|
||||
'correct_option' => 'a',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 9
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Jumlah huruf yang keluar lewat lidah adalah .....',
|
||||
'option_a' => '15 huruf',
|
||||
'option_b' => '16 huruf',
|
||||
'option_c' => '17 huruf',
|
||||
'option_d' => '18 huruf',
|
||||
'correct_option' => 'd',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 10
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Jumlah huruf yang keluar lewat bibir adalah .....',
|
||||
'option_a' => '2 huruf',
|
||||
'option_b' => '3 huruf',
|
||||
'option_c' => '4 huruf',
|
||||
'option_d' => '5 huruf',
|
||||
'correct_option' => 'c',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 11
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Berikut ini merupakan kelompok huruf yang keluar dari makhraj yang sama, kecuali .....',
|
||||
'option_a' => 'Huruf ع dan ح',
|
||||
'option_b' => 'Huruf غ dan خ',
|
||||
'option_c' => 'Huruf ل dan ط',
|
||||
'option_d' => 'Huruf ث, ذ, dan ظ',
|
||||
'correct_option' => 'a',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 12
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Berikut ini merupakan huruf yang keluar dari pangkal lidah adalah .....',
|
||||
'option_a' => 'Huruf kaf (ك)',
|
||||
'option_b' => 'Huruf nun (ن)',
|
||||
'option_c' => 'Huruf jim (ج)',
|
||||
'option_d' => 'Huruf shad (ص)',
|
||||
'correct_option' => 'a',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 13
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Berikut ini merupakan huruf yang keluar dari tengah lidah adalah .....',
|
||||
'option_a' => 'Huruf kaf (ك)',
|
||||
'option_b' => 'Huruf nun (ن)',
|
||||
'option_c' => 'Huruf jim (ج)',
|
||||
'option_d' => 'Huruf shad (ص)',
|
||||
'correct_option' => 'c',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 14
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Huruf dhad (ض) merupakan huruf yang keluar dari .....',
|
||||
'option_a' => 'Pangkal lidah',
|
||||
'option_b' => 'Bibir dalam',
|
||||
'option_c' => 'Tepi lidah',
|
||||
'option_d' => 'Ujung lidah',
|
||||
'correct_option' => 'c',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 15
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Dua huruf yang keluar dari makhraj yang sama disebut .....',
|
||||
'option_a' => 'Mutamatsilain',
|
||||
'option_b' => 'Mutajanisain',
|
||||
'option_c' => 'Mutaqaribain',
|
||||
'option_d' => 'Mutabaidain',
|
||||
'correct_option' => 'c',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 16
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Berikut ini adalah huruf-huruf yang keluar dari ujung lidah, kecuali .....',
|
||||
'option_a' => 'Huruf dal (د)',
|
||||
'option_b' => 'Huruf tsa (ث)',
|
||||
'option_c' => 'Huruf ya (ي)',
|
||||
'option_d' => 'Huruf dha (ظ)',
|
||||
'correct_option' => 'c',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 17
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Huruf yang keluar dari al-Jauf adalah .....',
|
||||
'option_a' => 'Alif',
|
||||
'option_b' => 'Ba',
|
||||
'option_c' => 'Ta',
|
||||
'option_d' => 'Tsa',
|
||||
'correct_option' => 'a',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 18
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Berapa jumlah huruf yang keluar dari pangkal lidah? .....',
|
||||
'option_a' => '1 huruf',
|
||||
'option_b' => '2 huruf',
|
||||
'option_c' => '3 huruf',
|
||||
'option_d' => '4 huruf',
|
||||
'correct_option' => 'b',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 19
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Berikut ini manakah pernyataan yang benar? .....',
|
||||
'option_a' => 'Makhraj sin (س) adalah ujung lidah dengan rongga antara gigi atas dan gigi bawah yang lebih dekat dengan gigi bawah',
|
||||
'option_b' => 'Makhraj ta (ت) adalah ujung lidah menempel dengan ujung gigi atas',
|
||||
'option_c' => 'Makhraj tha (ط) adalah ujung lidah menempel dengan ujung gigi atas',
|
||||
'option_d' => 'Makhraj tsa (ث) adalah ujung lidah dengan rongga antara gigi atas dan gigi bawah yang lebih dekat dengan gigi bawah',
|
||||
'correct_option' => 'b',
|
||||
'score' => 20,
|
||||
],
|
||||
// Soal 20
|
||||
[
|
||||
'id_materi' => 1,
|
||||
'question' => 'Makhraj huruf zay (ز) adalah .....',
|
||||
'option_a' => 'Ujung lidah dengan rongga antara gigi atas dan gigi bawah yang lebih dekat dengan gigi bawah',
|
||||
'option_b' => 'Ujung lidah menempel dengan pangkal gigi atas',
|
||||
'option_c' => 'Ujung lidah menempel dengan ujung gigi atas',
|
||||
'option_d' => 'Tenggorakan bagian tengah',
|
||||
'correct_option' => 'c',
|
||||
'score' => 20,
|
||||
],
|
||||
];
|
||||
|
||||
// Insert data soal ke dalam tabel quiz
|
||||
foreach ($questions as $question) {
|
||||
DB::table('quiz')->insert([
|
||||
'id_materi' => $question['id_materi'],
|
||||
'question' => $question['question'],
|
||||
'option_a' => $question['option_a'],
|
||||
'option_b' => $question['option_b'],
|
||||
'option_c' => $question['option_c'],
|
||||
'option_d' => $question['option_d'],
|
||||
'correct_option' => $question['correct_option'],
|
||||
'score' => $question['score'],
|
||||
'status' => 'unanswered',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
use App\Http\Controllers\API\KategoryController;
|
||||
use App\Http\Controllers\API\SubMateriControler;
|
||||
use App\Http\Controllers\API\LatihanControler;
|
||||
use App\Http\Controllers\QuizController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -32,4 +33,25 @@
|
|||
Route::get('/kategori/{id_materi}', [KategoryController::class, 'getKategoriByMateri']);
|
||||
// Route::get('/sub_materi', [SubMateriControler::class, 'getAllSubMateri']);
|
||||
Route::get('/sub_materi/{id_kategori}', [SubMateriControler::class, 'getSubMateriByKategori']);
|
||||
Route::get('/latihan/{id_submateri}', [LatihanControler::class, 'getLatihanBySubMateri']);
|
||||
Route::get('/latihan/{id_submateri}', [LatihanControler::class, 'getLatihanBySubMateri']);
|
||||
Route::get('quiz/{materiId}', [QuizController::class, 'getQuizByMateri']);
|
||||
// Route::post('quiz/{materiId}/check', [QuizController::class, 'checkAnswers']);
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
// Endpoint untuk memeriksa jawaban quiz
|
||||
Route::post('quiz/{materiId}/check', [QuizController::class, 'checkAnswers']);
|
||||
|
||||
// Endpoint untuk mengambil hasil quiz berdasarkan materiId
|
||||
Route::get('quizresult/{materiId}', [QuizController::class, 'getQuizResult']);
|
||||
});
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
// Rute untuk mendapatkan user berdasarkan ID
|
||||
Route::get('/user/{id}', [UserControler::class, 'getUserInfoById']);
|
||||
|
||||
// Rute untuk mendapatkan users berdasarkan peran (role) tertentu
|
||||
Route::get('users/santri', [UserControler::class, 'getUsersByRole']);
|
||||
|
||||
Route::put('/updateUser/{id}', [UserControler::class, 'updateUserById']);
|
||||
|
||||
Route::post('/tambahSantri', [UserControler::class, 'tambahSantri']);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue