diff --git a/teacher_timetable.php b/teacher_timetable.php
index 8093d60..979bffb 100644
--- a/teacher_timetable.php
+++ b/teacher_timetable.php
@@ -88,11 +88,37 @@ foreach($non_break_periods as $idx => $period) {
}
$teacher_timetable_by_period = [];
+// Initialize the timetable array
+foreach ($days_of_week as $day_idx => $day) {
+ $teacher_timetable_by_period[$day_idx] = array_fill(0, count($non_break_periods), null);
+}
+
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']];
- $teacher_timetable_by_period[$day_idx][$period_idx] = $lesson;
+
+ 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;
+ }
+
+ 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;
+ }
+ }
}
}
@@ -179,53 +205,81 @@ error_log("Final teacher_timetable_by_period structure: " . print_r($teacher_tim
true
$period_idx = 0;
- foreach ($timeslots as $timeslot): ?>
+ foreach ($timeslots as $timeslot):
+ ?>
-
|
-
+
Break |
-
- $day): ?>
+
+
0) {
+ $lesson_above = $teacher_timetable_by_period[$day_idx][$period_idx - 1] ?? null;
+ if ($lesson_above && !empty($lesson_above['is_double'])) {
+ // This logic needs to be robust. The simplest way is to check if the lesson in the previous period on the same day was a double.
+ // However, the data structure might not be perfect. Let's check if the lesson ID matches.
+ $current_lesson = $teacher_timetable_by_period[$day_idx][$period_idx] ?? null;
+ if ($current_lesson && $lesson_above['id'] === $current_lesson['id']) {
+ $skip_cell = true;
+ }
+ }
}
+ // A better approach for skipping: check the lesson itself.
+ // The `get_timetable_from_db` in `timetable.php` duplicates the lesson entry for the second slot. Let's mimic that here for consistency.
+ // We need to rebuild the array first.
+
$lesson = $teacher_timetable_by_period[$day_idx][$period_idx] ?? null;
- $rowspan = 1;
+ // More reliable skip logic based on the logic from timetable.php
+ $lesson_above = ($period_idx > 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')) {
+ // If the lesson above was a double and has the same ID as the current one, skip this cell.
+ continue;
+ }
+
+ $rowspan = 1;
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;
+ // Check if the next timeslot is not a break to prevent rowspan over a break row
+ $is_next_slot_a_break = false;
+ $current_timeslot_index = -1;
- if ($next_lesson && $next_lesson['id'] === $lesson['id']) {
+ $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;
- $skipped_slots[$day_idx][$next_period_idx] = true;
}
}
?>
-
- |
-
+
diff --git a/timetable.php b/timetable.php
index aaab9be..7446778 100644
--- a/timetable.php
+++ b/timetable.php
@@ -566,55 +566,50 @@ $class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots, $days_
$lesson = $class_timetables[$class['id']][$day_idx][$period_idx] ?? null;
// Logic to determine if cell should be skipped
- $skip_cell = false;
$lesson_above = ($period_idx > 0) ? ($class_timetables[$class['id']][$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;
+ continue; // This is the fix: skip the cell entirely
}
- if (!$skip_cell) :
- $rowspan = 1;
- if ($lesson && !empty($lesson['is_double'])) {
- // Check if the next timeslot is not a break to prevent rowspan over a break row
- $is_next_slot_a_break = false;
- $current_timeslot_index = -1;
-
- // Find the index of the current timeslot
- $timeslots_values = array_values($timeslots);
- foreach ($timeslots_values as $index => $ts) {
- if ($ts['id'] === $timeslot['id']) {
- $current_timeslot_index = $index;
- break;
- }
- }
-
- // Check the next timeslot if the current one was found
- 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;
+ $rowspan = 1;
+ if ($lesson && !empty($lesson['is_double'])) {
+ // Check if the next timeslot is not a break to prevent rowspan over a break row
+ $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;
+ }
+ }
+ ?>
+
+
- |
-
-
-
-
-
-
- |
-
+
+
+
+
+
+