fix is_new issue with enrollment fixes
This commit is contained in:
@@ -542,7 +542,7 @@ class StudentController extends BaseController
|
||||
|
||||
// Retrieve students with an enrollment in the selected year (any status)
|
||||
$students = $this->studentModel
|
||||
->select('students.id, students.firstname, students.lastname, students.registration_date, students.is_new, students.age, students.parent_id, students.registration_grade')
|
||||
->select('students.id, students.firstname, students.lastname, students.registration_date, students.age, students.parent_id, students.registration_grade')
|
||||
->join('enrollments e', 'e.student_id = students.id', 'inner')
|
||||
->where('e.school_year', $selectedYear)
|
||||
->groupBy('students.id')
|
||||
@@ -552,11 +552,13 @@ class StudentController extends BaseController
|
||||
// Fallback: if none found (data inconsistency), include students even without an enrollment row
|
||||
if (empty($students)) {
|
||||
$students = $this->studentModel
|
||||
->select('students.id, students.firstname, students.lastname, students.registration_date, students.is_new, students.age, students.parent_id, students.registration_grade')
|
||||
->select('students.id, students.firstname, students.lastname, students.registration_date, students.age, students.parent_id, students.registration_grade')
|
||||
->orderBy('students.lastname', 'ASC')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
service('studentYearStatus')->attachToStudents($students, $selectedYear);
|
||||
|
||||
$studentData = [];
|
||||
foreach ($students as $student) {
|
||||
$sectionNames = $this->studentClassModel->getClassSectionsByStudentIdWithFlags((int)$student['id'], $selectedYear, true);
|
||||
@@ -2608,7 +2610,6 @@ class StudentController extends BaseController
|
||||
'school_year' => $in['school_year'] ?: null,
|
||||
'rfid_tag' => $in['rfid_tag'] ?: null,
|
||||
'semester' => $in['semester'] ?: null,
|
||||
'is_new' => (int) ($in['is_new'] === '1'),
|
||||
];
|
||||
|
||||
// Normalize health lists (server-side safety)
|
||||
@@ -2631,6 +2632,13 @@ class StudentController extends BaseController
|
||||
->with('errors', $this->studentModel->errors() ?: []);
|
||||
}
|
||||
|
||||
$statusYear = $in['school_year'] !== ''
|
||||
? $in['school_year']
|
||||
: (string) ($this->currentSchoolYearName((string) ($this->schoolYear ?? '')) ?: '');
|
||||
if ($statusYear !== '') {
|
||||
service('studentYearStatus')->upsert($id, $statusYear, $in['is_new'] === '1');
|
||||
}
|
||||
|
||||
// Only sync health lists when user actually changed them (touched=1)
|
||||
// Fallback: if no touch flag but a non-empty value was explicitly posted, also sync.
|
||||
$medTouched = ($in['medical_touched'] === '1');
|
||||
|
||||
Reference in New Issue
Block a user