Some checks failed
tests / ci (pull_request) Has been cancelled
- Implemented CourseRegistrationShow component for admin to view registration details. - Added course registration creation and listing for students. - Enhanced student registration edit and create forms with improved error handling. - Introduced new columns for course registration submissions in student view. - Updated routes for course registration management in admin and student contexts. - Added logging and status handling for course registration submissions. - Improved type definitions for course registration and user roles.
76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Manage;
|
|
|
|
use App\Services\Admin\Manage\CourseRegistrationService;
|
|
use App\Services\Admin\Master\AcademicTermService;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class CourseRegistrationRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
if (! $this->routeIs('student.*')) {
|
|
return true;
|
|
}
|
|
|
|
$student = $this->user()->student;
|
|
|
|
if (! $student) {
|
|
return false;
|
|
}
|
|
|
|
$term = app(AcademicTermService::class)->getActive();
|
|
|
|
if (! $term) {
|
|
return false;
|
|
}
|
|
|
|
$service = app(CourseRegistrationService::class);
|
|
$submission = $service->currentSubmission($student, $term);
|
|
|
|
if (! $service->canSubmit($submission)) {
|
|
return false;
|
|
}
|
|
|
|
return $service->paymentStatus($student, $term)['is_paid'];
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
if ($this->routeIs('student.*')) {
|
|
$student = $this->user()->student;
|
|
$term = app(AcademicTermService::class)->getActive();
|
|
$allowedIds = $student && $term
|
|
? app(CourseRegistrationService::class)->allowedCourseClassIds($student, $term)
|
|
: [];
|
|
|
|
return [
|
|
'course_class_ids' => ['required', 'array', 'min:1'],
|
|
'course_class_ids.*' => ['integer', Rule::in($allowedIds)],
|
|
'signature' => ['required', 'image', 'max:2048'],
|
|
];
|
|
}
|
|
|
|
return [
|
|
'student_id' => ['required', 'integer', Rule::exists('students', 'id')],
|
|
'academic_term_id' => ['required', 'integer', Rule::exists('academic_terms', 'id')],
|
|
'course_class_ids' => ['required', 'array', 'min:1'],
|
|
'course_class_ids.*' => [
|
|
'integer',
|
|
Rule::exists('course_classes', 'id'),
|
|
Rule::unique('course_registrations', 'course_class_id')
|
|
->where('student_id', $this->input('student_id')),
|
|
],
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'course_class_ids' => 'mata kuliah',
|
|
];
|
|
}
|
|
}
|