fix school year and enrollment steps
Tests / PHPUnit (push) Failing after 58s

This commit is contained in:
root
2026-08-15 21:15:05 -04:00
parent 4603d9ced2
commit 3cbfc40934
18 changed files with 1142 additions and 163 deletions
@@ -52,6 +52,7 @@ class ParentReportCardController extends BaseController
$studentIds = array_values(array_filter(array_map(static fn ($s) => (int) ($s['id'] ?? 0), $students)));
$ackMap = [];
$reportAvailableMap = $this->reportAvailabilityMap($studentIds, $schoolYear, $semester);
if (! empty($studentIds)) {
$rows = $this->ackModel
->where('parent_id', $parentId)
@@ -67,6 +68,7 @@ class ParentReportCardController extends BaseController
return view('parent/report_cards', [
'students' => $students,
'ackMap' => $ackMap,
'reportAvailableMap' => $reportAvailableMap,
'schoolYear' => $schoolYear,
'semester' => $semester,
'isEditable' => ! $schoolYearContext->isReadonly(),
@@ -89,6 +91,11 @@ class ParentReportCardController extends BaseController
$schoolYear = trim($schoolYearContext->yearName());
$semester = trim((string) ($this->request->getGet('semester') ?? $this->configModel->getConfig('semester') ?? ''));
if (! $this->reportExists((int) $studentId, $schoolYear, $semester)) {
return redirect()->to(site_url('parent/report-cards'))
->with('error', 'No report card exists for the selected school year and semester.');
}
if (! $schoolYearContext->isReadonly()) {
$this->touchAcknowledgement($parentId, (int) $studentId, $schoolYear, $semester, [
'viewed_at' => date('Y-m-d H:i:s'),
@@ -136,6 +143,12 @@ class ParentReportCardController extends BaseController
$schoolYear = trim($schoolYearContext->yearName());
$semester = trim((string) ($this->configModel->getConfig('semester') ?? ''));
if (! $this->reportExists((int) $studentId, $schoolYear, $semester)) {
return redirect()->to(site_url('parent/report-cards'))
->with('error', 'No report card exists for the selected school year and semester.');
}
$now = date('Y-m-d H:i:s');
$this->touchAcknowledgement($parentId, (int) $studentId, $schoolYear, $semester, [
'viewed_at' => $now,
@@ -173,6 +186,80 @@ class ParentReportCardController extends BaseController
return $parentId ?: null;
}
protected function reportAvailabilityMap(array $studentIds, string $schoolYear, string $semester): array
{
$studentIds = array_values(array_filter(array_map('intval', $studentIds), static fn ($id) => $id > 0));
if (empty($studentIds) || $schoolYear === '') {
return [];
}
$builder = $this->db->table('semester_scores')
->select('student_id')
->whereIn('student_id', $studentIds)
->where('school_year', $schoolYear);
$semesterVariants = $this->semesterVariants($semester);
if (! empty($semesterVariants)) {
$builder->whereIn('semester', $semesterVariants);
}
$rows = $builder
->groupBy('student_id')
->get()
->getResultArray();
$map = [];
foreach ($rows as $row) {
$sid = (int) ($row['student_id'] ?? 0);
if ($sid > 0) {
$map[$sid] = true;
}
}
return $map;
}
protected function reportExists(int $studentId, string $schoolYear, string $semester): bool
{
if ($studentId <= 0 || $schoolYear === '') {
return false;
}
$builder = $this->db->table('semester_scores')
->select('id')
->where('student_id', $studentId)
->where('school_year', $schoolYear)
->limit(1);
$semesterVariants = $this->semesterVariants($semester);
if (! empty($semesterVariants)) {
$builder->whereIn('semester', $semesterVariants);
}
return (bool) $builder->get()->getRowArray();
}
protected function semesterVariants(string $semester): array
{
$raw = trim($semester);
if ($raw === '') {
return [];
}
$normalized = strtolower($raw);
if ($normalized === 'fall' || $normalized === 'first' || str_contains($normalized, 'fall') || str_contains($normalized, '1')) {
$values = ['Fall', 'fall', 'First', 'first', 'Semester 1', 'semester 1', 'Semester1', 'semester1', 'Sem 1', 'sem 1', '1', '01', 'S1', 's1'];
} elseif ($normalized === 'spring' || $normalized === 'second' || str_contains($normalized, 'spring') || str_contains($normalized, '2')) {
$values = ['Spring', 'spring', 'Second', 'second', 'Semester 2', 'semester 2', 'Semester2', 'semester2', 'Sem 2', 'sem 2', '2', '02', 'S2', 's2'];
} else {
$values = [$raw];
}
$values[] = $raw;
return array_values(array_unique($values));
}
protected function touchAcknowledgement(
int $parentId,
int $studentId,