add school year model

This commit is contained in:
root
2026-06-07 00:52:01 -04:00
parent a192ed433d
commit 6866aedf42
36 changed files with 4771 additions and 88 deletions
@@ -12,14 +12,18 @@ class AdministratorSharedService
) {
}
public function getSemester(): string
public function getSemester(?string $override = null): string
{
return (string) ($this->configuration->getConfig('semester') ?? '');
$value = trim((string) $override);
return $value !== '' ? $value : (string) ($this->configuration->getConfig('semester') ?? '');
}
public function getSchoolYear(): string
public function getSchoolYear(?string $override = null): string
{
return (string) ($this->configuration->getConfig('school_year') ?? '');
$value = trim((string) $override);
return $value !== '' ? $value : (string) ($this->configuration->getConfig('school_year') ?? '');
}
public function getPreviousSchoolYear(string $schoolYear): string
@@ -146,4 +150,4 @@ class AdministratorSharedService
return count(array_unique($ids));
}
}
}
@@ -12,13 +12,13 @@ class AdministratorTeacherSubmissionService
) {
}
public function report(): array
public function report(array $filters = []): array
{
return $this->reportService->report();
return $this->reportService->report($filters);
}
public function sendNotifications(Request $request, int $adminId): array
{
return $this->notificationService->send($request, $adminId);
}
}
}
@@ -32,7 +32,9 @@ class TeacherSubmissionNotificationService
}
$missingItemsPayload = $request->input('missing_items', []);
$targets = $this->extractTargets($notify);
$schoolYear = $this->shared->getSchoolYear($request->input('school_year'));
$semester = $this->shared->getSemester($request->input('semester'));
$targets = $this->extractTargets($notify, $schoolYear, $semester);
if (empty($targets)) {
return [
@@ -72,8 +74,7 @@ class TeacherSubmissionNotificationService
$sectionName = $classSections->get($classSectionId)?->class_section_name ?? "Section {$classSectionId}";
$teacherName = trim(($teacher->firstname ?? '') . ' ' . ($teacher->lastname ?? '')) ?: 'Teacher';
$missingPayload = $missingItemsPayload[$classSectionId][$teacherId] ?? '';
$missingItems = $this->support->parseMissingItemsPayload((string) $missingPayload);
$missingItems = $this->resolveMissingItems($missingItemsPayload, $classSectionId, $teacherId);
$missingNote = !empty($missingItems)
? '<p>Outstanding items: ' . e($this->support->formatMissingItemsText($missingItems)) . '.</p>'
@@ -111,8 +112,8 @@ class TeacherSubmissionNotificationService
'notification_category' => 'teacher_submissions',
'message' => $this->support->truncateNotificationMessage($body),
'status' => $status,
'school_year' => $this->shared->getSchoolYear(),
'semester' => $this->shared->getSemester(),
'school_year' => $schoolYear,
'semester' => $semester,
'sent_at' => now(),
]);
}
@@ -134,8 +135,31 @@ class TeacherSubmissionNotificationService
];
}
protected function extractTargets(array $notify): array
protected function extractTargets(array $notify, string $schoolYear, string $semester): array
{
if ($this->isFlatTeacherIdList($notify)) {
$teacherIds = array_values(array_unique(array_map('intval', array_filter($notify, static fn ($value) => (int) $value > 0))));
if (empty($teacherIds)) {
return [];
}
return ClassSection::query()
->select('teacher_class.class_section_id', 'teacher_class.teacher_id')
->join('teacher_class', 'teacher_class.class_section_id', '=', 'classSection.class_section_id')
->whereIn('teacher_class.teacher_id', $teacherIds)
->where('teacher_class.school_year', $schoolYear)
->where('teacher_class.semester', $semester)
->orderBy('teacher_class.class_section_id')
->get()
->map(static fn ($row): array => [
'class_section_id' => (int) $row->class_section_id,
'teacher_id' => (int) $row->teacher_id,
])
->filter(static fn (array $row): bool => $row['class_section_id'] > 0 && $row['teacher_id'] > 0)
->values()
->all();
}
$targets = [];
foreach ($notify as $sectionIdRaw => $teachers) {
@@ -159,4 +183,39 @@ class TeacherSubmissionNotificationService
return array_values($targets);
}
protected function isFlatTeacherIdList(array $notify): bool
{
foreach ($notify as $value) {
if (is_array($value)) {
return false;
}
}
return true;
}
protected function resolveMissingItems($payload, int $classSectionId, int $teacherId): array
{
if (!is_array($payload)) {
return [];
}
if (isset($payload[$classSectionId]) && is_array($payload[$classSectionId])) {
$sectionPayload = $payload[$classSectionId];
if (array_key_exists($teacherId, $sectionPayload) || array_key_exists((string) $teacherId, $sectionPayload)) {
$value = $sectionPayload[$teacherId] ?? $sectionPayload[(string) $teacherId] ?? null;
return $this->support->parseMissingItemsPayload($value);
}
}
if (array_key_exists($teacherId, $payload) || array_key_exists((string) $teacherId, $payload)) {
$value = $payload[$teacherId] ?? $payload[(string) $teacherId] ?? null;
return $this->support->parseMissingItemsPayload($value);
}
return [];
}
}
@@ -17,10 +17,10 @@ class TeacherSubmissionReportService
) {
}
public function report(): array
public function report(array $filters = []): array
{
$semester = $this->shared->getSemester();
$schoolYear = $this->shared->getSchoolYear();
$semester = $this->shared->getSemester($filters['semester'] ?? null);
$schoolYear = $this->shared->getSchoolYear($filters['school_year'] ?? null);
$assignmentRows = DB::table('teacher_class as tc')
->select([
@@ -230,6 +230,8 @@ class TeacherSubmissionReportService
'rows' => $rows,
'semester' => $semester,
'schoolYear' => $schoolYear,
'currentSemester' => $this->shared->getSemester(),
'currentSchoolYear' => $this->shared->getSchoolYear(),
'notificationHistory' => $historyMap,
'summary' => $summary,
];
@@ -83,8 +83,21 @@ class TeacherSubmissionSupportService
: mb_substr($text, 0, $limit) . '…';
}
public function parseMissingItemsPayload(string $payload): array
public function parseMissingItemsPayload($payload): array
{
if (is_array($payload)) {
$items = [];
foreach ($payload as $item) {
$item = trim((string) $item);
if ($item !== '') {
$items[] = $item;
}
}
return array_values(array_unique($items));
}
$payload = trim((string) $payload);
if ($payload === '') {
return [];
}