fix attendance
This commit is contained in:
@@ -20,31 +20,21 @@ class SemesterRangeService
|
||||
|
||||
public function getSchoolYearRange(string $schoolYear): array
|
||||
{
|
||||
$fallStart = Configuration::getConfig('fall_semester_start');
|
||||
$lastDay = Configuration::getConfig('last_school_day');
|
||||
|
||||
if ($fallStart && $lastDay) {
|
||||
return [
|
||||
Carbon::parse($fallStart)->toDateString(),
|
||||
Carbon::parse($lastDay)->toDateString(),
|
||||
];
|
||||
}
|
||||
|
||||
[$startYear, $endYear] = $this->parseSchoolYear($schoolYear);
|
||||
$config = $this->ensureAttendanceConfigs($schoolYear);
|
||||
|
||||
return [
|
||||
Carbon::create($startYear, 9, 1)->toDateString(),
|
||||
Carbon::create($endYear, 5, 31)->toDateString(),
|
||||
Carbon::parse($config['fall_semester_start'])->toDateString(),
|
||||
Carbon::parse($config['last_school_day'])->toDateString(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getSemesterRange(string $schoolYear, string $semester): ?array
|
||||
{
|
||||
$semester = $this->normalizeSemester($semester);
|
||||
|
||||
$fallStart = Configuration::getConfig('fall_semester_start');
|
||||
$springStart = Configuration::getConfig('spring_semester_start');
|
||||
$lastDay = Configuration::getConfig('last_school_day');
|
||||
$config = $this->ensureAttendanceConfigs($schoolYear);
|
||||
$fallStart = $config['fall_semester_start'];
|
||||
$springStart = $config['spring_semester_start'];
|
||||
$lastDay = $config['last_school_day'];
|
||||
|
||||
if ($semester === 'Fall' && $fallStart && $springStart) {
|
||||
return [
|
||||
@@ -60,20 +50,7 @@ class SemesterRangeService
|
||||
];
|
||||
}
|
||||
|
||||
// Fallback to hardcoded logic when config keys are missing
|
||||
[$startYear, $endYear] = $this->parseSchoolYear($schoolYear);
|
||||
|
||||
return match ($semester) {
|
||||
'Fall' => [
|
||||
Carbon::create($startYear, 9, 21)->toDateString(),
|
||||
Carbon::create($endYear, 1, 18)->toDateString(),
|
||||
],
|
||||
'Spring' => [
|
||||
Carbon::create($endYear, 1, 25)->toDateString(),
|
||||
Carbon::create($endYear, 5, 31)->toDateString(),
|
||||
],
|
||||
default => null,
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
public function buildSundayList(string $startDate, string $endDate): array
|
||||
@@ -102,7 +79,54 @@ class SemesterRangeService
|
||||
return [(int)$m[1], (int)$m[2]];
|
||||
}
|
||||
|
||||
$configured = trim((string) Configuration::getConfig('school_year'));
|
||||
if (preg_match('/^\s*(\d{4})\s*-\s*(\d{4})\s*$/', $configured, $m)) {
|
||||
return [(int) $m[1], (int) $m[2]];
|
||||
}
|
||||
|
||||
$year = (int) date('Y');
|
||||
$derived = $year . '-' . ($year + 1);
|
||||
Configuration::setConfigValueByKey('school_year', $derived);
|
||||
|
||||
return [$year, $year + 1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the attendance range config keys exist in `configuration`.
|
||||
*
|
||||
* @return array{
|
||||
* school_year:string,
|
||||
* fall_semester_start:string,
|
||||
* spring_semester_start:string,
|
||||
* last_school_day:string
|
||||
* }
|
||||
*/
|
||||
protected function ensureAttendanceConfigs(string $schoolYear): array
|
||||
{
|
||||
[$startYear, $endYear] = $this->parseSchoolYear($schoolYear);
|
||||
|
||||
$resolvedSchoolYear = trim($schoolYear);
|
||||
if ($resolvedSchoolYear === '') {
|
||||
$resolvedSchoolYear = sprintf('%04d-%04d', $startYear, $endYear);
|
||||
}
|
||||
|
||||
$defaults = [
|
||||
'school_year' => $resolvedSchoolYear,
|
||||
'fall_semester_start' => Carbon::create($startYear, 9, 1)->toDateString(),
|
||||
'spring_semester_start' => Carbon::create($endYear, 1, 25)->toDateString(),
|
||||
'last_school_day' => Carbon::create($endYear, 5, 31)->toDateString(),
|
||||
];
|
||||
|
||||
$resolved = [];
|
||||
foreach ($defaults as $key => $defaultValue) {
|
||||
$value = trim((string) Configuration::getConfig($key));
|
||||
if ($value === '') {
|
||||
Configuration::setConfigValueByKey($key, $defaultValue);
|
||||
$value = $defaultValue;
|
||||
}
|
||||
$resolved[$key] = $value;
|
||||
}
|
||||
|
||||
return $resolved;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user