fix some responses
This commit is contained in:
@@ -19,12 +19,16 @@ class HomeworkScoreService
|
||||
$semester = $this->term->semesterLabel($semester);
|
||||
$schoolYear = $this->term->schoolYear($schoolYear);
|
||||
$semVariants = $this->term->semesterVariants($semester);
|
||||
$schoolYearVariants = $this->term->schoolYearVariants($schoolYear);
|
||||
if (empty($schoolYearVariants)) {
|
||||
$schoolYearVariants = [$schoolYear];
|
||||
}
|
||||
|
||||
$headerRows = Homework::query()
|
||||
->select('homework_index')
|
||||
->where('class_section_id', $classSectionId)
|
||||
->whereIn('semester', $semVariants)
|
||||
->where('school_year', $schoolYear)
|
||||
->whereIn('school_year', $schoolYearVariants)
|
||||
->orderBy('homework_index')
|
||||
->get();
|
||||
|
||||
@@ -32,7 +36,7 @@ class HomeworkScoreService
|
||||
|
||||
$studentIds = StudentClass::query()
|
||||
->where('class_section_id', $classSectionId)
|
||||
->where('school_year', $schoolYear)
|
||||
->whereIn('school_year', $schoolYearVariants)
|
||||
->pluck('student_id')
|
||||
->map(fn ($v) => (int) $v)
|
||||
->all();
|
||||
@@ -55,7 +59,7 @@ class HomeworkScoreService
|
||||
->select('student_id', 'homework_index', 'score')
|
||||
->where('class_section_id', $classSectionId)
|
||||
->whereIn('semester', $semVariants)
|
||||
->where('school_year', $schoolYear)
|
||||
->whereIn('school_year', $schoolYearVariants)
|
||||
->get()
|
||||
->map(fn ($row) => $row->toArray())
|
||||
->all();
|
||||
@@ -78,11 +82,32 @@ class HomeworkScoreService
|
||||
'headers' => $headers,
|
||||
'semester' => $semester,
|
||||
'schoolYear' => $schoolYear,
|
||||
'scoresLocked' => GradingLock::isLocked($classSectionId, $semester, $schoolYear),
|
||||
'missingOkMap' => MissingScoreOverride::getOverridesMap($classSectionId, $semester, $schoolYear, 'homework'),
|
||||
'scoresLocked' => $this->isLockedForAnySchoolYear($classSectionId, $semester, $schoolYearVariants),
|
||||
'missingOkMap' => $this->getMissingOverridesForAnySchoolYear($classSectionId, $semester, $schoolYearVariants),
|
||||
];
|
||||
}
|
||||
|
||||
private function isLockedForAnySchoolYear(int $classSectionId, string $semester, array $schoolYearVariants): bool
|
||||
{
|
||||
foreach ($schoolYearVariants as $year) {
|
||||
if (GradingLock::isLocked($classSectionId, $semester, $year)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getMissingOverridesForAnySchoolYear(int $classSectionId, string $semester, array $schoolYearVariants): array
|
||||
{
|
||||
foreach ($schoolYearVariants as $year) {
|
||||
$map = MissingScoreOverride::getOverridesMap($classSectionId, $semester, $year, 'homework');
|
||||
if (!empty($map)) {
|
||||
return $map;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function update(int $classSectionId, string $semester, string $schoolYear, array $scores, array $missingOk, int $updatedBy): int
|
||||
{
|
||||
if (GradingLock::isLocked($classSectionId, $semester, $schoolYear)) {
|
||||
|
||||
@@ -44,6 +44,24 @@ class ScoreTermService
|
||||
return (string) (Configuration::getConfig('school_year') ?? '');
|
||||
}
|
||||
|
||||
public function schoolYearVariants(?string $input): array
|
||||
{
|
||||
$value = trim((string) $input);
|
||||
if ($value === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$variants = [
|
||||
$value,
|
||||
str_replace('_', '-', $value),
|
||||
str_replace('-', '_', $value),
|
||||
str_replace('/', '-', $value),
|
||||
str_replace('/', '_', $value),
|
||||
];
|
||||
|
||||
return array_values(array_unique(array_filter($variants, static fn ($v) => $v !== '')));
|
||||
}
|
||||
|
||||
public function semesterVariants(?string $semester): array
|
||||
{
|
||||
$raw = trim((string) $semester);
|
||||
|
||||
Reference in New Issue
Block a user