fix is_active student flag and apply it in all pages
This commit is contained in:
@@ -55,6 +55,32 @@ class StudentClassModel extends Model
|
||||
return $this->db->table($this->table);
|
||||
}
|
||||
|
||||
private function includeActiveOrTerminalEnrollment(BaseBuilder $builder, string $schoolYear): BaseBuilder
|
||||
{
|
||||
$terminalStatuses = array_map([$this->db, 'escape'], [
|
||||
'denied',
|
||||
'withdrawn',
|
||||
'widthran',
|
||||
'widthrawan',
|
||||
'withdrawan',
|
||||
'waitlist',
|
||||
]);
|
||||
|
||||
$builder->groupStart()
|
||||
->where('students.is_active', 1);
|
||||
|
||||
if ($schoolYear !== '') {
|
||||
$builder->orWhere(
|
||||
'LOWER(TRIM(enrollments.enrollment_status)) IN (' . implode(',', $terminalStatuses) . ')',
|
||||
null,
|
||||
false
|
||||
)
|
||||
->orWhere('enrollments.is_withdrawn', 1);
|
||||
}
|
||||
|
||||
return $builder->groupEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fresh builder scoped to active students.
|
||||
*/
|
||||
@@ -131,7 +157,8 @@ class StudentClassModel extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active students assigned to a class section.
|
||||
* Get students assigned to a class section, including inactive students with
|
||||
* terminal current-year enrollment statuses.
|
||||
*
|
||||
* student_class is scoped by school year only. It has no semester column.
|
||||
*/
|
||||
@@ -139,7 +166,22 @@ class StudentClassModel extends Model
|
||||
int $classSectionId,
|
||||
?string $schoolYear = null
|
||||
): array {
|
||||
$builder = $this->activeStudentsBuilder()
|
||||
$schoolYear = $schoolYear !== null ? trim($schoolYear) : '';
|
||||
|
||||
$builder = $this->freshBuilder()
|
||||
->select('student_class.*, students.is_active, enrollments.enrollment_status, enrollments.is_withdrawn')
|
||||
->join(
|
||||
'students',
|
||||
'students.id = student_class.student_id',
|
||||
'inner'
|
||||
)
|
||||
->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'
|
||||
)
|
||||
->where(
|
||||
'student_class.class_section_id',
|
||||
$classSectionId
|
||||
@@ -150,13 +192,15 @@ class StudentClassModel extends Model
|
||||
false
|
||||
);
|
||||
|
||||
if ($schoolYear !== null && trim($schoolYear) !== '') {
|
||||
if ($schoolYear !== '') {
|
||||
$builder->where(
|
||||
'student_class.school_year',
|
||||
trim($schoolYear)
|
||||
$schoolYear
|
||||
);
|
||||
}
|
||||
|
||||
$this->includeActiveOrTerminalEnrollment($builder, $schoolYear);
|
||||
|
||||
$rows = $builder
|
||||
->orderBy('students.lastname', 'ASC')
|
||||
->orderBy('students.firstname', 'ASC')
|
||||
@@ -195,7 +239,6 @@ class StudentClassModel extends Model
|
||||
'student_class.class_section_id',
|
||||
$classSectionId
|
||||
)
|
||||
->where('students.is_active', 1)
|
||||
->where(
|
||||
'student_class.class_section_id IS NOT NULL',
|
||||
null,
|
||||
@@ -206,9 +249,16 @@ class StudentClassModel extends Model
|
||||
$builder->where(
|
||||
'student_class.school_year',
|
||||
$schoolYear
|
||||
)
|
||||
->join(
|
||||
'enrollments',
|
||||
'enrollments.student_id = student_class.student_id AND enrollments.school_year = ' . $this->db->escape($schoolYear),
|
||||
'left'
|
||||
);
|
||||
}
|
||||
|
||||
$this->includeActiveOrTerminalEnrollment($builder, $schoolYear);
|
||||
|
||||
$rows = $builder
|
||||
->groupBy('student_class.student_id')
|
||||
->get()
|
||||
@@ -364,7 +414,8 @@ class StudentClassModel extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Return active students for a set of class-section IDs.
|
||||
* Return students for a set of class-section IDs, including inactive
|
||||
* students with terminal current-year enrollment statuses.
|
||||
*/
|
||||
public function getStudentsByClassSectionIds(
|
||||
array $classSectionIds,
|
||||
@@ -379,37 +430,50 @@ class StudentClassModel extends Model
|
||||
return [];
|
||||
}
|
||||
|
||||
$schoolYear = $schoolYear !== null ? trim($schoolYear) : '';
|
||||
|
||||
$builder = $this->freshBuilder()
|
||||
->select([
|
||||
'students.id AS student_id',
|
||||
'students.firstname',
|
||||
'students.lastname',
|
||||
'students.school_id',
|
||||
'students.is_active',
|
||||
'students.is_new',
|
||||
'students.photo_consent',
|
||||
'students.age',
|
||||
'student_class.school_year',
|
||||
'student_class.class_section_id',
|
||||
'student_class.is_event_only',
|
||||
'enrollments.enrollment_status',
|
||||
'enrollments.is_withdrawn',
|
||||
])
|
||||
->join(
|
||||
'students',
|
||||
'students.id = student_class.student_id',
|
||||
'inner'
|
||||
)
|
||||
->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'
|
||||
)
|
||||
->whereIn(
|
||||
'student_class.class_section_id',
|
||||
$classSectionIds
|
||||
)
|
||||
->where('students.is_active', 1);
|
||||
);
|
||||
|
||||
if ($schoolYear !== null && trim($schoolYear) !== '') {
|
||||
if ($schoolYear !== '') {
|
||||
$builder->where(
|
||||
'student_class.school_year',
|
||||
trim($schoolYear)
|
||||
$schoolYear
|
||||
);
|
||||
}
|
||||
|
||||
$this->includeActiveOrTerminalEnrollment($builder, $schoolYear);
|
||||
|
||||
return $builder
|
||||
->orderBy('students.lastname', 'ASC')
|
||||
->orderBy('students.firstname', 'ASC')
|
||||
@@ -504,7 +568,6 @@ class StudentClassModel extends Model
|
||||
'students.id = student_class.student_id',
|
||||
'inner'
|
||||
)
|
||||
->where('students.is_active', 1)
|
||||
->where(
|
||||
'student_class.class_section_id IS NOT NULL',
|
||||
null,
|
||||
@@ -513,12 +576,22 @@ class StudentClassModel extends Model
|
||||
->groupBy('student_class.class_section_id');
|
||||
|
||||
if ($schoolYear !== null && trim($schoolYear) !== '') {
|
||||
$schoolYear = trim($schoolYear);
|
||||
$builder->where(
|
||||
'student_class.school_year',
|
||||
trim($schoolYear)
|
||||
$schoolYear
|
||||
)
|
||||
->join(
|
||||
'enrollments',
|
||||
'enrollments.student_id = student_class.student_id AND enrollments.school_year = ' . $this->db->escape($schoolYear),
|
||||
'left'
|
||||
);
|
||||
} else {
|
||||
$schoolYear = '';
|
||||
}
|
||||
|
||||
$this->includeActiveOrTerminalEnrollment($builder, $schoolYear);
|
||||
|
||||
$rows = $builder
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
Reference in New Issue
Block a user