diff --git a/teacher_timetable.php b/teacher_timetable.php index d86497a..a7be905 100644 --- a/teacher_timetable.php +++ b/teacher_timetable.php @@ -103,26 +103,24 @@ foreach ($teacher_schedule_raw as $lesson) { $day_idx = $lesson['day_of_week']; if (isset($timeslot_id_to_period_idx[$lesson['timeslot_id']])) { $period_idx = $timeslot_id_to_period_idx[$lesson['timeslot_id']]; - - if (isset($teacher_timetable_by_period[$day_idx][$period_idx])) { - // This slot is already filled, potentially by a multi-class elective. - // Create an array if it's not already one. - if (!is_array($teacher_timetable_by_period[$day_idx][$period_idx])) { - $teacher_timetable_by_period[$day_idx][$period_idx] = [$teacher_timetable_by_period[$day_idx][$period_idx]]; - } - $teacher_timetable_by_period[$day_idx][$period_idx][] = $lesson; - } else { - $teacher_timetable_by_period[$day_idx][$period_idx] = $lesson; + + // Skip if this slot is already filled by a continuation marker + if (isset($teacher_timetable_by_period[$day_idx][$period_idx]) && isset($teacher_timetable_by_period[$day_idx][$period_idx]['continuation'])) { + continue; } - if (!empty($lesson['is_double']) && isset($teacher_timetable_by_period[$day_idx][$period_idx + 1])) { - if (isset($teacher_timetable_by_period[$day_idx][$period_idx + 1])) { - if (!is_array($teacher_timetable_by_period[$day_idx][$period_idx + 1])) { - $teacher_timetable_by_period[$day_idx][$period_idx + 1] = [$teacher_timetable_by_period[$day_idx][$period_idx + 1]]; - } - $teacher_timetable_by_period[$day_idx][$period_idx + 1][] = $lesson; - } else { - $teacher_timetable_by_period[$day_idx][$period_idx + 1] = $lesson; + // Place the lesson. Handle co-teaching by making it an array. + if (!isset($teacher_timetable_by_period[$day_idx][$period_idx]) || $teacher_timetable_by_period[$day_idx][$period_idx] === null) { + $teacher_timetable_by_period[$day_idx][$period_idx] = [$lesson]; + } else { + $teacher_timetable_by_period[$day_idx][$period_idx][] = $lesson; + } + + if (!empty($lesson['is_double'])) { + $next_period_idx = $period_idx + 1; + if (isset($non_break_periods[$next_period_idx])) { + $continuation_marker = ['continuation' => true, 'original_lesson' => $lesson]; + $teacher_timetable_by_period[$day_idx][$next_period_idx] = $continuation_marker; } } } @@ -234,28 +232,45 @@ error_log("Final teacher_timetable_by_period structure: " . print_r($teacher_tim - $day): ?> - - '; - echo '' . htmlspecialchars($display_name) . '
'; - echo '' . htmlspecialchars($single_lesson['class_name']) . ''; - echo ''; } } + ?> + + '; + echo '' . htmlspecialchars($display_name) . '
'; + echo '' . htmlspecialchars($single_lesson['class_name']) . ''; + echo ''; + } + } + } + ?> + + -