From 1f8ea6c15930b084c9c62d6d34e9ae812c2b3659 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 6 Dec 2025 19:08:45 +0000 Subject: [PATCH] still in circles --- teacher_timetable.php | 77 ++++++++++--------------------------------- 1 file changed, 17 insertions(+), 60 deletions(-) diff --git a/teacher_timetable.php b/teacher_timetable.php index d960ba2..8093d60 100644 --- a/teacher_timetable.php +++ b/teacher_timetable.php @@ -17,7 +17,7 @@ function get_timeslots($pdo) { function get_teacher_schedule($pdo, $teacher_id, $school_id) { $stmt = $pdo->prepare(" SELECT - s.id, // Gemini: Added for double lesson check + s.id, s.day_of_week, s.timeslot_id, s.lesson_display_name, @@ -93,36 +93,6 @@ foreach ($teacher_schedule_raw as $lesson) { if (isset($timeslot_id_to_period_idx[$lesson['timeslot_id']])) { $period_idx = $timeslot_id_to_period_idx[$lesson['timeslot_id']]; $teacher_timetable_by_period[$day_idx][$period_idx] = $lesson; - - // If it's a double lesson, we need to fill the next period as well - if ($lesson['is_double']) { - if (isset($teacher_timetable_by_period[$day_idx][$period_idx + 1])) { - // This should not happen with valid data, but as a safeguard - continue; - } - // Find the next timeslot that is not a break - $current_timeslot_index = -1; - $timeslots_values = array_values($timeslots); - foreach ($timeslots_values as $index => $ts) { - if ($ts['id'] === $lesson['timeslot_id']) { - $current_timeslot_index = $index; - break; - } - } - - if ($current_timeslot_index !== -1 && isset($timeslots_values[$current_timeslot_index + 1])) { - $next_timeslot = $timeslots_values[$current_timeslot_index + 1]; - if (!$next_timeslot['is_break']) { - if(isset($timeslot_id_to_period_idx[$next_timeslot['id']])) { - $next_period_idx = $timeslot_id_to_period_idx[$next_timeslot['id']]; - // Ensure the next period is consecutive - if ($next_period_idx === $period_idx + 1) { - $teacher_timetable_by_period[$day_idx][$next_period_idx] = $lesson; - } - } - } - } - } } } @@ -209,6 +179,7 @@ error_log("Final teacher_timetable_by_period structure: " . print_r($teacher_tim true $period_idx = 0; foreach ($timeslots as $timeslot): ?> @@ -221,37 +192,23 @@ error_log("Final teacher_timetable_by_period structure: " . print_r($teacher_tim $day): ?> 0) ? ($teacher_timetable_by_period[$day_idx][$period_idx - 1] ?? null) : null; - if ($lesson_above && !empty($lesson_above['is_double']) && ($lesson_above['id'] ?? 'a') === ($lesson['id'] ?? 'b')) { - $skip_cell = true; + if (isset($skipped_slots[$day_idx][$period_idx])) { + continue; } + + $lesson = $teacher_timetable_by_period[$day_idx][$period_idx] ?? null; + $rowspan = 1; - if (!$skip_cell): - $rowspan = 1; - if ($lesson && !empty($lesson['is_double'])) { - $is_next_slot_a_break = false; - $current_timeslot_index = -1; - $timeslots_values = array_values($timeslots); - foreach ($timeslots_values as $index => $ts) { - if ($ts['id'] === $timeslot['id']) { - $current_timeslot_index = $index; - break; - } - } - if ($current_timeslot_index !== -1 && isset($timeslots_values[$current_timeslot_index + 1])) { - $next_timeslot = $timeslots_values[$current_timeslot_index + 1]; - if ($next_timeslot['is_break']) { - $is_next_slot_a_break = true; - } - } - if (!$is_next_slot_a_break) { - $rowspan = 2; - } + if ($lesson && !empty($lesson['is_double'])) { + // Check if the next period is available for the double lesson + $next_period_idx = $period_idx + 1; + $next_lesson = $teacher_timetable_by_period[$day_idx][$next_period_idx] ?? null; + + if ($next_lesson && $next_lesson['id'] === $lesson['id']) { + $rowspan = 2; + $skipped_slots[$day_idx][$next_period_idx] = true; } + } ?>
@@ -267,7 +225,6 @@ error_log("Final teacher_timetable_by_period structure: " . print_r($teacher_tim
-