update the new school year model

This commit is contained in:
root
2026-06-07 20:01:58 -04:00
parent 6866aedf42
commit 68a5c9edca
19 changed files with 472 additions and 32 deletions
@@ -6,6 +6,8 @@ use App\Models\ClassProgressAttachment;
use App\Models\ClassProgressReport;
use App\Models\TeacherClass;
use App\Models\User;
use App\Services\SchoolYears\SchoolYearContextService;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
@@ -16,6 +18,7 @@ class ClassProgressMutationService
private ClassProgressRuleService $rules,
private ClassProgressAttachmentService $attachments,
private ClassProgressQueryService $queries,
private SchoolYearContextService $schoolYears,
) {}
public function createReports(User $user, array $payload, array $filesBySubject): Collection
@@ -25,6 +28,9 @@ class ClassProgressMutationService
$this->assertTeacherAssignment($user, $classSectionId);
$schoolYear = $this->schoolYears->currentSchoolYear($payload['school_year'] ?? null);
$semester = $this->schoolYears->currentSemester($payload['semester'] ?? null);
$weekStart = (string) ($payload['week_start'] ?? '');
$weekEnd = $this->rules->ensureWeekEnd($weekStart, $payload['week_end'] ?? null);
@@ -51,7 +57,7 @@ class ClassProgressMutationService
throw new \InvalidArgumentException('CONFIRM_OVERWRITE');
}
$reports = DB::transaction(function () use ($user, $payload, $subjectSections, $classSectionId, $weekStart, $weekEnd, $filesBySubject, $confirmOverwrite, $existingIds) {
$reports = DB::transaction(function () use ($user, $payload, $subjectSections, $classSectionId, $schoolYear, $semester, $weekStart, $weekEnd, $filesBySubject, $confirmOverwrite, $existingIds) {
if ($existingIds !== [] && $confirmOverwrite) {
ClassProgressAttachment::query()->whereIn('report_id', $existingIds)->delete();
ClassProgressReport::query()->whereIn('id', $existingIds)->delete();
@@ -70,7 +76,7 @@ class ClassProgressMutationService
$chapterValues = (array) ($payload["chapter_{$slug}"] ?? []);
$unitTitle = $this->rules->buildUnitChapterSummary($unitValues, $chapterValues);
$report = ClassProgressReport::query()->create([
$data = [
'teacher_id' => $user->id,
'class_section_id' => $classSectionId,
'week_start' => $weekStart,
@@ -82,7 +88,16 @@ class ClassProgressMutationService
'status' => $this->rules->defaultStatus(),
'support_needed' => $payload['support_needed'] ?? null,
'flags_json' => $this->rules->normalizeFlags($payload['flags'] ?? null),
]);
];
if (Schema::hasColumn('class_progress_reports', 'school_year')) {
$data['school_year'] = $schoolYear !== '' ? $schoolYear : null;
}
if (Schema::hasColumn('class_progress_reports', 'semester')) {
$data['semester'] = $semester !== '' ? $semester : null;
}
$report = ClassProgressReport::query()->create($data);
$attachments = $filesBySubject[$slug] ?? [];
$stored = $this->attachments->storeAttachments($report->id, $attachments);
@@ -121,6 +136,9 @@ class ClassProgressMutationService
$this->assertTeacherAssignment($user, $classSectionId);
$schoolYear = $this->schoolYears->currentSchoolYear($payload['school_year'] ?? null);
$semester = $this->schoolYears->currentSemester($payload['semester'] ?? null);
$weekStart = (string) ($payload['week_start'] ?? '');
$weekEnd = $this->rules->ensureWeekEnd($weekStart, $payload['week_end'] ?? null);
@@ -172,6 +190,8 @@ class ClassProgressMutationService
$classSectionId,
$weekStart,
$weekEnd,
$schoolYear,
$semester,
$filesBySubject,
$allowedIds,
$originalWeekStart,
@@ -226,6 +246,13 @@ class ClassProgressMutationService
$data['flags_json'] = $this->rules->normalizeFlags($payload['flags'] ?? null);
}
if (Schema::hasColumn('class_progress_reports', 'school_year')) {
$data['school_year'] = $schoolYear !== '' ? $schoolYear : null;
}
if (Schema::hasColumn('class_progress_reports', 'semester')) {
$data['semester'] = $semester !== '' ? $semester : null;
}
if ($existing) {
$existing->fill($data);
$existing->save();