fix the exam draft
This commit is contained in:
@@ -98,6 +98,10 @@ class ClassProgressController extends BaseController
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
if (! $this->hasIslamicUnitSelection()) {
|
||||
return redirect()->back()->withInput()->with('error', 'Please select at least one Islamic Studies unit.');
|
||||
}
|
||||
|
||||
$attachmentErrors = $this->validateAttachmentFiles($subjectSections);
|
||||
if (! empty($attachmentErrors)) {
|
||||
return redirect()->back()->withInput()->with('errors', $attachmentErrors);
|
||||
@@ -431,6 +435,10 @@ class ClassProgressController extends BaseController
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
if (! $this->hasIslamicUnitSelection()) {
|
||||
return redirect()->back()->withInput()->with('error', 'Please select at least one Islamic Studies unit.');
|
||||
}
|
||||
|
||||
$attachmentErrors = $this->validateAttachmentFiles($subjectSections);
|
||||
if (! empty($attachmentErrors)) {
|
||||
return redirect()->back()->withInput()->with('errors', $attachmentErrors);
|
||||
@@ -694,6 +702,17 @@ class ClassProgressController extends BaseController
|
||||
return mb_strlen($summary) > 120 ? mb_substr($summary, 0, 120) : $summary;
|
||||
}
|
||||
|
||||
protected function hasIslamicUnitSelection(): bool
|
||||
{
|
||||
$unitValues = array_map('trim', (array) $this->request->getPost('unit_islamic'));
|
||||
foreach ($unitValues as $value) {
|
||||
if ($value !== '') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function parseUnitChapterSummary(string $summary): array
|
||||
{
|
||||
$summary = trim($summary);
|
||||
|
||||
@@ -240,23 +240,23 @@ class ExamDraftController extends BaseController
|
||||
// Group legacy uploads (admin-uploaded finalized exams) by class_section for separate tab
|
||||
$legacyByClass = [];
|
||||
if ($this->hasIsLegacyColumn) {
|
||||
// Keep all submissions visible; additionally surface legacy items in a separate tab
|
||||
$drafts = $allDrafts;
|
||||
|
||||
// Keep legacy items out of the main submissions list; show them in the legacy tab only.
|
||||
$drafts = [];
|
||||
foreach ($allDrafts as $d) {
|
||||
$isLegacy = !empty($d['is_legacy']);
|
||||
if (!$isLegacy) {
|
||||
if ($isLegacy) {
|
||||
$cid = (int)($d['class_section_id'] ?? 0);
|
||||
if (!isset($legacyByClass[$cid])) {
|
||||
$legacyByClass[$cid] = [
|
||||
'class_section_id' => $cid,
|
||||
'class_section_name' => $d['class_section_name'] ?? 'Class ' . $cid,
|
||||
'items' => [],
|
||||
];
|
||||
}
|
||||
$legacyByClass[$cid]['items'][] = $d;
|
||||
continue;
|
||||
}
|
||||
$cid = (int)($d['class_section_id'] ?? 0);
|
||||
if (!isset($legacyByClass[$cid])) {
|
||||
$legacyByClass[$cid] = [
|
||||
'class_section_id' => $cid,
|
||||
'class_section_name' => $d['class_section_name'] ?? 'Class ' . $cid,
|
||||
'items' => [],
|
||||
];
|
||||
}
|
||||
$legacyByClass[$cid]['items'][] = $d;
|
||||
$drafts[] = $d;
|
||||
}
|
||||
} else {
|
||||
// Column missing: keep behavior simple and avoid legacy tab
|
||||
@@ -284,13 +284,17 @@ class ExamDraftController extends BaseController
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
|
||||
$classSectionId = (int) ($this->request->getPost('class_section_id') ?? 0);
|
||||
$classSectionIds = $this->request->getPost('class_section_ids');
|
||||
if (!is_array($classSectionIds)) {
|
||||
$classSectionIds = [$classSectionIds];
|
||||
}
|
||||
$classSectionIds = array_values(array_filter(array_map('intval', $classSectionIds)));
|
||||
$schoolYear = trim((string) ($this->request->getPost('school_year') ?? $this->schoolYear));
|
||||
$semester = trim((string) ($this->request->getPost('semester') ?? $this->semester));
|
||||
$examType = trim((string) $this->request->getPost('exam_type'));
|
||||
|
||||
if ($classSectionId <= 0) {
|
||||
return redirect()->back()->withInput()->with('error', 'Select a class section.');
|
||||
if (empty($classSectionIds)) {
|
||||
return redirect()->back()->withInput()->with('error', 'Select at least one class section.');
|
||||
}
|
||||
if ($schoolYear === '') {
|
||||
return redirect()->back()->withInput()->with('error', 'School year is required.');
|
||||
@@ -309,9 +313,17 @@ class ExamDraftController extends BaseController
|
||||
return redirect()->back()->withInput()->with('error', 'File type not allowed or upload failed.');
|
||||
}
|
||||
|
||||
$payload = [
|
||||
$pdfName = null;
|
||||
if (strtolower($file->getClientExtension()) === 'pdf') {
|
||||
$pdfName = $stored;
|
||||
} else {
|
||||
$pdfName = $this->convertDocToPdf(
|
||||
$this->fullUploadPath(self::FINAL_UPLOAD_DIR, $stored),
|
||||
self::FINAL_UPLOAD_DIR
|
||||
);
|
||||
}
|
||||
$basePayload = [
|
||||
'teacher_id' => $adminId, // store under admin user since legacy uploads are admin-only
|
||||
'class_section_id' => $classSectionId,
|
||||
'semester' => ucfirst(strtolower($semester)),
|
||||
'school_year' => $schoolYear,
|
||||
'exam_type' => $examType === '' ? null : $examType,
|
||||
@@ -325,23 +337,22 @@ class ExamDraftController extends BaseController
|
||||
'version' => 1,
|
||||
];
|
||||
if ($this->hasIsLegacyColumn) {
|
||||
$payload['is_legacy'] = 1;
|
||||
}
|
||||
|
||||
$pdfName = null;
|
||||
if (strtolower($file->getClientExtension()) === 'pdf') {
|
||||
$pdfName = $stored;
|
||||
} else {
|
||||
$pdfName = $this->convertDocToPdf(
|
||||
$this->fullUploadPath(self::FINAL_UPLOAD_DIR, $stored),
|
||||
self::FINAL_UPLOAD_DIR
|
||||
);
|
||||
$basePayload['is_legacy'] = 1;
|
||||
}
|
||||
if ($pdfName !== null && $this->hasFinalPdfColumn) {
|
||||
$payload['final_pdf_file'] = $pdfName;
|
||||
$basePayload['final_pdf_file'] = $pdfName;
|
||||
}
|
||||
|
||||
if ($this->examDraftModel->insert($payload)) {
|
||||
$saved = 0;
|
||||
foreach ($classSectionIds as $classSectionId) {
|
||||
$payload = $basePayload;
|
||||
$payload['class_section_id'] = $classSectionId;
|
||||
if ($this->examDraftModel->insert($payload)) {
|
||||
$saved++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($saved > 0) {
|
||||
return redirect()->to('/administrator/exam-drafts')->with('success', 'Old exam uploaded successfully.');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user