58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Carbon\Carbon;
|
|
|
|
class DummyJadwalSeeder extends Seeder
|
|
{
|
|
public function run()
|
|
{
|
|
$start = Carbon::now()->startOfWeek(); // Senin minggu ini
|
|
$gurus = DB::table('guru')->pluck('id')->toArray();
|
|
$kelass = DB::table('kelas')->get();
|
|
$ruangans = DB::table('ruangan')->pluck('id')->toArray();
|
|
$sesis = DB::table('sesi')->pluck('id')->toArray();
|
|
|
|
if (empty($gurus) || empty($kelass) || empty($sesis)) {
|
|
return;
|
|
}
|
|
|
|
foreach ($kelass as $idx => $k) {
|
|
$dayOffset = $idx % 6; // Senin - Sabtu
|
|
$hari = $dayOffset + 1; // 1: Senin, ..., 6: Sabtu
|
|
$sesiId = $sesis[$idx % count($sesis)];
|
|
$guruId = $gurus[$idx % count($gurus)];
|
|
$ruanganId = !empty($ruangans) ? $ruangans[$idx % count($ruangans)] : null;
|
|
$tgl = $start->copy()->addDays($dayOffset)->format('Y-m-d');
|
|
|
|
DB::table('jadwal_kelas')->insert([
|
|
'kelas_id' => $k->id,
|
|
'hari' => $hari,
|
|
'sesi_id' => $sesiId,
|
|
'ruangan_id' => $ruanganId,
|
|
'guru_id' => $guruId,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
DB::table('logbook')->insert([
|
|
'kelas_id' => $k->id,
|
|
'kode_kelas' => $k->kode_kelas,
|
|
'guru_id' => $guruId,
|
|
'ruangan_id' => $ruanganId,
|
|
'sesi_id' => $sesiId,
|
|
'tanggal' => $tgl,
|
|
'pertemuan' => '1',
|
|
'materi' => 'Robot Soccer & Basic Electronics - Sesi ' . ($idx + 1),
|
|
'kegiatan_minggu_ini' => 'Perakitan komponen dasar, pemrograman sensor, dan simulasi gerak.',
|
|
'status' => 'completed',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
}
|
|
}
|