Fix Laravel Pint formatting
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services\Exams;
|
||||
|
||||
use App\Models\ClassSection;
|
||||
use App\Models\ExamDraft;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ExamDraftAdminService
|
||||
@@ -11,8 +12,7 @@ class ExamDraftAdminService
|
||||
public function __construct(
|
||||
private ExamDraftConfigService $configService,
|
||||
private ExamDraftFileService $fileService
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function list(): array
|
||||
{
|
||||
@@ -29,7 +29,7 @@ class ExamDraftAdminService
|
||||
|
||||
if ($teacherUserColumn !== '') {
|
||||
$draftsQuery
|
||||
->leftJoin('users as u', "u.id", '=', "ed.{$teacherUserColumn}")
|
||||
->leftJoin('users as u', 'u.id', '=', "ed.{$teacherUserColumn}")
|
||||
->addSelect(
|
||||
'u.firstname as teacher_first',
|
||||
'u.lastname as teacher_last'
|
||||
@@ -82,15 +82,15 @@ class ExamDraftAdminService
|
||||
$legacyByClass = [];
|
||||
if ($context['has_legacy'] ?? false) {
|
||||
foreach ($drafts as $row) {
|
||||
$isLegacy = !empty($row['is_legacy']);
|
||||
if (!$isLegacy) {
|
||||
$isLegacy = ! empty($row['is_legacy']);
|
||||
if (! $isLegacy) {
|
||||
continue;
|
||||
}
|
||||
$cid = (int) ($row['class_section_id'] ?? 0);
|
||||
if (!isset($legacyByClass[$cid])) {
|
||||
if (! isset($legacyByClass[$cid])) {
|
||||
$legacyByClass[$cid] = [
|
||||
'class_section_id' => $cid,
|
||||
'class_section_name' => $row['class_section_name'] ?? 'Class ' . $cid,
|
||||
'class_section_name' => $row['class_section_name'] ?? 'Class '.$cid,
|
||||
'items' => [],
|
||||
];
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class ExamDraftAdminService
|
||||
];
|
||||
}
|
||||
|
||||
public function uploadLegacy(int $adminId, array $payload, \Illuminate\Http\UploadedFile $file): array
|
||||
public function uploadLegacy(int $adminId, array $payload, UploadedFile $file): array
|
||||
{
|
||||
$context = $this->configService->context();
|
||||
$adminUserColumn = (string) ($context['admin_user_column'] ?? '');
|
||||
@@ -148,7 +148,7 @@ class ExamDraftAdminService
|
||||
|
||||
$finalFilename = $stored['extension'] === 'pdf'
|
||||
? $stored['original']
|
||||
: (pathinfo($stored['original'], PATHINFO_FILENAME) . '.pdf');
|
||||
: (pathinfo($stored['original'], PATHINFO_FILENAME).'.pdf');
|
||||
|
||||
$payload = [
|
||||
'class_section_id' => $classSectionId,
|
||||
@@ -193,7 +193,7 @@ class ExamDraftAdminService
|
||||
return ['ok' => true, 'draft' => $draft->toArray()];
|
||||
}
|
||||
|
||||
public function review(int $adminId, array $payload, ?\Illuminate\Http\UploadedFile $file): array
|
||||
public function review(int $adminId, array $payload, ?UploadedFile $file): array
|
||||
{
|
||||
$draftId = (int) ($payload['draft_id'] ?? 0);
|
||||
if ($draftId <= 0) {
|
||||
@@ -201,7 +201,7 @@ class ExamDraftAdminService
|
||||
}
|
||||
|
||||
$draft = ExamDraft::query()->find($draftId);
|
||||
if (!$draft) {
|
||||
if (! $draft) {
|
||||
return ['ok' => false, 'message' => 'Submission not found.'];
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ class ExamDraftAdminService
|
||||
$statusInput = trim((string) ($payload['review_status'] ?? ''));
|
||||
$currentStatus = (string) ($draft->status ?? 'draft');
|
||||
$status = $this->normalizeStatus($statusInput !== '' ? $statusInput : $currentStatus, $currentStatus);
|
||||
if (!in_array($status, ExamDraftConfigService::STATUS_OPTIONS, true)) {
|
||||
if (! in_array($status, ExamDraftConfigService::STATUS_OPTIONS, true)) {
|
||||
$status = 'reviewed';
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ class ExamDraftAdminService
|
||||
if ($pdfName !== null && ($this->configService->context()['has_final_pdf'] ?? false)) {
|
||||
$update['final_pdf_file'] = $pdfName;
|
||||
}
|
||||
} elseif ($status === 'finalized' && !empty($draft->teacher_file ?: $draft->author_file)) {
|
||||
} elseif ($status === 'finalized' && ! empty($draft->teacher_file ?: $draft->author_file)) {
|
||||
$copied = $this->fileService->copyDraftToFinal(
|
||||
(string) ($draft->teacher_file ?? $draft->author_file),
|
||||
ExamDraftConfigService::TEACHER_UPLOAD_DIR,
|
||||
@@ -297,6 +297,7 @@ class ExamDraftAdminService
|
||||
if (isset($aliases[$input])) {
|
||||
$input = $aliases[$input];
|
||||
}
|
||||
|
||||
return in_array($input, ExamDraftConfigService::STATUS_OPTIONS, true) ? $input : $default;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,13 @@ use Illuminate\Support\Facades\Schema;
|
||||
class ExamDraftConfigService
|
||||
{
|
||||
public const TEACHER_UPLOAD_DIR = 'exams/drafts';
|
||||
|
||||
public const FINAL_UPLOAD_DIR = 'exams/finals';
|
||||
|
||||
public const MAX_UPLOAD_BYTES = 12 * 1024 * 1024;
|
||||
|
||||
public const ALLOWED_EXTENSIONS = ['doc', 'docx'];
|
||||
|
||||
public const ADMIN_ALLOWED_EXTENSIONS = ['doc', 'docx', 'pdf'];
|
||||
|
||||
public const EXAM_TYPES = [
|
||||
|
||||
@@ -9,21 +9,22 @@ class ExamDraftFileService
|
||||
public function storeUploadedFile(UploadedFile $file, string $subdir, array $allowedExtensions, int $maxBytes): ?array
|
||||
{
|
||||
$ext = strtolower($file->getClientOriginalExtension());
|
||||
if (!in_array($ext, $allowedExtensions, true)) {
|
||||
if (! in_array($ext, $allowedExtensions, true)) {
|
||||
return null;
|
||||
}
|
||||
if ($file->getSize() > $maxBytes) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$destination = storage_path('uploads/' . trim($subdir, '/'));
|
||||
if (!is_dir($destination)) {
|
||||
$destination = storage_path('uploads/'.trim($subdir, '/'));
|
||||
if (! is_dir($destination)) {
|
||||
mkdir($destination, 0755, true);
|
||||
}
|
||||
|
||||
$filename = uniqid('exam_', true) . '.' . $ext;
|
||||
$filename = uniqid('exam_', true).'.'.$ext;
|
||||
try {
|
||||
$file->move($destination, $filename);
|
||||
|
||||
return [
|
||||
'stored' => $filename,
|
||||
'original' => $file->getClientOriginalName(),
|
||||
@@ -43,46 +44,49 @@ class ExamDraftFileService
|
||||
$ext = strtolower((string) $originalExt);
|
||||
if ($ext === 'pdf') {
|
||||
$path = $this->fullUploadPath($subdir, $finalFilename);
|
||||
|
||||
return is_file($path) ? $finalFilename : null;
|
||||
}
|
||||
|
||||
return $this->convertDocToPdf($this->fullUploadPath($subdir, $finalFilename), $subdir);
|
||||
}
|
||||
|
||||
public function copyDraftToFinal(string $draftFilename, string $sourceDir, string $targetDir): ?string
|
||||
{
|
||||
$source = $this->fullUploadPath($sourceDir, $draftFilename);
|
||||
if (!is_file($source)) {
|
||||
if (! is_file($source)) {
|
||||
return null;
|
||||
}
|
||||
$destinationDir = storage_path('uploads/' . trim($targetDir, '/'));
|
||||
if (!is_dir($destinationDir)) {
|
||||
$destinationDir = storage_path('uploads/'.trim($targetDir, '/'));
|
||||
if (! is_dir($destinationDir)) {
|
||||
mkdir($destinationDir, 0755, true);
|
||||
}
|
||||
$ext = pathinfo($draftFilename, PATHINFO_EXTENSION);
|
||||
$destName = uniqid('final_', true) . '.' . $ext;
|
||||
$destPath = $destinationDir . '/' . $destName;
|
||||
if (!@copy($source, $destPath)) {
|
||||
$destName = uniqid('final_', true).'.'.$ext;
|
||||
$destPath = $destinationDir.'/'.$destName;
|
||||
if (! @copy($source, $destPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $destName;
|
||||
}
|
||||
|
||||
private function convertDocToPdf(string $sourcePath, string $targetSubdir): ?string
|
||||
{
|
||||
$ext = strtolower(pathinfo($sourcePath, PATHINFO_EXTENSION));
|
||||
if (!in_array($ext, ['doc', 'docx'], true)) {
|
||||
if (! in_array($ext, ['doc', 'docx'], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$targetDir = storage_path('uploads/' . trim($targetSubdir, '/'));
|
||||
if (!is_dir($targetDir)) {
|
||||
$targetDir = storage_path('uploads/'.trim($targetSubdir, '/'));
|
||||
if (! is_dir($targetDir)) {
|
||||
mkdir($targetDir, 0755, true);
|
||||
}
|
||||
|
||||
$base = pathinfo($sourcePath, PATHINFO_FILENAME);
|
||||
$targetPath = $targetDir . '/' . $base . '.pdf';
|
||||
$targetPath = $targetDir.'/'.$base.'.pdf';
|
||||
|
||||
$cmd = 'soffice --headless --convert-to pdf --outdir ' . escapeshellarg($targetDir) . ' ' . escapeshellarg($sourcePath) . ' 2>/dev/null';
|
||||
$cmd = 'soffice --headless --convert-to pdf --outdir '.escapeshellarg($targetDir).' '.escapeshellarg($sourcePath).' 2>/dev/null';
|
||||
@exec($cmd);
|
||||
|
||||
return is_file($targetPath) ? basename($targetPath) : null;
|
||||
@@ -96,12 +100,13 @@ class ExamDraftFileService
|
||||
$path = $this->fullUploadPath($subdir, $filename);
|
||||
$base = pathinfo($path, PATHINFO_FILENAME);
|
||||
$dir = pathinfo($path, PATHINFO_DIRNAME);
|
||||
$pdfPath = $dir . '/' . $base . '.pdf';
|
||||
$pdfPath = $dir.'/'.$base.'.pdf';
|
||||
|
||||
return is_file($pdfPath) ? basename($pdfPath) : null;
|
||||
}
|
||||
|
||||
private function fullUploadPath(string $subdir, string $filename): string
|
||||
{
|
||||
return storage_path('uploads/' . trim($subdir, '/') . '/' . $filename);
|
||||
return storage_path('uploads/'.trim($subdir, '/').'/'.$filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Services\Exams;
|
||||
|
||||
use App\Models\ExamDraft;
|
||||
use App\Models\TeacherClass;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ExamDraftTeacherService
|
||||
@@ -11,8 +12,7 @@ class ExamDraftTeacherService
|
||||
public function __construct(
|
||||
private ExamDraftConfigService $configService,
|
||||
private ExamDraftFileService $fileService
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function listForTeacher(int $teacherId): array
|
||||
{
|
||||
@@ -33,7 +33,7 @@ class ExamDraftTeacherService
|
||||
}
|
||||
|
||||
$legacyExams = [];
|
||||
if (($context['has_legacy'] ?? false) && !empty($classSectionIds)) {
|
||||
if (($context['has_legacy'] ?? false) && ! empty($classSectionIds)) {
|
||||
$legacyExams = DB::table('exam_drafts as ed')
|
||||
->select('ed.*', 'cs.class_section_name')
|
||||
->leftJoin('classSection as cs', 'cs.class_section_id', '=', 'ed.class_section_id')
|
||||
@@ -58,7 +58,7 @@ class ExamDraftTeacherService
|
||||
];
|
||||
}
|
||||
|
||||
public function store(int $teacherId, array $payload, ?\Illuminate\Http\UploadedFile $file): array
|
||||
public function store(int $teacherId, array $payload, ?UploadedFile $file): array
|
||||
{
|
||||
$context = $this->configService->context();
|
||||
$schoolYear = (string) ($context['school_year'] ?? '');
|
||||
@@ -77,7 +77,7 @@ class ExamDraftTeacherService
|
||||
->where('class_section_id', $classSectionId)
|
||||
->first();
|
||||
|
||||
if (!$assignment) {
|
||||
if (! $assignment) {
|
||||
return ['ok' => false, 'message' => 'You are not assigned to the selected class section.'];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user