fix parent, teacher and admin pages

This commit is contained in:
root
2026-04-25 00:00:23 -04:00
parent 4cd98f1d30
commit eafe4eb134
30 changed files with 1566 additions and 105 deletions
@@ -106,6 +106,8 @@ class StudentController extends BaseApiController
$validator = Validator::make($data, [
'q' => ['nullable', 'string', 'max:255'],
'limit' => ['nullable', 'integer', 'min:1', 'max:1000'],
'class_section_id' => ['nullable', 'integer', 'min:1'],
'school_year' => ['nullable', 'string', 'max:32'],
]);
if ($validator->fails()) {
@@ -118,35 +120,24 @@ class StudentController extends BaseApiController
$payload = $validator->validated();
$query = trim((string) ($payload['q'] ?? ''));
$limit = (int) ($payload['limit'] ?? ($query !== '' ? 50 : 1000));
$classSectionId = isset($payload['class_section_id']) ? (int) $payload['class_section_id'] : null;
$schoolYear = isset($payload['school_year']) ? trim((string) $payload['school_year']) : null;
$studentsQuery = Student::query()
->select('id', 'school_id', 'firstname', 'lastname', 'is_active')
->where('is_active', 1);
if ($query !== '') {
$studentsQuery->where(function ($builder) use ($query) {
$builder->where('firstname', 'like', '%' . $query . '%')
->orWhere('lastname', 'like', '%' . $query . '%')
->orWhere('school_id', 'like', '%' . $query . '%');
});
$user = Auth::user();
if (! $user instanceof User) {
return response()->json([
'ok' => false,
'message' => 'Unauthorized.',
], 401);
}
$students = $studentsQuery
->orderBy('lastname')
->orderBy('firstname')
->limit($limit)
->get()
->map(fn (Student $student) => [
'id' => (int) $student->id,
'student_id' => (int) $student->id,
'school_id' => (string) ($student->school_id ?? ''),
'firstname' => (string) ($student->firstname ?? ''),
'lastname' => (string) ($student->lastname ?? ''),
'name' => trim(((string) ($student->firstname ?? '')) . ' ' . ((string) ($student->lastname ?? ''))),
'is_active' => (int) ($student->is_active ?? 0),
])
->values()
->all();
$students = $this->scoreCardService->scoreCardSelectableStudents(
$user,
$query,
$limit,
$classSectionId > 0 ? $classSectionId : null,
$schoolYear !== '' ? $schoolYear : null,
);
return response()->json([
'ok' => true,