fix exam and grading
This commit is contained in:
@@ -17,19 +17,45 @@ class ExamDraftAdminService
|
||||
public function list(): array
|
||||
{
|
||||
$context = $this->configService->context();
|
||||
$teacherUserColumn = (string) ($context['teacher_user_column'] ?? '');
|
||||
$adminUserColumn = (string) ($context['admin_user_column'] ?? '');
|
||||
|
||||
$drafts = DB::table('exam_drafts as ed')
|
||||
$draftsQuery = DB::table('exam_drafts as ed')
|
||||
->leftJoin('classSection as cs', 'cs.class_section_id', '=', 'ed.class_section_id')
|
||||
->leftJoin('users as u', 'u.id', '=', 'ed.teacher_id')
|
||||
->leftJoin('users as a', 'a.id', '=', 'ed.admin_id')
|
||||
->select(
|
||||
'ed.*',
|
||||
'cs.class_section_name',
|
||||
'u.firstname as teacher_first',
|
||||
'u.lastname as teacher_last',
|
||||
'a.firstname as admin_first',
|
||||
'a.lastname as admin_last'
|
||||
)
|
||||
);
|
||||
|
||||
if ($teacherUserColumn !== '') {
|
||||
$draftsQuery
|
||||
->leftJoin('users as u', "u.id", '=', "ed.{$teacherUserColumn}")
|
||||
->addSelect(
|
||||
'u.firstname as teacher_first',
|
||||
'u.lastname as teacher_last'
|
||||
);
|
||||
} else {
|
||||
$draftsQuery->addSelect(
|
||||
DB::raw('NULL as teacher_first'),
|
||||
DB::raw('NULL as teacher_last')
|
||||
);
|
||||
}
|
||||
|
||||
if ($adminUserColumn !== '') {
|
||||
$draftsQuery
|
||||
->leftJoin('users as a', 'a.id', '=', "ed.{$adminUserColumn}")
|
||||
->addSelect(
|
||||
'a.firstname as admin_first',
|
||||
'a.lastname as admin_last'
|
||||
);
|
||||
} else {
|
||||
$draftsQuery->addSelect(
|
||||
DB::raw('NULL as admin_first'),
|
||||
DB::raw('NULL as admin_last')
|
||||
);
|
||||
}
|
||||
|
||||
$drafts = $draftsQuery
|
||||
->orderByDesc('ed.created_at')
|
||||
->get()
|
||||
->map(fn ($r) => (array) $r)
|
||||
@@ -88,6 +114,7 @@ class ExamDraftAdminService
|
||||
public function uploadLegacy(int $adminId, array $payload, \Illuminate\Http\UploadedFile $file): array
|
||||
{
|
||||
$context = $this->configService->context();
|
||||
$adminUserColumn = (string) ($context['admin_user_column'] ?? '');
|
||||
$classSectionId = (int) ($payload['class_section_id'] ?? 0);
|
||||
$schoolYear = trim((string) ($payload['school_year'] ?? $context['school_year'] ?? ''));
|
||||
$semester = trim((string) ($payload['semester'] ?? $context['semester'] ?? ''));
|
||||
@@ -124,20 +151,35 @@ class ExamDraftAdminService
|
||||
: (pathinfo($stored['original'], PATHINFO_FILENAME) . '.pdf');
|
||||
|
||||
$payload = [
|
||||
'teacher_id' => $adminId,
|
||||
'class_section_id' => $classSectionId,
|
||||
'semester' => ucfirst(strtolower($semester)),
|
||||
'school_year' => $schoolYear,
|
||||
'exam_type' => $examType !== '' ? $examType : null,
|
||||
'draft_title' => $examType !== '' ? $examType : 'Legacy Exam',
|
||||
'final_file' => $pdfName,
|
||||
'final_filename' => $finalFilename,
|
||||
'status' => 'finalized',
|
||||
'admin_id' => $adminId,
|
||||
'reviewed_at' => now(),
|
||||
'version' => 1,
|
||||
];
|
||||
|
||||
if ($context['has_teacher_id'] ?? false) {
|
||||
$payload['teacher_id'] = $adminId;
|
||||
}
|
||||
if ($context['has_author_id'] ?? false) {
|
||||
$payload['author_id'] = $adminId;
|
||||
}
|
||||
|
||||
if ($context['has_final_filename'] ?? false) {
|
||||
$payload['final_filename'] = $finalFilename;
|
||||
}
|
||||
if ($context['has_admin_id'] ?? false) {
|
||||
$payload['admin_id'] = $adminId;
|
||||
} elseif ($adminUserColumn === 'reviewer_id') {
|
||||
$payload['reviewer_id'] = $adminId;
|
||||
}
|
||||
if ($context['has_reviewed_at'] ?? false) {
|
||||
$payload['reviewed_at'] = now();
|
||||
}
|
||||
|
||||
if ($context['has_legacy'] ?? false) {
|
||||
$payload['is_legacy'] = 1;
|
||||
}
|
||||
@@ -171,13 +213,26 @@ class ExamDraftAdminService
|
||||
$status = 'reviewed';
|
||||
}
|
||||
|
||||
$context = $this->configService->context();
|
||||
|
||||
$update = [
|
||||
'status' => $status,
|
||||
'admin_comments' => $comments !== '' ? $comments : null,
|
||||
'admin_id' => $adminId,
|
||||
'reviewed_at' => now(),
|
||||
];
|
||||
|
||||
if ($context['has_admin_comments'] ?? false) {
|
||||
$update['admin_comments'] = $comments !== '' ? $comments : null;
|
||||
} elseif ($context['has_reviewer_comments'] ?? false) {
|
||||
$update['reviewer_comments'] = $comments !== '' ? $comments : null;
|
||||
}
|
||||
if ($context['has_admin_id'] ?? false) {
|
||||
$update['admin_id'] = $adminId;
|
||||
} elseif (($context['admin_user_column'] ?? null) === 'reviewer_id') {
|
||||
$update['reviewer_id'] = $adminId;
|
||||
}
|
||||
if ($context['has_reviewed_at'] ?? false) {
|
||||
$update['reviewed_at'] = now();
|
||||
}
|
||||
|
||||
if ($file) {
|
||||
$stored = $this->fileService->storeUploadedFile(
|
||||
$file,
|
||||
@@ -189,7 +244,9 @@ class ExamDraftAdminService
|
||||
return ['ok' => false, 'message' => 'Unable to store the final draft.'];
|
||||
}
|
||||
$update['final_file'] = $stored['stored'];
|
||||
$update['final_filename'] = $stored['original'];
|
||||
if ($context['has_final_filename'] ?? false) {
|
||||
$update['final_filename'] = $stored['original'];
|
||||
}
|
||||
$pdfName = $this->fileService->ensurePdfExists(
|
||||
$stored['stored'],
|
||||
$stored['extension'],
|
||||
@@ -198,27 +255,29 @@ class ExamDraftAdminService
|
||||
if ($pdfName !== null && ($this->configService->context()['has_final_pdf'] ?? false)) {
|
||||
$update['final_pdf_file'] = $pdfName;
|
||||
}
|
||||
} elseif ($status === 'finalized' && !empty($draft->teacher_file)) {
|
||||
} elseif ($status === 'finalized' && !empty($draft->teacher_file ?: $draft->author_file)) {
|
||||
$copied = $this->fileService->copyDraftToFinal(
|
||||
(string) $draft->teacher_file,
|
||||
(string) ($draft->teacher_file ?? $draft->author_file),
|
||||
ExamDraftConfigService::TEACHER_UPLOAD_DIR,
|
||||
ExamDraftConfigService::FINAL_UPLOAD_DIR
|
||||
);
|
||||
if ($copied !== null) {
|
||||
$update['final_file'] = $copied;
|
||||
$update['final_filename'] = $draft->teacher_filename ?? $draft->teacher_file;
|
||||
if ($context['has_final_filename'] ?? false) {
|
||||
$update['final_filename'] = $draft->teacher_filename ?? $draft->author_filename ?? $draft->teacher_file ?? $draft->author_file;
|
||||
}
|
||||
$pdfName = $this->fileService->ensurePdfExists(
|
||||
$copied,
|
||||
pathinfo($copied, PATHINFO_EXTENSION),
|
||||
ExamDraftConfigService::FINAL_UPLOAD_DIR
|
||||
);
|
||||
if ($pdfName !== null && ($this->configService->context()['has_final_pdf'] ?? false)) {
|
||||
if ($pdfName !== null && ($context['has_final_pdf'] ?? false)) {
|
||||
$update['final_pdf_file'] = $pdfName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($status === 'finalized' && ($this->configService->context()['has_legacy'] ?? false)) {
|
||||
if ($status === 'finalized' && ($context['has_legacy'] ?? false)) {
|
||||
$update['is_legacy'] = 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user