Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Http/Controllers/API/JawabanTAController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function store(Request $request): JsonResponse
'praktikan_id' => ['required', 'integer'],
'modul_id' => ['required', 'integer'],
'answers' => ['present', 'array'],
'answers.*.soal_id' => ['required', 'integer', 'exists:soal_tas,id'],
'answers.*.soal_id' => ['required', 'integer', 'exists:soal_tas,id', 'distinct'],
'answers.*.opsi_id' => ['required', 'integer', 'exists:soal_opsis,id'],
]);

Expand Down Expand Up @@ -114,7 +114,8 @@ public function store(Request $request): JsonResponse
->get();

$correct = $jawaban->filter(fn (JawabanTa $item) => $item->opsi_id === $item->soal_ta?->opsi_benar_id)->count();
$nilai = $jawaban->isNotEmpty() ? ($correct / $jawaban->count()) * 100 : 0;
$totalQuestions = SoalTa::where('modul_id', $modulId)->count();
$nilai = $totalQuestions > 0 ? round(($correct / $totalQuestions) * 100, 2) : 0;

return response()->json([
'status' => 'success',
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/API/JawabanTKController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function store(Request $request): JsonResponse
'praktikan_id' => ['required', 'integer'],
'modul_id' => ['required', 'integer'],
'answers' => ['present', 'array'],
'answers.*.soal_id' => ['required', 'integer', 'exists:soal_tks,id'],
'answers.*.soal_id' => ['required', 'integer', 'exists:soal_tks,id', 'distinct'],
'answers.*.opsi_id' => ['required', 'integer', 'exists:soal_opsis,id'],
]);

Expand Down Expand Up @@ -113,7 +113,8 @@ public function store(Request $request): JsonResponse
->get();

$correct = $jawaban->filter(fn (JawabanTk $item) => $item->opsi_id === $item->soal_tk?->opsi_benar_id)->count();
$nilai = $jawaban->isNotEmpty() ? ($correct / $jawaban->count()) * 100 : 0;
$totalQuestions = SoalTk::where('modul_id', $modulId)->count();
$nilai = $totalQuestions > 0 ? round(($correct / $totalQuestions) * 100, 2) : 0;

return response()->json([
'status' => 'success',
Expand Down
9 changes: 8 additions & 1 deletion app/Http/Controllers/API/SoalTPController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ public function store(Request $request, $id)
// Validasi input
$request->validate([
'soal' => 'required|string|max:10000',
'enable_file_upload' => 'sometimes|boolean',
]);

// Menyimpan soal baru
$soal = SoalTp::create([
'modul_id' => $id,
'soal' => $request->soal,
'enable_file_upload' => $request->boolean('enable_file_upload'),
]);

return response()->json([
Expand Down Expand Up @@ -76,7 +78,8 @@ public function update(Request $request, $id)
'modul_id' => 'required|integer|exists:moduls,id',
// "isEssay" => "required|boolean",
// "isProgram" => "required|boolean",
'soal' => 'required|string|max:1000',
'soal' => 'required|string|max:10000',
'enable_file_upload' => 'sometimes|boolean',
]);
$soal = SoalTp::find($id);
if (! $soal) {
Expand All @@ -97,6 +100,10 @@ public function update(Request $request, $id)
// $soal->isEssay = $request->isEssay;
// $soal->isProgram = $request->isProgram;
$soal->soal = $request->soal;
if ($request->has('enable_file_upload')) {
$soal->enable_file_upload =
$request->boolean('enable_file_upload');
}
$soal->updated_at = now();
$soal->save();

Expand Down
28 changes: 18 additions & 10 deletions database/factories/AsistenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,26 @@ public function definition(): array
];
}

public function withRoles(array $roleName)
public function withRoles(array $roleNames)
{
return $this->afterCreating(function (Asisten $asisten) {
// Assign role in Spatie
$asisten->assignRole($role);
return $this
->state(function () use ($roleNames) {
$roleName = fake()->randomElement($roleNames);

// // Sync `role_id` in the asistens table
// if (!$asisten->role_id) {
// $asisten->role_id = $role->id;
// $asisten->save();
// }
$role = Role::where('name', $roleName)
->where('guard_name', 'asisten')
->firstOrFail();

});
return [
'role_id' => $role->id,
];
})
->afterCreating(function (Asisten $asisten) {
$role = Role::where('id', $asisten->role_id)
->where('guard_name', 'asisten')
->firstOrFail();

$asisten->syncRoles([$role]);
});
}
}
7 changes: 7 additions & 0 deletions database/factories/PraktikanFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Database\Factories;

use App\Models\Kelas;
use App\Models\Praktikan;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand Down Expand Up @@ -30,4 +31,10 @@ public function definition(): array
'updated_at' => now(),
];
}
public function withRole()
{
return $this->afterCreating(function (Praktikan $praktikan) {
$praktikan->assignRole('PRAKTIKAN');
});
}
}
131 changes: 68 additions & 63 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Models\SoalTp;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Spatie\Permission\Models\Role;

class DatabaseSeeder extends Seeder
{
Expand All @@ -24,74 +25,78 @@ class DatabaseSeeder extends Seeder
public function run(): void
{
// First seeding
// Modul::factory(20)->create();
// Role::create(['name' => 'SOFTWARE', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'KORDAS', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'WAKORDAS', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'KOORPRAK', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'ADMIN', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'HARDWARE', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'DDC', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'ATC', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'RDC', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'HRD', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'CMD', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
// Role::create(['name' => 'MLC', 'guard_name' => 'asisten', 'created_at' => now(), 'updated_at' => now()]);
$this->call(RolePermissionsSeeder::class);

Modul::factory(20)->create();

// end Of First Seeding

// ////////////////////////////////////////////////////////////

// Second Seeding
// Kelas::factory(10)->create();

// Asisten::factory(10)->create();
// $asisten = Asisten::factory(90)->withRoles(['SOFTWARE', 'KORDAS', 'WAKORDAS', 'KOORPRAK', 'ADMIN', 'HARDWARE', 'DDC', 'ATC', 'RDC', 'HRD', 'CMD', 'MLC'])->create();

// DB::table('configurations')->insert([
// [
// 'tp_activation' => 1,
// 'tubes_activation' => 0,
// 'polling_activation' => 1,
// 'secretfeature_activation' => 0,
// 'registrationPraktikan_activation' => 1,
// 'registrationAsisten_activation' => 1,
// 'kode_asisten' => 'BOT',
// 'created_at' => now(),
// 'updated_at' => now(),
// ],
// ]);

// // buat polling
// $words = [
// 'Terjaim',
// 'Terasik',
// 'Terganteng',
// 'Tercantik',
// 'Terjamet',
// 'Terwibu',
// 'Tergalak',
// 'Tergalau',
// 'Termager',
// 'Terkocak',
// 'Tergaring',
// 'Tersantuy',
// 'Terimut',
// 'Tercool',
// 'Terpelit',
// 'Terkece',
// 'Terkpop',
// ];

// foreach ($words as $word) {
// DB::table('jenis_pollings')->insert([
// 'judul' => $word,
// 'created_at' => now(),
// 'updated_at' => now(),
// ]);
// }

// // buat kode pelanggaran
Kelas::factory(10)->create();

Asisten::factory(30)
->withRoles([
'SOFTWARE',
'KORDAS',
'WAKORDAS',
'KOORPRAK',
'ADMIN',
'HARDWARE',
'DDC',
'ATC',
'RDC',
'HRD',
'CMD',
'MLC',
])
->create();

DB::table('configurations')->insert([
[
'tp_activation' => 1,
'tubes_activation' => 0,
'polling_activation' => 1,
'secretfeature_activation' => 0,
'registrationPraktikan_activation' => 1,
'registrationAsisten_activation' => 1,
'kode_asisten' => 'BOT',
'created_at' => now(),
'updated_at' => now(),
],
]);

// buat polling
$words = [
'Terjaim',
'Terasik',
'Terganteng',
'Tercantik',
'Terjamet',
'Terwibu',
'Tergalak',
'Tergalau',
'Termager',
'Terkocak',
'Tergaring',
'Tersantuy',
'Terimut',
'Tercool',
'Terpelit',
'Terkece',
'Terkpop',
];

foreach ($words as $word) {
DB::table('jenis_pollings')->insert([
'judul' => $word,
'created_at' => now(),
'updated_at' => now(),
]);
}

// buat kode pelanggaran
// DB::table('kode_pelanggarans')->insert([
// [
// 'pelanggaran' => 'Belum Input Nilai',
Expand All @@ -108,7 +113,7 @@ public function run(): void
// Third Seeding

// // buat praktikan
// Praktikan::factory()->count(30)->create();
Praktikan::factory()->count(30)->withRole()->create();

SoalTp::factory()->count(10)->create(); // Menghasilkan 10 record untuk tabel soal_tps
SoalTa::factory()->count(10)->create(); // Menghasilkan 10 record untuk tabel soal_tas
Expand Down
Loading