still trying
This commit is contained in:
parent
1f8ea6c159
commit
461ef5375c
@ -88,11 +88,37 @@ foreach($non_break_periods as $idx => $period) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$teacher_timetable_by_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) {
|
foreach ($teacher_schedule_raw as $lesson) {
|
||||||
$day_idx = $lesson['day_of_week'];
|
$day_idx = $lesson['day_of_week'];
|
||||||
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;
|
|
||||||
|
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
|
|||||||
</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>
|
||||||
<td>
|
<td>
|
||||||
<strong><?php echo htmlspecialchars($timeslot['name']); ?></strong><br>
|
<strong><?php echo htmlspecialchars($timeslot['name']); ?></strong><br>
|
||||||
<small class="text-muted"><?php echo date("g:i A", strtotime($timeslot['start_time'])); ?> - <?php echo date("g:i A", strtotime($timeslot['end_time'])); ?></small>
|
<small class="text-muted"><?php echo date("g:i A", strtotime($timeslot['start_time'])); ?> - <?php echo date("g:i A", strtotime($timeslot['end_time'])); ?></small>
|
||||||
</td>
|
</td>
|
||||||
<?php if ($timeslot['is_break']): ?>
|
<?php if ($timeslot['is_break']) : ?>
|
||||||
<td colspan="<?php echo count($days_of_week); ?>" class="text-center table-secondary"><strong>Break</strong></td>
|
<td colspan="<?php echo count($days_of_week); ?>" class="text-center table-secondary"><strong>Break</strong></td>
|
||||||
<?php else: ?>
|
<?php else : ?>
|
||||||
<?php foreach ($days_of_week as $day_idx => $day): ?>
|
<?php for ($day_idx = 0; $day_idx < count($days_of_week); $day_idx++) : ?>
|
||||||
<?php
|
<?php
|
||||||
if (isset($skipped_slots[$day_idx][$period_idx])) {
|
// Check if this cell should be skipped because of a rowspan from a double lesson above it.
|
||||||
continue;
|
$skip_cell = false;
|
||||||
|
if ($period_idx > 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;
|
$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'])) {
|
if ($lesson && !empty($lesson['is_double'])) {
|
||||||
// Check if the next period is available for the double lesson
|
// Check if the next timeslot is not a break to prevent rowspan over a break row
|
||||||
$next_period_idx = $period_idx + 1;
|
$is_next_slot_a_break = false;
|
||||||
$next_lesson = $teacher_timetable_by_period[$day_idx][$next_period_idx] ?? null;
|
$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;
|
$rowspan = 2;
|
||||||
$skipped_slots[$day_idx][$next_period_idx] = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<td class="timetable-slot align-middle" rowspan="<?php echo $rowspan; ?>">
|
<td class="timetable-slot align-middle" rowspan="<?php echo $rowspan; ?>">
|
||||||
<?php
|
<?php if ($lesson): ?>
|
||||||
if ($lesson):
|
<div class="lesson p-1 h-100 d-flex flex-column justify-content-center">
|
||||||
$class_str = '';
|
|
||||||
if ($lesson['is_horizontal_elective']) $class_str = 'bg-light-purple';
|
|
||||||
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';
|
|
||||||
?>
|
|
||||||
<div class="lesson p-1 <?php echo $class_str; ?>">
|
|
||||||
<strong><?php echo htmlspecialchars($lesson['lesson_display_name']); ?></strong><br>
|
<strong><?php echo htmlspecialchars($lesson['lesson_display_name']); ?></strong><br>
|
||||||
<small><?php echo htmlspecialchars($lesson['class_name']); ?></small>
|
<small><?php echo htmlspecialchars($lesson['class_name']); ?></small>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</td>
|
</td>
|
||||||
<?php endforeach; // days_of_week ?>
|
<?php endfor; // day_idx ?>
|
||||||
<?php $period_idx++; ?>
|
<?php $period_idx++; ?>
|
||||||
<?php endif; // is_break ?>
|
<?php endif; // is_break ?>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@ -566,55 +566,50 @@ $class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots, $days_
|
|||||||
$lesson = $class_timetables[$class['id']][$day_idx][$period_idx] ?? null;
|
$lesson = $class_timetables[$class['id']][$day_idx][$period_idx] ?? null;
|
||||||
|
|
||||||
// Logic to determine if cell should be skipped
|
// 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;
|
$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')) {
|
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;
|
||||||
$rowspan = 1;
|
if ($lesson && !empty($lesson['is_double'])) {
|
||||||
if ($lesson && !empty($lesson['is_double'])) {
|
// Check if the next timeslot is not a break to prevent rowspan over a break row
|
||||||
// Check if the next timeslot is not a break to prevent rowspan over a break row
|
$is_next_slot_a_break = false;
|
||||||
$is_next_slot_a_break = false;
|
$current_timeslot_index = -1;
|
||||||
$current_timeslot_index = -1;
|
|
||||||
|
$timeslots_values = array_values($timeslots);
|
||||||
// Find the index of the current timeslot
|
foreach ($timeslots_values as $index => $ts) {
|
||||||
$timeslots_values = array_values($timeslots);
|
if ($ts['id'] === $timeslot['id']) {
|
||||||
foreach ($timeslots_values as $index => $ts) {
|
$current_timeslot_index = $index;
|
||||||
if ($ts['id'] === $timeslot['id']) {
|
break;
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<td class="timetable-slot align-middle" rowspan="<?php echo $rowspan; ?>">
|
||||||
|
<?php
|
||||||
|
if ($lesson) :
|
||||||
|
$css_class = 'lesson p-1 h-100 d-flex flex-column justify-content-center';
|
||||||
|
if (!empty($lesson['is_elective'])) $css_class .= ' is-elective';
|
||||||
|
if (!empty($lesson['is_double'])) $css_class .= ' is-double';
|
||||||
?>
|
?>
|
||||||
<td class="timetable-slot align-middle" rowspan="<?php echo $rowspan; ?>">
|
<div class="<?php echo $css_class; ?>" data-lesson-id="<?php echo $lesson['id'] ?? ''; ?>">
|
||||||
<?php
|
<strong><?php echo htmlspecialchars($lesson['subject_name']); ?></strong><br>
|
||||||
if ($lesson) :
|
<small><?php echo htmlspecialchars($lesson['teacher_name']); ?></small>
|
||||||
$css_class = 'lesson p-1 h-100 d-flex flex-column justify-content-center';
|
</div>
|
||||||
if (!empty($lesson['is_elective'])) $css_class .= ' is-elective';
|
<?php endif; ?>
|
||||||
if (!empty($lesson['is_double'])) $css_class .= ' is-double';
|
</td>
|
||||||
?>
|
|
||||||
<div class="<?php echo $css_class; ?>" data-lesson-id="<?php echo $lesson['id'] ?? ''; ?>">
|
|
||||||
<strong><?php echo htmlspecialchars($lesson['subject_name']); ?></strong><br>
|
|
||||||
<small><?php echo htmlspecialchars($lesson['teacher_name']); ?></small>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
||||||
</td>
|
|
||||||
<?php endif; // if !skip_cell ?>
|
|
||||||
<?php endfor; // day_idx ?>
|
<?php endfor; // day_idx ?>
|
||||||
<?php $period_idx++; ?>
|
<?php $period_idx++; ?>
|
||||||
<?php endif; // is_break ?>
|
<?php endif; // is_break ?>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user