This commit is contained in:
@@ -365,13 +365,33 @@ class StudentModel extends Model
|
||||
$schoolYear = trim((string) $schoolYear);
|
||||
$studentClassJoin = 'student_class.student_id = students.id';
|
||||
$enrollmentJoin = 'enrollments.student_id = students.id';
|
||||
$selectedYearFilter = '';
|
||||
|
||||
if ($schoolYear !== '') {
|
||||
$studentClassJoin .= ' AND student_class.school_year = ' . $this->db->escape($schoolYear);
|
||||
$enrollmentJoin .= ' AND enrollments.school_year = ' . $this->db->escape($schoolYear);
|
||||
$escapedSchoolYear = $this->db->escape($schoolYear);
|
||||
$studentClassJoin .= ' AND student_class.school_year = ' . $escapedSchoolYear;
|
||||
$enrollmentJoin .= ' AND enrollments.school_year = ' . $escapedSchoolYear;
|
||||
$selectedYearFilter = "
|
||||
(
|
||||
student_class.student_id IS NOT NULL
|
||||
OR enrollments.student_id IS NOT NULL
|
||||
OR (
|
||||
NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM student_class sc_history
|
||||
WHERE sc_history.student_id = students.id
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM enrollments e_history
|
||||
WHERE e_history.student_id = students.id
|
||||
)
|
||||
)
|
||||
)
|
||||
";
|
||||
}
|
||||
|
||||
return $this->select('
|
||||
$builder = $this->select('
|
||||
students.*,
|
||||
student_class.class_section_id,
|
||||
enrollments.enrollment_status,
|
||||
@@ -381,7 +401,13 @@ class StudentModel extends Model
|
||||
')
|
||||
->join('student_class', $studentClassJoin, 'left')
|
||||
->join('enrollments', $enrollmentJoin, 'left')
|
||||
->join('users u', 'u.id = students.parent_id', 'left')
|
||||
->join('users u', 'u.id = students.parent_id', 'left');
|
||||
|
||||
if ($selectedYearFilter !== '') {
|
||||
$builder->where($selectedYearFilter, null, false);
|
||||
}
|
||||
|
||||
return $builder
|
||||
// keep your original grouping as-is so behavior doesn't change
|
||||
->groupBy('students.id, student_class.class_section_id, enrollments.enrollment_status, enrollments.admission_status')
|
||||
->findAll();
|
||||
|
||||
Reference in New Issue
Block a user