partial fix for teacher class progress
API CI/CD / Validate (composer + pint) (push) Successful in 3m9s
API CI/CD / Test (PHPUnit) (push) Failing after 5m6s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 49s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped

This commit is contained in:
root
2026-07-07 22:02:42 -04:00
parent c891a82012
commit 21c9322127
5 changed files with 137 additions and 7 deletions
@@ -151,4 +151,51 @@ class ClassProgressMetaService
return $options;
}
public function unitOptions(?int $classId, ?string $schoolYear = null): array
{
$curriculum = $this->curriculumOptions($classId, $schoolYear);
$units = [];
foreach ($curriculum as $slug => $rows) {
$seen = [];
$units[$slug] = [];
foreach ($rows as $row) {
$unitNumber = $row->unit_number ?? null;
$unitTitle = trim((string) ($row->unit_title ?? ''));
if ($unitNumber === null && $unitTitle === '') {
continue;
}
$key = ((string) $unitNumber).'|'.$unitTitle;
if (isset($seen[$key])) {
continue;
}
$seen[$key] = true;
$units[$slug][] = [
'unit_number' => $unitNumber !== null ? (int) $unitNumber : null,
'unit_title' => $unitTitle,
'label' => $this->formatUnitLabel($unitNumber !== null ? (int) $unitNumber : null, $unitTitle),
];
}
}
return $units;
}
private function formatUnitLabel(?int $unitNumber, string $unitTitle): string
{
if ($unitNumber !== null && $unitTitle !== '') {
return 'Unit '.$unitNumber.' - '.$unitTitle;
}
if ($unitNumber !== null) {
return 'Unit '.$unitNumber;
}
return $unitTitle;
}
}