fix attendance spring days
This commit is contained in:
@@ -1566,35 +1566,31 @@ class ReportCardsController extends PrintablesBaseController
|
|||||||
$semRange = $this->semesterRangeService->getSemesterRange($refYear, ucfirst($normSemester));
|
$semRange = $this->semesterRangeService->getSemesterRange($refYear, ucfirst($normSemester));
|
||||||
if ($semRange) {
|
if ($semRange) {
|
||||||
try {
|
try {
|
||||||
$events = $this->calendarModel->getEventsBySchoolYearAndSemester($refYear, $normSemester);
|
// Fetch all events for the year (no semester filter) so that
|
||||||
|
// no-school events stored with a different semester label or
|
||||||
|
// NULL semester are still picked up. Date-range filtering below.
|
||||||
|
$events = $this->calendarModel->getEventsBySchoolYearAndSemester($refYear, null);
|
||||||
$noSchoolDays = [];
|
$noSchoolDays = [];
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
if (empty($event['no_school'])) {
|
if (empty($event['no_school'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$dateStr = substr((string)($event['date'] ?? ''), 0, 10);
|
$dateStr = substr((string)($event['date'] ?? ''), 0, 10);
|
||||||
if ($dateStr === '') {
|
if ($dateStr === '' || $dateStr < $semRange[0] || $dateStr > $semRange[1]) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$eventDate = new \DateTime($dateStr);
|
|
||||||
} catch (\Throwable) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($eventDate->format('N') !== '7') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($dateStr < $semRange[0] || $dateStr > $semRange[1]) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$noSchoolDays[$dateStr] = true;
|
$noSchoolDays[$dateStr] = true;
|
||||||
}
|
}
|
||||||
$sundays = $this->listSundays($semRange[0], $semRange[1]);
|
$sundays = $this->listSundays($semRange[0], $semRange[1]);
|
||||||
$anchor = $this->resolveAnchorSunday();
|
|
||||||
$limit = $semRange[1];
|
$limit = $semRange[1];
|
||||||
|
// Only cap at "today" while the semester is still in progress.
|
||||||
|
// Once the semester end date has passed, count all its Sundays.
|
||||||
|
if ($semRange[1] > date('Y-m-d')) {
|
||||||
|
$anchor = $this->resolveAnchorSunday();
|
||||||
if ($anchor !== '' && $anchor >= $semRange[0]) {
|
if ($anchor !== '' && $anchor >= $semRange[0]) {
|
||||||
$limit = min($anchor, $semRange[1]);
|
$limit = min($anchor, $semRange[1]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$totalSemesterDays = 0;
|
$totalSemesterDays = 0;
|
||||||
foreach ($sundays as $date) {
|
foreach ($sundays as $date) {
|
||||||
if ($date > $limit) {
|
if ($date > $limit) {
|
||||||
|
|||||||
@@ -72,11 +72,26 @@ class SemesterRangeService
|
|||||||
$y1 = (int)$m[1];
|
$y1 = (int)$m[1];
|
||||||
$y2 = (int)$m[2];
|
$y2 = (int)$m[2];
|
||||||
$normalized = ucfirst(strtolower(trim($semester)));
|
$normalized = ucfirst(strtolower(trim($semester)));
|
||||||
|
|
||||||
|
$fallStartCfg = (string)($this->configModel->getConfig('fall_semester_start') ?? '');
|
||||||
|
$fallEndCfg = (string)($this->configModel->getConfig('fall_end_date') ?? '');
|
||||||
|
$springStartCfg = (string)($this->configModel->getConfig('spring_semester_start') ?? '');
|
||||||
|
$springEndCfg = (string)($this->configModel->getConfig('last_school_day') ?? '');
|
||||||
|
|
||||||
|
$md = static fn(string $cfg, int $year, string $fallback): string =>
|
||||||
|
$cfg !== '' ? sprintf('%04d-%s', $year, date('m-d', strtotime($cfg))) : $fallback;
|
||||||
|
|
||||||
if ($normalized === 'Fall') {
|
if ($normalized === 'Fall') {
|
||||||
return [sprintf('%04d-09-21', $y1), sprintf('%04d-01-18', $y2)];
|
return [
|
||||||
|
$md($fallStartCfg, $y1, sprintf('%04d-09-21', $y1)),
|
||||||
|
$md($fallEndCfg, $y2, sprintf('%04d-01-18', $y2)),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
if ($normalized === 'Spring') {
|
if ($normalized === 'Spring') {
|
||||||
return [sprintf('%04d-01-25', $y2), sprintf('%04d-05-31', $y2)];
|
return [
|
||||||
|
$md($springStartCfg, $y2, sprintf('%04d-01-25', $y2)),
|
||||||
|
$md($springEndCfg, $y2, sprintf('%04d-05-31', $y2)),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user