fix draft exam upload
This commit is contained in:
@@ -348,6 +348,16 @@ class ExamDraftController extends BaseController
|
||||
}
|
||||
|
||||
public function adminIndex()
|
||||
{
|
||||
return $this->reviewIndex();
|
||||
}
|
||||
|
||||
public function principalIndex()
|
||||
{
|
||||
return $this->reviewIndex();
|
||||
}
|
||||
|
||||
public function reviewIndex()
|
||||
{
|
||||
if ($this->reviewerIdColumn !== '') {
|
||||
$allDrafts = $this->examDraftModel
|
||||
@@ -487,10 +497,23 @@ class ExamDraftController extends BaseController
|
||||
'visibleClasses' => $visibleClasses,
|
||||
'classDraftGroups' => $classDraftGroups,
|
||||
'newSubmissionClasses' => $newSubmissionClasses,
|
||||
'reviewActionUrl' => base_url($this->reviewRoutePrefix() . '/exam-drafts/review'),
|
||||
'legacyUploadUrl' => base_url($this->reviewRoutePrefix() . '/exam-drafts/upload-legacy'),
|
||||
'reviewPortalLabel' => $this->reviewPortalLabel(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function adminUploadLegacy()
|
||||
{
|
||||
return $this->reviewUploadLegacy();
|
||||
}
|
||||
|
||||
public function principalUploadLegacy()
|
||||
{
|
||||
return $this->reviewUploadLegacy();
|
||||
}
|
||||
|
||||
public function reviewUploadLegacy()
|
||||
{
|
||||
$adminId = (int) (session()->get('user_id') ?? 0);
|
||||
if ($adminId <= 0) {
|
||||
@@ -571,13 +594,23 @@ class ExamDraftController extends BaseController
|
||||
}
|
||||
|
||||
if ($saved > 0) {
|
||||
return redirect()->to('/administrator/exam-drafts')->with('success', 'Old exam uploaded successfully.');
|
||||
return redirect()->to($this->reviewDashboardPath())->with('success', 'Old exam uploaded successfully.');
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->with('error', 'Unable to save the old exam.');
|
||||
}
|
||||
|
||||
public function adminReview()
|
||||
{
|
||||
return $this->reviewSubmission();
|
||||
}
|
||||
|
||||
public function principalReview()
|
||||
{
|
||||
return $this->reviewSubmission();
|
||||
}
|
||||
|
||||
public function reviewSubmission()
|
||||
{
|
||||
$draftId = (int) ($this->request->getPost('draft_id') ?? 0);
|
||||
if ($draftId <= 0) {
|
||||
@@ -690,11 +723,6 @@ class ExamDraftController extends BaseController
|
||||
if ($this->hasAcceptanceTypeColumn) {
|
||||
$newRow['acceptance_type'] = $status === 'accepted' ? $acceptanceType : null;
|
||||
}
|
||||
$teacherFile = $this->draftTeacherFile($draft);
|
||||
if (!empty($teacherFile)) {
|
||||
$newRow[$this->authorFileColumn] = $teacherFile;
|
||||
$newRow[$this->authorFilenameColumn] = $this->draftTeacherFilename($draft) ?? $teacherFile;
|
||||
}
|
||||
if ($this->hasIsLegacyColumn && !empty($draft['is_legacy'])) {
|
||||
$newRow['is_legacy'] = 1;
|
||||
}
|
||||
@@ -711,16 +739,6 @@ class ExamDraftController extends BaseController
|
||||
return redirect()->back()->with('success', 'Review saved successfully.');
|
||||
}
|
||||
return redirect()->back()->with('error', 'Unable to save the review.');
|
||||
} elseif (strtolower($status) === 'accepted' && !empty($this->draftTeacherFile($draft))) {
|
||||
$copied = $this->copyDraftToFinal($this->draftTeacherFile($draft));
|
||||
if ($copied !== null) {
|
||||
$update['final_file'] = $copied;
|
||||
$update['final_filename'] = $this->draftTeacherFilename($draft) ?? $this->draftTeacherFile($draft);
|
||||
$pdfName = $this->ensurePdfExists($copied, pathinfo($copied, PATHINFO_EXTENSION));
|
||||
if ($pdfName !== null && $this->hasFinalPdfColumn) {
|
||||
$update['final_pdf_file'] = $pdfName;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($status === 'legacy') {
|
||||
$this->prepareLegacyPdfVersion($update, $draft);
|
||||
@@ -1010,7 +1028,7 @@ class ExamDraftController extends BaseController
|
||||
. '<tr><td style="padding:4px 8px;"><strong>Status</strong></td><td style="padding:4px 8px;">' . esc((string) ($draft['status'] ?? 'submitted')) . '</td></tr>'
|
||||
. '<tr><td style="padding:4px 8px;"><strong>Submitted at</strong></td><td style="padding:4px 8px;">' . esc((string) $submittedAt) . '</td></tr>'
|
||||
. '</table>'
|
||||
. '<p>Review drafts: <a href="' . esc(base_url('administrator/exam-drafts')) . '">Admin exam drafts</a></p>';
|
||||
. '<p>Review drafts: <a href="' . esc(base_url($this->reviewRoutePrefix() . '/exam-drafts')) . '">' . esc($this->reviewPortalLabel()) . ' exam drafts</a></p>';
|
||||
|
||||
$mailer = \Config\Services::emailService();
|
||||
$mailer->send($principalEmail, $subject, $body, 'notifications');
|
||||
@@ -1019,6 +1037,38 @@ class ExamDraftController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
private function reviewDashboardPath(): string
|
||||
{
|
||||
return '/' . $this->reviewRoutePrefix() . '/exam-drafts';
|
||||
}
|
||||
|
||||
private function reviewRoutePrefix(): string
|
||||
{
|
||||
return $this->isPrincipalReviewer() ? 'principal' : 'administrator';
|
||||
}
|
||||
|
||||
private function reviewPortalLabel(): string
|
||||
{
|
||||
return $this->isPrincipalReviewer() ? 'Principal' : 'Administrator';
|
||||
}
|
||||
|
||||
private function isPrincipalReviewer(): bool
|
||||
{
|
||||
$roles = session()->get('roles');
|
||||
if (!is_array($roles)) {
|
||||
$roles = $roles === null ? [] : [$roles];
|
||||
}
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$normalized = strtolower(trim(str_replace([' ', '-'], '_', (string) $role)));
|
||||
if ($normalized === 'principal') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function nextDraftVersion(array $draft): int
|
||||
{
|
||||
$query = $this->examDraftModel
|
||||
@@ -1373,6 +1423,11 @@ class ExamDraftController extends BaseController
|
||||
$base = pathinfo($sourcePath, PATHINFO_FILENAME);
|
||||
$targetPath = $targetDir . '/' . $base . '.pdf';
|
||||
|
||||
if (!function_exists('exec')) {
|
||||
log_message('warning', 'ExamDraftController::convertDocToPdf skipped because exec() is unavailable.');
|
||||
return is_file($targetPath) ? basename($targetPath) : null;
|
||||
}
|
||||
|
||||
// Attempt conversion via LibreOffice if available
|
||||
$cmd = 'soffice --headless --convert-to pdf --outdir ' . escapeshellarg($targetDir) . ' ' . escapeshellarg($sourcePath) . ' 2>/dev/null';
|
||||
@\exec($cmd);
|
||||
|
||||
Reference in New Issue
Block a user