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
+22 -14
View File
@@ -1224,12 +1224,6 @@ $scoresEndY = $pdf->GetY();
public function generateSingleReport($studentId)
{
// Prevent Debug Toolbar from corrupting PDF
if (ENVIRONMENT !== 'production') {
// Turn off toolbar manually by unsetting the collector
unset(service('toolbar')->collectors['CodeIgniter\Debug\Toolbar\Collectors\Timers']);
}
$download = $this->request->getGet('download') === '1';
$schoolYear = $this->request->getGet('school_year') ?? $this->schoolYear;
$semester = $this->request->getGet('semester') ?? $this->semester;
@@ -1237,7 +1231,7 @@ $scoresEndY = $pdf->GetY();
$data = $this->prepareStudentReportData((int)$studentId, (string)$schoolYear, (string)$semester);
if (!$data) {
return "Student not found or missing scores.";
return $this->missingReportResponse((int)$studentId, (string)$schoolYear, (string)$semester);
}
$data['report_date'] = $reportDate['iso'];
$data['report_date_display'] = $reportDate['display'];
@@ -1264,12 +1258,6 @@ $scoresEndY = $pdf->GetY();
public function generateClassReport($classSectionId)
{
// Disable toolbar output to prevent PDF corruption
if (ENVIRONMENT !== 'production') {
unset(service('toolbar')->collectors['CodeIgniter\Debug\Toolbar\Collectors\Timers']);
}
$download = $this->request->getGet('download') === '1';
$schoolYear = $this->request->getGet('school_year') ?? $this->schoolYear;
$semester = $this->request->getGet('semester') ?? $this->semester;
@@ -1290,10 +1278,11 @@ $scoresEndY = $pdf->GetY();
->findAll();
if (!$scores) {
return "No students found for this class section.";
return $this->missingReportResponse(null, (string)$schoolYear, (string)$semester, (int)$classSectionId);
}
$pdf = new \FPDF('P', 'mm', 'Letter');
$generatedCount = 0;
foreach ($scores as $score) {
$studentId = $score['student_id'];
@@ -1304,9 +1293,14 @@ $scoresEndY = $pdf->GetY();
$data['report_date'] = $reportDate['iso'];
$data['report_date_display'] = $reportDate['display'];
$this->formatReportPDF($pdf, $data);
$generatedCount++;
}
}
if ($generatedCount === 0) {
return $this->missingReportResponse(null, (string)$schoolYear, (string)$semester, (int)$classSectionId);
}
$filename = 'ClassReport_Section_' . $classSectionId . '.pdf';
// Clean any existing output buffer
@@ -1324,6 +1318,20 @@ $scoresEndY = $pdf->GetY();
->setBody($pdfContent);
}
protected function missingReportResponse(?int $studentId, string $schoolYear, string $semester, ?int $classSectionId = null)
{
$target = $studentId !== null
? 'student #' . $studentId
: 'class section #' . (int)$classSectionId;
$period = trim($schoolYear . ($semester !== '' ? ' ' . $semester : ''));
$message = 'No report card exists for ' . $target . ($period !== '' ? ' for ' . $period : '') . '.';
return $this->response
->setStatusCode(404)
->setHeader('Content-Type', 'text/plain; charset=UTF-8')
->setBody($message . "\nPlease select a school year and semester that has saved scores before viewing or signing the report card.");
}
protected function normalizeSemester(?string $input): string
{