85 lines
2.6 KiB
PHP
85 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Seeds;
|
|
|
|
use CodeIgniter\Database\Seeder;
|
|
|
|
class AcademicSeeder extends Seeder
|
|
{
|
|
public function run()
|
|
{
|
|
$now = date('Y-m-d H:i:s');
|
|
$todayDayOfWeek = (int) date('N'); // 1=Monday, 7=Sunday
|
|
|
|
// Insert 1 class
|
|
$classData = [
|
|
[
|
|
'name' => 'X IPA 1',
|
|
'grade' => '10',
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
],
|
|
];
|
|
$this->db->table('classes')->insertBatch($classData);
|
|
$classId = $this->db->insertID();
|
|
|
|
// Insert 2 students
|
|
$studentData = [
|
|
[
|
|
'nisn' => '2024001',
|
|
'name' => 'Student One',
|
|
'gender' => 'L',
|
|
'class_id' => $classId,
|
|
'is_active' => 1,
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
],
|
|
[
|
|
'nisn' => '2024002',
|
|
'name' => 'Student Two',
|
|
'gender' => 'P',
|
|
'class_id' => $classId,
|
|
'is_active' => 1,
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
],
|
|
];
|
|
$this->db->table('students')->insertBatch($studentData);
|
|
|
|
// Insert 2 subjects
|
|
$subjectData = [
|
|
[
|
|
'name' => 'Mathematics',
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
],
|
|
[
|
|
'name' => 'Physics',
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
],
|
|
];
|
|
$this->db->table('subjects')->insertBatch($subjectData);
|
|
$subjectIds = $this->db->query('SELECT id FROM subjects ORDER BY id')->getResultArray();
|
|
$mathSubjectId = $subjectIds[0]['id'];
|
|
$physicsSubjectId = $subjectIds[1]['id'];
|
|
|
|
// Insert 1 schedule for today's weekday
|
|
// Schedule: 08:00 - 09:30 for Mathematics
|
|
$scheduleData = [
|
|
[
|
|
'class_id' => $classId,
|
|
'subject_id' => $mathSubjectId,
|
|
'teacher_name' => 'Mr. Mathematics Teacher',
|
|
'day_of_week' => $todayDayOfWeek,
|
|
'start_time' => '08:00:00',
|
|
'end_time' => '09:30:00',
|
|
'room' => 'A101',
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
],
|
|
];
|
|
$this->db->table('schedules')->insertBatch($scheduleData);
|
|
}
|
|
}
|