still in circles

This commit is contained in:
Flatlogic Bot 2025-12-06 19:08:45 +00:00
parent a254737287
commit 1f8ea6c159

View File

@ -17,7 +17,7 @@ function get_timeslots($pdo) {
function get_teacher_schedule($pdo, $teacher_id, $school_id) { function get_teacher_schedule($pdo, $teacher_id, $school_id) {
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
SELECT SELECT
s.id, // Gemini: Added for double lesson check s.id,
s.day_of_week, s.day_of_week,
s.timeslot_id, s.timeslot_id,
s.lesson_display_name, s.lesson_display_name,
@ -93,36 +93,6 @@ 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']];
$teacher_timetable_by_period[$day_idx][$period_idx] = $lesson; $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
</thead> </thead>
<tbody> <tbody>
<?php <?php
$skipped_slots = []; // [day_idx][period_idx] => true
$period_idx = 0; $period_idx = 0;
foreach ($timeslots as $timeslot): ?> foreach ($timeslots as $timeslot): ?>
<tr> <tr>
@ -221,35 +192,21 @@ error_log("Final teacher_timetable_by_period structure: " . print_r($teacher_tim
<?php else: ?> <?php else: ?>
<?php foreach ($days_of_week as $day_idx => $day): ?> <?php foreach ($days_of_week as $day_idx => $day): ?>
<?php <?php
if (isset($skipped_slots[$day_idx][$period_idx])) {
continue;
}
$lesson = $teacher_timetable_by_period[$day_idx][$period_idx] ?? null; $lesson = $teacher_timetable_by_period[$day_idx][$period_idx] ?? null;
// Logic to skip rendering the cell if it's the second part of a double lesson
$skip_cell = false;
$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')) {
$skip_cell = true;
}
if (!$skip_cell):
$rowspan = 1; $rowspan = 1;
if ($lesson && !empty($lesson['is_double'])) { if ($lesson && !empty($lesson['is_double'])) {
$is_next_slot_a_break = false; // Check if the next period is available for the double lesson
$current_timeslot_index = -1; $next_period_idx = $period_idx + 1;
$timeslots_values = array_values($timeslots); $next_lesson = $teacher_timetable_by_period[$day_idx][$next_period_idx] ?? null;
foreach ($timeslots_values as $index => $ts) {
if ($ts['id'] === $timeslot['id']) { if ($next_lesson && $next_lesson['id'] === $lesson['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; $rowspan = 2;
$skipped_slots[$day_idx][$next_period_idx] = true;
} }
} }
?> ?>
@ -259,6 +216,7 @@ error_log("Final teacher_timetable_by_period structure: " . print_r($teacher_tim
$class_str = ''; $class_str = '';
if ($lesson['is_horizontal_elective']) $class_str = 'bg-light-purple'; if ($lesson['is_horizontal_elective']) $class_str = 'bg-light-purple';
elseif ($lesson['is_elective']) $class_str = 'bg-light-green'; elseif ($lesson['is_elective']) $class_str = 'bg-light-green';
// Use a different color for double lessons to distinguish them
elseif ($lesson['is_double']) $class_str = 'bg-light-blue'; elseif ($lesson['is_double']) $class_str = 'bg-light-blue';
?> ?>
<div class="lesson p-1 <?php echo $class_str; ?>"> <div class="lesson p-1 <?php echo $class_str; ?>">
@ -267,7 +225,6 @@ error_log("Final teacher_timetable_by_period structure: " . print_r($teacher_tim
</div> </div>
<?php endif; ?> <?php endif; ?>
</td> </td>
<?php endif; // if !skip_cell ?>
<?php endforeach; // days_of_week ?> <?php endforeach; // days_of_week ?>
<?php $period_idx++; ?> <?php $period_idx++; ?>
<?php endif; // is_break ?> <?php endif; // is_break ?>