Files
alrahma_sunday_school_api/app/Services/ClassSections/ClassAttendanceService.php
T
2026-06-11 11:46:12 -04:00

33 lines
1.2 KiB
PHP

<?php
namespace App\Services\ClassSections;
use App\Models\ClassSection;
use App\Models\Configuration;
use App\Models\Student;
use App\Models\User;
class ClassAttendanceService
{
public function getAttendancePayload(int $classSectionId, int $teacherId, ?string $schoolYear = null, ?string $semester = null): array
{
$schoolYear = $schoolYear ?: (string) (Configuration::getConfig('school_year') ?? '');
$semester = $semester ?: (string) (Configuration::getConfig('semester') ?? '');
$teacher = User::query()->find($teacherId);
$teacherName = trim((string) ($teacher?->firstname ?? '').' '.(string) ($teacher?->lastname ?? ''));
$className = ClassSection::getClassSectionNameBySectionId($classSectionId) ?? (string) $classSectionId;
$students = Student::getStudentInfoByClassSectionId($classSectionId, $semester, $schoolYear, $teacherId);
return [
'teacher_name' => $teacherName,
'class_name' => $className,
'class_section_id' => $classSectionId,
'semester' => $semester,
'school_year' => $schoolYear,
'students' => $students,
];
}
}