update policy and fix other issues
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 49s
Tests / PHPUnit (push) Successful in 1m19s

This commit is contained in:
root
2026-08-23 18:19:08 -04:00
parent 103f970110
commit a6e0ce1432
13 changed files with 433 additions and 317 deletions
+59 -29
View File
@@ -55,7 +55,12 @@ class StudentClassModel extends Model
return $this->db->table($this->table);
}
private function includeActiveOrTerminalEnrollment(BaseBuilder $builder, string $schoolYear): BaseBuilder
private function includeActiveOrTerminalEnrollment(
BaseBuilder $builder,
string $schoolYear,
bool $hasEnrollmentStatus = false,
bool $hasEnrollmentWithdrawn = false
): BaseBuilder
{
$terminalStatuses = array_map([$this->db, 'escape'], [
'denied',
@@ -66,13 +71,16 @@ class StudentClassModel extends Model
$builder->groupStart()
->where('students.is_active', 1);
if ($schoolYear !== '') {
if ($schoolYear !== '' && $hasEnrollmentStatus) {
$builder->orWhere(
'LOWER(TRIM(enrollments.enrollment_status)) IN (' . implode(',', $terminalStatuses) . ')',
null,
false
)
->orWhere('enrollments.is_withdrawn', 1);
);
}
if ($schoolYear !== '' && $hasEnrollmentWithdrawn) {
$builder->orWhere('enrollments.is_withdrawn', 1);
}
return $builder->groupEnd();
@@ -446,44 +454,61 @@ class StudentClassModel extends Model
$schoolYear = $schoolYear !== null ? trim($schoolYear) : '';
$hasStudentYearStatus = $this->db->tableExists('student_year_status')
&& $this->db->fieldExists('is_new', 'student_year_status');
$hasEventOnly = $this->db->fieldExists('is_event_only', 'student_class');
$hasEnrollments = $this->db->tableExists('enrollments');
$hasEnrollmentStatus = $hasEnrollments && $this->db->fieldExists('enrollment_status', 'enrollments');
$hasEnrollmentWithdrawn = $hasEnrollments && $this->db->fieldExists('is_withdrawn', 'enrollments');
$select = [
'students.id AS student_id',
'students.firstname',
'students.lastname',
'students.school_id',
'students.is_active',
$hasStudentYearStatus ? 'COALESCE(sys.is_new, 1) AS is_new' : '1 AS is_new',
'students.photo_consent',
'students.age',
'student_class.school_year',
'student_class.class_section_id',
$hasEventOnly ? 'student_class.is_event_only' : '0 AS is_event_only',
$hasEnrollmentStatus ? 'enrollments.enrollment_status' : 'NULL AS enrollment_status',
$hasEnrollmentWithdrawn ? 'enrollments.is_withdrawn' : '0 AS is_withdrawn',
];
$builder = $this->freshBuilder()
->select([
'students.id AS student_id',
'students.firstname',
'students.lastname',
'students.school_id',
'students.is_active',
'COALESCE(sys.is_new, 1) AS 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',
])
->select($select)
->join(
'students',
'students.id = student_class.student_id',
'inner'
)
->join(
);
if ($hasStudentYearStatus) {
$builder->join(
'student_year_status sys',
$schoolYear !== ''
? '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(
'left',
false
);
}
if ($hasEnrollments) {
$builder->join(
'enrollments',
$this->latestEnrollmentJoinCondition($schoolYear),
'left',
false
)
->whereIn(
'student_class.class_section_id',
$classSectionIds
);
}
$builder->whereIn(
'student_class.class_section_id',
$classSectionIds
);
if ($schoolYear !== '') {
$builder->where(
@@ -492,7 +517,12 @@ class StudentClassModel extends Model
);
}
$this->includeActiveOrTerminalEnrollment($builder, $schoolYear);
$this->includeActiveOrTerminalEnrollment(
$builder,
$schoolYear,
$hasEnrollmentStatus,
$hasEnrollmentWithdrawn
);
return $builder
->orderBy('students.lastname', 'ASC')