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
@@ -138,7 +138,7 @@ class ClassProgressMetaService
return $svc->getSchoolYearRange($schoolYear);
}
public function curriculumOptions(?int $classId): array
public function curriculumOptions(?int $classId, ?string $schoolYear = null): array
{
if (!$classId) {
return [];
@@ -146,7 +146,7 @@ class ClassProgressMetaService
$options = [];
foreach ($this->subjectSections() as $slug => $section) {
$options[$slug] = SubjectCurriculum::getOptionsForClass((int) $classId, (string) $slug);
$options[$slug] = SubjectCurriculum::getOptionsForClass((int) $classId, (string) $slug, $schoolYear);
}
return $options;
@@ -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();
@@ -7,10 +7,21 @@ use App\Models\ClassProgressReport;
use App\Models\Configuration;
use App\Models\TeacherClass;
use App\Models\User;
use App\Services\SchoolYears\SchoolYearContextService;
use Illuminate\Support\Facades\Schema;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
class ClassProgressQueryService
{
private SchoolYearContextService $schoolYears;
public function __construct($schoolYears = null)
{
$this->schoolYears = $schoolYears instanceof SchoolYearContextService
? $schoolYears
: app(SchoolYearContextService::class);
}
public function listReports(User $user, array $filters): LengthAwarePaginator
{
$query = ClassProgressReport::query()
@@ -51,6 +62,14 @@ class ClassProgressQueryService
$query->where('status', (string) $filters['status']);
}
if (!empty($filters['school_year']) && Schema::hasColumn('class_progress_reports', 'school_year')) {
$query->where('school_year', (string) $filters['school_year']);
}
if (!empty($filters['semester']) && Schema::hasColumn('class_progress_reports', 'semester')) {
$query->where('semester', (string) $filters['semester']);
}
if (!empty($filters['week_start'])) {
$query->whereDate('week_start', '>=', $filters['week_start']);
}
@@ -132,6 +151,11 @@ class ClassProgressQueryService
return TeacherClass::getClassAssignmentsByUserId($user->id, $schoolYear, $semester);
}
public function meta(?string $schoolYear = null, ?string $semester = null): array
{
return $this->schoolYears->options($schoolYear, $semester);
}
private function statusLabel(?string $status): string
{
$options = (array) config('progress.status_options', []);