fix exam and grading

This commit is contained in:
root
2026-06-04 13:25:31 -04:00
parent b4e6ac03c5
commit feb6be0610
22 changed files with 1288 additions and 120 deletions
+45 -13
View File
@@ -18,15 +18,19 @@ class ExamDraftTeacherService
{
$context = $this->configService->context();
$schoolYear = (string) ($context['school_year'] ?? '');
$teacherUserColumn = (string) ($context['teacher_user_column'] ?? '');
$assignments = TeacherClass::getClassAssignmentsByUserId($teacherId, $schoolYear);
$classSectionIds = array_map(static fn ($a) => (int) $a['class_section_id'], $assignments);
$drafts = ExamDraft::query()
->where('teacher_id', $teacherId)
->orderByDesc('created_at')
->get()
->toArray();
$drafts = [];
if ($teacherUserColumn !== '') {
$drafts = ExamDraft::query()
->where($teacherUserColumn, $teacherId)
->orderByDesc('created_at')
->get()
->toArray();
}
$legacyExams = [];
if (($context['has_legacy'] ?? false) && !empty($classSectionIds)) {
@@ -94,11 +98,14 @@ class ExamDraftTeacherService
}
$existingDraft = ExamDraft::query()
->where('teacher_id', $teacherId)
->where('class_section_id', $classSectionId)
->where('semester', $semester)
->where('school_year', $schoolYear)
->orderByDesc('version')
->when(
(string) ($context['teacher_user_column'] ?? '') !== '',
fn ($query) => $query->where((string) $context['teacher_user_column'], $teacherId)
)
->first();
$nextVersion = 1;
@@ -110,20 +117,45 @@ class ExamDraftTeacherService
$title = $examType !== '' ? $examType : 'Exam Draft';
$draft = ExamDraft::query()->create([
'teacher_id' => $teacherId,
$createPayload = [
'class_section_id' => $classSectionId,
'semester' => $semester,
'school_year' => $schoolYear,
'exam_type' => $examType !== '' ? $examType : null,
'draft_title' => $title,
'description' => $description !== '' ? $description : null,
'teacher_file' => $teacherFile,
'teacher_filename' => $teacherFilename,
'status' => 'submitted',
'version' => $nextVersion,
'previous_draft_id' => $previousId,
]);
];
if (($context['teacher_user_column'] ?? null) === 'teacher_id') {
$createPayload['teacher_id'] = $teacherId;
}
if (($context['teacher_user_column'] ?? null) === 'author_id') {
$createPayload['author_id'] = $teacherId;
}
if (($context['teacher_comment_column'] ?? null) === 'description') {
$createPayload['description'] = $description !== '' ? $description : null;
}
if (($context['teacher_comment_column'] ?? null) === 'author_comment') {
$createPayload['author_comment'] = $description !== '' ? $description : null;
}
if (($context['teacher_file_column'] ?? null) === 'teacher_file') {
$createPayload['teacher_file'] = $teacherFile;
}
if (($context['teacher_file_column'] ?? null) === 'author_file') {
$createPayload['author_file'] = $teacherFile;
}
if (($context['teacher_filename_column'] ?? null) === 'teacher_filename') {
$createPayload['teacher_filename'] = $teacherFilename;
}
if (($context['teacher_filename_column'] ?? null) === 'author_filename') {
$createPayload['author_filename'] = $teacherFilename;
}
if ($context['has_previous_draft_id'] ?? false) {
$createPayload['previous_draft_id'] = $previousId;
}
$draft = ExamDraft::query()->create($createPayload);
return [
'ok' => true,