Fix last-name exception carry-forward and parent action label
Tests / PHPUnit (push) Successful in 55s

This commit is contained in:
root
2026-08-15 21:20:51 -04:00
parent 3cbfc40934
commit 717baaea79
3 changed files with 40 additions and 7 deletions
+34 -1
View File
@@ -1445,6 +1445,20 @@ final class EnrollmentTransitionService
return;
}
$approvedStudentIds = $this->exceptionFamilyStudentIds($prior);
$currentStudentIds = $this->linkedStudentIds($parentId);
sort($currentStudentIds);
if ($approvedStudentIds !== [] && $approvedStudentIds !== $currentStudentIds) {
$evaluation['last_name_exception_carry_forward'] = [
'eligible' => false,
'prior_exception_id' => (int) ($prior['id'] ?? 0),
'prior_school_year' => (string) ($prior['school_year'] ?? ''),
'approved_student_ids' => $approvedStudentIds,
'reason' => 'NEW_STUDENT_ADDED',
];
return;
}
$this->removeRuleCode($evaluation, 'SIBLING_LAST_NAME_MISMATCH');
$this->addRuleCode($evaluation, 'LAST_NAME_EXCEPTION_CARRIED_FORWARD', 'warning');
$evaluation['warnings'] = array_values(array_unique(array_merge(
@@ -1456,7 +1470,7 @@ final class EnrollmentTransitionService
'eligible' => true,
'prior_exception_id' => (int) ($prior['id'] ?? 0),
'prior_school_year' => (string) ($prior['school_year'] ?? ''),
'approved_student_ids' => [(int) ($prior['student_id'] ?? $studentId)],
'approved_student_ids' => $approvedStudentIds !== [] ? $approvedStudentIds : [(int) ($prior['student_id'] ?? $studentId)],
];
}
@@ -1522,6 +1536,25 @@ final class EnrollmentTransitionService
return in_array('SIBLING_LAST_NAME_MISMATCH', $codes, true);
}
/**
* @return list<int>
*/
private function exceptionFamilyStudentIds(array $exception): array
{
$ids = json_decode((string) ($exception['family_student_ids_json'] ?? ''), true);
if (! is_array($ids)) {
return [];
}
$ids = array_values(array_unique(array_filter(array_map(
static fn ($id): int => (int) $id,
$ids
), static fn (int $id): bool => $id > 0)));
sort($ids);
return $ids;
}
private function linkedStudentsForParent(int $parentId): array
{
if ($parentId <= 0 || ! $this->db->tableExists('students')) {