itmpwk.ac.id/app/Services/Admin/AcademicClasses/SubmissionService.php
Yoga Pangestu 4980ad95b3 Refactor assignment management system
- Updated the PermissionCatalog to remove unnecessary permissions for assignment submissions.
- Modified RolePermissionSeeder to align with the updated permissions.
- Enhanced useServerTable hook to support resetKeys for Inertia's reset visit option.
- Removed obsolete columns.tsx file related to assignment columns.
- Revamped assignment index page to utilize InfiniteScroll and improved UI components.
- Introduced new assignment status management with enums and updated database schema.
- Created GradeSubmissionRequest for validation of submission grading.
- Implemented score editing functionality in submission index with real-time updates.
- Added accordion component for better UI organization in assignment descriptions.
2026-09-03 09:51:27 +07:00

53 lines
1.5 KiB
PHP

<?php
namespace App\Services\Admin\AcademicClasses;
use App\Enums\SubmissionStatus;
use App\Models\Assignment;
use App\Models\Student;
use App\Models\Submission;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\UploadedFile;
class SubmissionService
{
/**
* Self-service submission by the student themselves: creates their
* submission for this assignment, or updates it if they already
* submitted before (e.g. resubmitting).
*/
public function submitForStudent(Assignment $assignment, Student $student, array $data, ?UploadedFile $file): Submission
{
$submission = Submission::query()->updateOrCreate(
['assignment_id' => $assignment->id, 'student_id' => $student->id],
[
'notes' => $data['notes'] ?? null,
'status' => SubmissionStatus::Submitted,
'submitted_at' => now(),
],
);
if ($file) {
$submission->addMedia($file)->toMediaCollection('submission_file');
}
return $submission;
}
public function forAssignment(Assignment $assignment): Collection
{
return $assignment->submissions()
->with(['student.user.profile', 'student.department'])
->latest('created_at')
->get();
}
public function grade(Submission $submission, ?float $score): Submission
{
$submission->score = $score;
$submission->update();
return $submission;
}
}