fix is_new issue with enrollment fixes
This commit is contained in:
@@ -78,6 +78,23 @@ class StudentClassModel extends Model
|
||||
return $builder->groupEnd();
|
||||
}
|
||||
|
||||
private function latestEnrollmentJoinCondition(string $schoolYear): string
|
||||
{
|
||||
$schoolYear = trim($schoolYear);
|
||||
$yearCondition = $schoolYear !== ''
|
||||
? 'e_latest.school_year = ' . $this->db->escape($schoolYear)
|
||||
: 'e_latest.school_year = student_class.school_year';
|
||||
|
||||
return 'enrollments.id = (
|
||||
SELECT e_latest.id
|
||||
FROM enrollments e_latest
|
||||
WHERE e_latest.student_id = student_class.student_id
|
||||
AND ' . $yearCondition . '
|
||||
ORDER BY e_latest.updated_at DESC, e_latest.enrollment_date DESC, e_latest.id DESC
|
||||
LIMIT 1
|
||||
)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fresh builder scoped to active students.
|
||||
*/
|
||||
@@ -174,10 +191,9 @@ class StudentClassModel extends Model
|
||||
)
|
||||
->join(
|
||||
'enrollments',
|
||||
$schoolYear !== ''
|
||||
? 'enrollments.student_id = student_class.student_id AND enrollments.school_year = ' . $this->db->escape($schoolYear)
|
||||
: 'enrollments.student_id = student_class.student_id',
|
||||
'left'
|
||||
$this->latestEnrollmentJoinCondition($schoolYear),
|
||||
'left',
|
||||
false
|
||||
)
|
||||
->where(
|
||||
'student_class.class_section_id',
|
||||
@@ -249,8 +265,9 @@ class StudentClassModel extends Model
|
||||
)
|
||||
->join(
|
||||
'enrollments',
|
||||
'enrollments.student_id = student_class.student_id AND enrollments.school_year = ' . $this->db->escape($schoolYear),
|
||||
'left'
|
||||
$this->latestEnrollmentJoinCondition($schoolYear),
|
||||
'left',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -436,7 +453,7 @@ class StudentClassModel extends Model
|
||||
'students.lastname',
|
||||
'students.school_id',
|
||||
'students.is_active',
|
||||
'students.is_new',
|
||||
'COALESCE(sys.is_new, 1) AS is_new',
|
||||
'students.photo_consent',
|
||||
'students.age',
|
||||
'student_class.school_year',
|
||||
@@ -451,12 +468,18 @@ class StudentClassModel extends Model
|
||||
'inner'
|
||||
)
|
||||
->join(
|
||||
'enrollments',
|
||||
'student_year_status sys',
|
||||
$schoolYear !== ''
|
||||
? 'enrollments.student_id = student_class.student_id AND enrollments.school_year = ' . $this->db->escape($schoolYear)
|
||||
: 'enrollments.student_id = student_class.student_id',
|
||||
? 'sys.student_id = students.id AND sys.school_year = ' . $this->db->escape($schoolYear)
|
||||
: 'sys.student_id = students.id AND sys.school_year = student_class.school_year',
|
||||
'left'
|
||||
)
|
||||
->join(
|
||||
'enrollments',
|
||||
$this->latestEnrollmentJoinCondition($schoolYear),
|
||||
'left',
|
||||
false
|
||||
)
|
||||
->whereIn(
|
||||
'student_class.class_section_id',
|
||||
$classSectionIds
|
||||
@@ -580,8 +603,9 @@ class StudentClassModel extends Model
|
||||
)
|
||||
->join(
|
||||
'enrollments',
|
||||
'enrollments.student_id = student_class.student_id AND enrollments.school_year = ' . $this->db->escape($schoolYear),
|
||||
'left'
|
||||
$this->latestEnrollmentJoinCondition($schoolYear),
|
||||
'left',
|
||||
false
|
||||
);
|
||||
} else {
|
||||
$schoolYear = '';
|
||||
|
||||
Reference in New Issue
Block a user