fix some responses

This commit is contained in:
root
2026-03-11 18:44:16 -04:00
parent 2ef71cc92b
commit 863e330dd8
7 changed files with 415 additions and 17 deletions
+12 -1
View File
@@ -11,8 +11,9 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;
use Laravel\Sanctum\HasApiTokens;
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable
class User extends Authenticatable implements JWTSubject
{
use HasApiTokens;
use HasFactory;
@@ -65,6 +66,16 @@ class User extends Authenticatable
'updated_at' => 'datetime',
];
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
/* ============================================================
* Relationships
* ============================================================
+30 -5
View File
@@ -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)) {
+18
View File
@@ -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);