- Created SubmissionService to handle submission logic for assignments. - Added migrations for assignments and submissions tables. - Implemented AssignmentSeeder and SubmissionSeeder for initial data. - Updated DatabaseSeeder to include new seeders. - Enhanced app sidebar to include assignments navigation. - Developed datetime field component for better date and time input. - Created assignment management pages with data tables for assignments and submissions. - Implemented forms for creating and editing assignments and submissions. - Added routes for assignment and submission management in admin panel. - Defined types for assignments and submissions to improve type safety.
58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin\Manage;
|
|
|
|
use App\Models\Assignment;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
class AssignmentService
|
|
{
|
|
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
|
{
|
|
return Assignment::query()
|
|
->select(['id', 'course_class_id', 'title', 'description', 'deadline'])
|
|
->withCount('submissions')
|
|
->with('courseClass.course:id,code,name')
|
|
->when($search, fn ($q) => $q->where('title', 'like', "%{$search}%"))
|
|
->orderBy($sort, $direction)
|
|
->paginate($perPage);
|
|
}
|
|
|
|
public function create(array $data, ?UploadedFile $file): Assignment
|
|
{
|
|
$assignment = Assignment::create([
|
|
'course_class_id' => $data['course_class_id'],
|
|
'title' => $data['title'],
|
|
'description' => $data['description'] ?? null,
|
|
'deadline' => $data['deadline'],
|
|
]);
|
|
|
|
if ($file) {
|
|
$assignment->addMedia($file)->toMediaCollection('assignment_attachment');
|
|
}
|
|
|
|
return $assignment;
|
|
}
|
|
|
|
public function update(Assignment $assignment, array $data, ?UploadedFile $file): Assignment
|
|
{
|
|
$assignment->course_class_id = $data['course_class_id'];
|
|
$assignment->title = $data['title'];
|
|
$assignment->description = $data['description'] ?? null;
|
|
$assignment->deadline = $data['deadline'];
|
|
$assignment->update();
|
|
|
|
if ($file) {
|
|
$assignment->addMedia($file)->toMediaCollection('assignment_attachment');
|
|
}
|
|
|
|
return $assignment;
|
|
}
|
|
|
|
public function delete(Assignment $assignment): bool
|
|
{
|
|
return $assignment->delete();
|
|
}
|
|
}
|