update exam and attendance

This commit is contained in:
root
2026-04-26 14:57:43 -04:00
parent 5e8fa682b9
commit 8beeed883f
11 changed files with 78 additions and 36 deletions
+31 -13
View File
@@ -37,6 +37,18 @@ class ExamDraftAdminService
$classSections = ClassSection::query()
->select('class_section_id', 'class_section_name')
->whereExists(function ($query) use ($context) {
$query->selectRaw('1')
->from('student_class as sc')
->join('students as s', 's.id', '=', 'sc.student_id')
->whereColumn('sc.class_section_id', 'classSection.class_section_id')
->where('s.is_active', 1);
$schoolYear = (string) ($context['school_year'] ?? '');
if ($schoolYear !== '') {
$query->where('sc.school_year', $schoolYear);
}
})
->orderBy('class_section_name')
->get()
->toArray();
@@ -95,6 +107,22 @@ class ExamDraftAdminService
return ['ok' => false, 'message' => 'File type not allowed or upload failed.'];
}
$pdfName = $stored['extension'] === 'pdf'
? $stored['stored']
: $this->fileService->ensurePdfExists(
$stored['stored'],
$stored['extension'],
ExamDraftConfigService::FINAL_UPLOAD_DIR
);
if ($pdfName === null) {
return ['ok' => false, 'message' => 'Unable to convert the uploaded exam to PDF.'];
}
$finalFilename = $stored['extension'] === 'pdf'
? $stored['original']
: (pathinfo($stored['original'], PATHINFO_FILENAME) . '.pdf');
$payload = [
'teacher_id' => $adminId,
'class_section_id' => $classSectionId,
@@ -102,8 +130,8 @@ class ExamDraftAdminService
'school_year' => $schoolYear,
'exam_type' => $examType !== '' ? $examType : null,
'draft_title' => $examType !== '' ? $examType : 'Legacy Exam',
'final_file' => $stored['stored'],
'final_filename' => $stored['original'],
'final_file' => $pdfName,
'final_filename' => $finalFilename,
'status' => 'finalized',
'admin_id' => $adminId,
'reviewed_at' => now(),
@@ -114,17 +142,7 @@ class ExamDraftAdminService
$payload['is_legacy'] = 1;
}
$pdfName = null;
if ($stored['extension'] === 'pdf') {
$pdfName = $stored['stored'];
} else {
$pdfName = $this->fileService->ensurePdfExists(
$stored['stored'],
$stored['extension'],
ExamDraftConfigService::FINAL_UPLOAD_DIR
);
}
if ($pdfName !== null && ($context['has_final_pdf'] ?? false)) {
if ($context['has_final_pdf'] ?? false) {
$payload['final_pdf_file'] = $pdfName;
}