fix enrollment for the new school-year
Tests / PHPUnit (push) Successful in 1m26s

This commit is contained in:
root
2026-08-07 23:43:31 -04:00
parent b6f3b14e7b
commit 1ef2800f12
66 changed files with 8997 additions and 498 deletions
+53 -1
View File
@@ -254,7 +254,41 @@ class FamilyAdminController extends BaseController
LIMIT 1",
[$studentId]
)->getRowArray();
if (!empty($row['id'])) $familyId = (int) $row['id'];
if (!empty($row['id'])) {
$familyId = (int) $row['id'];
} else {
// Legacy/newly-created students can have students.parent_id set
// before the normalized family_students row is created.
$row = $db->query(
"SELECT f.id
FROM students s
JOIN family_guardians fg ON fg.user_id = s.parent_id
JOIN families f ON f.id = fg.family_id
WHERE s.id = ?
ORDER BY fg.is_primary DESC, f.household_name
LIMIT 1",
[$studentId]
)->getRowArray();
if (!empty($row['id'])) {
$familyId = (int) $row['id'];
} else {
$row = $db->query(
"SELECT f.id
FROM students s
JOIN families f ON f.family_code = CONCAT('FAM-', s.parent_id)
WHERE s.id = ?
AND s.parent_id IS NOT NULL
ORDER BY f.household_name
LIMIT 1",
[$studentId]
)->getRowArray();
if (!empty($row['id'])) {
$familyId = (int) $row['id'];
}
}
}
} elseif ($guardianId) {
// 1) Try via guardians link
$row = $db->query(
@@ -330,6 +364,24 @@ class FamilyAdminController extends BaseController
ORDER BY s.lastname, s.firstname",
[$familyId]
)->getResultArray();
if ($studentId > 0) {
$studentIds = array_map(static fn(array $row): int => (int) ($row['id'] ?? 0), $studentsRows);
if (!in_array($studentId, $studentIds, true)) {
$selectedStudent = $db->query(
"SELECT id, firstname, lastname
FROM students
WHERE id = ?
LIMIT 1",
[$studentId]
)->getRowArray();
if ($selectedStudent) {
$studentsRows[] = $selectedStudent;
}
}
}
if (!empty($studentsRows)) {
foreach ($studentsRows as &$sr) {
$sid = (int) ($sr['id'] ?? 0);