End is very near

This commit is contained in:
Flatlogic Bot 2025-12-07 10:47:12 +00:00
parent 403c8e4f27
commit 9ab9dfefba
2 changed files with 57 additions and 36 deletions

View File

@ -104,25 +104,23 @@ foreach ($teacher_schedule_raw as $lesson) {
if (isset($timeslot_id_to_period_idx[$lesson['timeslot_id']])) { if (isset($timeslot_id_to_period_idx[$lesson['timeslot_id']])) {
$period_idx = $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])) { // Skip if this slot is already filled by a continuation marker
// This slot is already filled, potentially by a multi-class elective. if (isset($teacher_timetable_by_period[$day_idx][$period_idx]) && isset($teacher_timetable_by_period[$day_idx][$period_idx]['continuation'])) {
// Create an array if it's not already one. continue;
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])) { // Place the lesson. Handle co-teaching by making it an array.
if (isset($teacher_timetable_by_period[$day_idx][$period_idx + 1])) { if (!isset($teacher_timetable_by_period[$day_idx][$period_idx]) || $teacher_timetable_by_period[$day_idx][$period_idx] === null) {
if (!is_array($teacher_timetable_by_period[$day_idx][$period_idx + 1])) { $teacher_timetable_by_period[$day_idx][$period_idx] = [$lesson];
$teacher_timetable_by_period[$day_idx][$period_idx + 1] = [$teacher_timetable_by_period[$day_idx][$period_idx + 1]]; } else {
} $teacher_timetable_by_period[$day_idx][$period_idx][] = $lesson;
$teacher_timetable_by_period[$day_idx][$period_idx + 1][] = $lesson; }
} else {
$teacher_timetable_by_period[$day_idx][$period_idx + 1] = $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
<small class="text-muted"><?php echo date("g:i A", strtotime($timeslot_info['start_time'])); ?> - <?php echo date("g:i A", strtotime($timeslot_info['end_time'])); ?></small> <small class="text-muted"><?php echo date("g:i A", strtotime($timeslot_info['start_time'])); ?> - <?php echo date("g:i A", strtotime($timeslot_info['end_time'])); ?></small>
</td> </td>
<?php foreach ($days_of_week as $day_idx => $day): ?> <?php foreach ($days_of_week as $day_idx => $day): ?>
<td class="timetable-slot align-middle"> <?php
<?php $lessons = $teacher_timetable_by_period[$day_idx][$period_idx] ?? null;
$lesson = $teacher_timetable_by_period[$day_idx][$period_idx] ?? null;
if ($lesson) { if (isset($lessons['continuation'])) {
// If it's an array of lessons (co-teaching), display them all // This is a continuation of a double lesson, so we skip rendering the cell.
$lessons_to_display = is_array($lesson) && !isset($lesson['id']) ? $lesson : [$lesson]; } else {
foreach ($lessons_to_display as $single_lesson) { $rowspan = 1;
if ($single_lesson) { // Check not null // Check if any lesson in this slot is a double lesson
$display_name = $single_lesson['lesson_display_name']; if (is_array($lessons)) {
// For electives, the teacher should see their specific subject. foreach ($lessons as $l) {
if (!empty($single_lesson['is_elective']) && !empty($single_lesson['subject_name'])) { if (!empty($l['is_double'])) {
$display_name = $single_lesson['subject_name']; $rowspan = 2;
break;
} }
echo '<div class="lesson p-1 mb-1">';
echo '<strong>' . htmlspecialchars($display_name) . '</strong><br>';
echo '<small>' . htmlspecialchars($single_lesson['class_name']) . '</small>';
echo '</div>';
} }
} }
?>
<td class="timetable-slot align-middle" rowspan="<?php echo $rowspan; ?>">
<?php
if (is_array($lessons)) {
foreach ($lessons as $single_lesson) {
if ($single_lesson) { // Check not null
$display_name = $single_lesson['lesson_display_name'];
// For electives, the teacher should see their specific subject.
if (!empty($single_lesson['is_elective']) && !empty($single_lesson['subject_name'])) {
$display_name = $single_lesson['subject_name'];
}
echo '<div class="lesson p-1 mb-1">';
echo '<strong>' . htmlspecialchars($display_name) . '</strong><br>';
echo '<small>' . htmlspecialchars($single_lesson['class_name']) . '</small>';
echo '</div>';
}
}
}
?>
</td>
<?php
} }
?> ?>
</td>
<?php endforeach; ?> <?php endforeach; ?>
</tr> </tr>
<?php <?php

View File

@ -464,7 +464,13 @@ function get_timetable_from_db($pdo, $classes, $timeslots, $days_of_week) {
$class_timetables[$class_id][$day_idx][$period_idx] = $lesson_data; $class_timetables[$class_id][$day_idx][$period_idx] = $lesson_data;
if ($lesson_data['is_double'] && isset($class_timetables[$class_id][$day_idx][$period_idx + 1])) { if ($lesson_data['is_double'] && isset($class_timetables[$class_id][$day_idx][$period_idx + 1])) {
$class_timetables[$class_id][$day_idx][$period_idx + 1] = $lesson_data; // For the second part of a double lesson, create a new array
// that is marked as a continuation, but does NOT have is_double = true.
// This prevents the rendering logic from trying to start a new rowspan.
$continuation_data = $lesson_data;
$continuation_data['is_double'] = false;
$continuation_data['is_continuation'] = true;
$class_timetables[$class_id][$day_idx][$period_idx + 1] = $continuation_data;
} }
} }