fix registration enrollment of students
This commit is contained in:
@@ -380,6 +380,7 @@ class ParentController extends BaseController
|
||||
}
|
||||
unset($student);
|
||||
|
||||
$this->ensureStudentYearStatusRows($students, $selectedYear);
|
||||
service('studentYearStatus')->attachToStudents($students, $selectedYear);
|
||||
foreach ($students as &$student) {
|
||||
$studentId = (int) ($student['id'] ?? 0);
|
||||
@@ -528,7 +529,7 @@ class ParentController extends BaseController
|
||||
}
|
||||
|
||||
$studentName = trim((string) ($studentInfo['firstname'] ?? '') . ' ' . (string) ($studentInfo['lastname'] ?? '')) ?: 'Student ID ' . $studentId;
|
||||
if (empty($evaluation['can_enroll'])) {
|
||||
if (empty($evaluation['can_enroll']) && empty($evaluation['parent_enrollment_allowed'])) {
|
||||
$transitionService->logEnrollmentBlock($evaluation, 'parent_enroll_submit', (int) $parentId, (int) $parentId);
|
||||
$messages = array_values(array_filter(array_map('trim', array_map('strval', $evaluation['blockers'] ?? []))));
|
||||
$codes = array_values(array_filter(array_map('strval', array_merge($evaluation['blocking_rule_codes'] ?? [], $evaluation['review_rule_codes'] ?? []))));
|
||||
@@ -1951,6 +1952,7 @@ class ParentController extends BaseController
|
||||
if ($this->hasSettledParentEnrollmentStatus($existingStatus, $existingAdmissionStatus)) {
|
||||
$payload[] = [
|
||||
'student_id' => $studentId,
|
||||
'student_name' => trim((string) ($student['firstname'] ?? '') . ' ' . (string) ($student['lastname'] ?? '')) ?: 'Student ID ' . $studentId,
|
||||
'can_enroll' => false,
|
||||
'primary_block_reason' => 'ALREADY_ENROLLED',
|
||||
'primary_parent_message' => EnrollmentEligibility::alreadyEnrolledMessage($existingStatus),
|
||||
@@ -1969,7 +1971,10 @@ class ParentController extends BaseController
|
||||
);
|
||||
$payload[] = [
|
||||
'student_id' => $studentId,
|
||||
'student_name' => trim((string) ($student['firstname'] ?? '') . ' ' . (string) ($student['lastname'] ?? '')) ?: 'Student ID ' . $studentId,
|
||||
'can_enroll' => (bool) ($evaluation['can_enroll'] ?? false),
|
||||
'parent_enrollment_allowed' => (bool) ($evaluation['parent_enrollment_allowed'] ?? $evaluation['can_enroll'] ?? false),
|
||||
'first_enrollment' => (bool) ($evaluation['first_enrollment'] ?? false),
|
||||
'primary_block_reason' => $evaluation['primary_block_reason'] ?? null,
|
||||
'primary_parent_message' => $evaluation['primary_parent_message'] ?? null,
|
||||
'blocking_rule_codes' => array_values(array_map('strval', $evaluation['blocking_rule_codes'] ?? [])),
|
||||
@@ -2008,7 +2013,10 @@ class ParentController extends BaseController
|
||||
|
||||
foreach ($students as $student) {
|
||||
$evaluation = is_array($student['transition_evaluation'] ?? null) ? $student['transition_evaluation'] : [];
|
||||
if (($evaluation['can_enroll'] ?? false) !== true) {
|
||||
if (
|
||||
($evaluation['can_enroll'] ?? false) !== true
|
||||
&& ($evaluation['parent_enrollment_allowed'] ?? false) !== true
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2123,7 +2131,7 @@ class ParentController extends BaseController
|
||||
'parent'
|
||||
);
|
||||
|
||||
if (($evaluation['can_enroll'] ?? false) === true) {
|
||||
if (($evaluation['can_enroll'] ?? false) === true || ($evaluation['parent_enrollment_allowed'] ?? false) === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2800,6 +2808,7 @@ class ParentController extends BaseController
|
||||
}
|
||||
unset($kid);
|
||||
|
||||
$this->ensureStudentYearStatusRows($kids, $selectedSchoolYear);
|
||||
service('studentYearStatus')->attachToStudents($kids, $selectedSchoolYear);
|
||||
|
||||
foreach ($kids as &$kid) {
|
||||
@@ -2821,6 +2830,33 @@ class ParentController extends BaseController
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $students
|
||||
*/
|
||||
private function ensureStudentYearStatusRows(array $students, string $schoolYear): void
|
||||
{
|
||||
$schoolYear = trim($schoolYear);
|
||||
if ($students === [] || ! preg_match('/^\d{4}-\d{4}$/', $schoolYear)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$studentYearStatus = service('studentYearStatus');
|
||||
foreach ($students as $student) {
|
||||
$studentId = (int) ($student['id'] ?? $student['student_id'] ?? 0);
|
||||
if ($studentId <= 0 || $studentYearStatus->hasStatus($studentId, $schoolYear)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$isNew = (int) ($student['is_new'] ?? 1) === 1;
|
||||
if (! $studentYearStatus->upsert($studentId, $schoolYear, $isNew)) {
|
||||
log_message('error', 'Unable to repair student_year_status for student_id={studentId}, school_year={schoolYear}', [
|
||||
'studentId' => $studentId,
|
||||
'schoolYear' => $schoolYear,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function validateAndSaveOrUpdateStudent($idx, $parentId, $semester, $schoolYear, $schoolIdService, $isNew = null, $studentId = null)
|
||||
{
|
||||
$firstName = $this->request->getPost('studentFirstName')[$idx] ?? null;
|
||||
@@ -2883,8 +2919,10 @@ class ParentController extends BaseController
|
||||
'photo_consent' => $photoConsent,
|
||||
'parent_id' => (int) $parentId,
|
||||
'year_of_registration' => date('Y'),
|
||||
'school_year' => $schoolYear,
|
||||
];
|
||||
if ($this->db->fieldExists('school_year', 'students')) {
|
||||
$studentData['school_year'] = $schoolYear;
|
||||
}
|
||||
|
||||
if (!is_null($isNew)) {
|
||||
$studentData['is_new'] = $isNew ? 1 : 0;
|
||||
@@ -2950,7 +2988,11 @@ class ParentController extends BaseController
|
||||
}
|
||||
|
||||
if (! is_null($isNew) && (int) $studentId > 0) {
|
||||
service('studentYearStatus')->upsert((int) $studentId, (string) $schoolYear, (bool) $isNew);
|
||||
$studentYearStatus = service('studentYearStatus');
|
||||
$statusSaved = $studentYearStatus->upsert((int) $studentId, (string) $schoolYear, (bool) $isNew);
|
||||
if (! $statusSaved || ! $studentYearStatus->hasStatus((int) $studentId, (string) $schoolYear)) {
|
||||
throw new \RuntimeException('Student year status could not be saved for student ID ' . (int) $studentId . ' and school year ' . (string) $schoolYear . '.');
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- SAVE MEDICAL CONDITIONS ----------
|
||||
|
||||
Reference in New Issue
Block a user