fix registration enrollment of students
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 48s
Tests / PHPUnit (push) Successful in 1m19s

This commit is contained in:
root
2026-08-26 21:36:03 -04:00
parent a354d78fa9
commit 9676261d65
7 changed files with 208 additions and 53 deletions
@@ -302,7 +302,7 @@ final class EnrollmentRegistrationEmailService
return 'KG students may complete registration now. ' . $name . ' is eligible for re-enrollment even though no final deliberation decision is recorded.' . $placementText;
}
if (($evaluation['can_enroll'] ?? false) === false && ! empty($evaluation['primary_parent_message'])) {
if (! $this->canCompleteParentReEnrollment($evaluation) && ! empty($evaluation['primary_parent_message'])) {
return (string) $evaluation['primary_parent_message'];
}
@@ -655,7 +655,7 @@ final class EnrollmentRegistrationEmailService
return $placement;
}
return ($evaluation['can_enroll'] ?? false) === true ? 'Pending' : '';
return $this->canCompleteParentReEnrollment($evaluation) ? 'Pending' : '';
}
private function requiredAction(array $evaluation, string $deadline, string $name = 'The student'): string
+29 -13
View File
@@ -707,7 +707,35 @@ final class EnrollmentTransitionService
}
}
return trim((string) ($student['school_year'] ?? '')) === $targetSchoolYear;
if ($this->db->fieldExists('school_year', 'students')) {
return trim((string) ($student['school_year'] ?? '')) === $targetSchoolYear;
}
return ! $this->studentHasPriorSchoolHistory($studentId, $targetSchoolYear);
}
private function studentHasPriorSchoolHistory(int $studentId, string $targetSchoolYear): bool
{
if ($studentId <= 0) {
return false;
}
foreach (['student_class', 'enrollments', 'student_decisions'] as $table) {
if (! $this->db->tableExists($table) || ! $this->db->fieldExists('school_year', $table)) {
continue;
}
$count = $this->db->table($table)
->where('student_id', $studentId)
->where('school_year !=', $targetSchoolYear)
->countAllResults();
if ($count > 0) {
return true;
}
}
return false;
}
private function schoolYearByName(string $schoolYear): ?array
@@ -2009,19 +2037,7 @@ final class EnrollmentTransitionService
private function applyHouseholdLastNameRule(array &$evaluation, int $parentId, ?string $sourceSchoolYear = null): void
{
if (! empty($evaluation['first_enrollment'])) {
$evaluation['family_name_check_ok'] = true;
return;
}
$students = $this->linkedStudentsForParent($parentId);
$sourceSchoolYear = trim((string) $sourceSchoolYear);
if ($sourceSchoolYear !== '') {
$students = array_values(array_filter(
$students,
fn (array $student): bool => $this->sourceAssignment((int) ($student['id'] ?? 0), $sourceSchoolYear) !== null
));
}
if (count($students) <= 1) {
$evaluation['family_name_check_ok'] = true;
+22 -6
View File
@@ -40,15 +40,15 @@ class StudentYearStatusService
return (int) ($row['is_new'] ?? 1) === 1;
}
public function upsert(int $studentId, string $schoolYear, bool $isNew): void
public function upsert(int $studentId, string $schoolYear, bool $isNew): bool
{
if ($studentId <= 0) {
return;
return false;
}
$schoolYear = trim($schoolYear);
if (! preg_match('/^\d{4}-\d{4}$/', $schoolYear) || ! $this->db->tableExists('student_year_status')) {
return;
return false;
}
$flag = $isNew ? 1 : 0;
@@ -59,19 +59,35 @@ class StudentYearStatusService
->first();
if (is_array($existing) && isset($existing['id'])) {
$this->yearStatusModel->update((int) $existing['id'], [
return (bool) $this->yearStatusModel->update((int) $existing['id'], [
'is_new' => $flag,
]);
return;
}
$this->yearStatusModel->insert([
return (bool) $this->yearStatusModel->insert([
'student_id' => $studentId,
'school_year' => $schoolYear,
'is_new' => $flag,
]);
}
public function hasStatus(int $studentId, string $schoolYear): bool
{
if ($studentId <= 0) {
return false;
}
$schoolYear = trim($schoolYear);
if (! preg_match('/^\d{4}-\d{4}$/', $schoolYear) || ! $this->db->tableExists('student_year_status')) {
return false;
}
return $this->yearStatusModel
->where('student_id', $studentId)
->where('school_year', $schoolYear)
->countAllResults() > 0;
}
/**
* Mark students who existed in a source school year as returning in the target year.
*