0) { $schoolYear = trim((string)($schoolYear ?? '')); if ($schoolYear === '') { try { $schoolYear = (string)((new \App\Models\ConfigurationModel())->getConfig('school_year') ?? ''); } catch (\Throwable $e) { $schoolYear = ''; } } static $statusCache = []; $cacheKey = $studentId . ':' . $schoolYear; if (!array_key_exists($cacheKey, $statusCache)) { $statusCache[$cacheKey] = ''; if ($schoolYear !== '') { try { $row = db_connect()->table('enrollments') ->select('enrollment_status, is_withdrawn') ->where('student_id', $studentId) ->where('school_year', $schoolYear) ->orderBy('updated_at', 'DESC') ->orderBy('enrollment_date', 'DESC') ->orderBy('id', 'DESC') ->get(1) ->getRowArray(); $rowStatus = strtolower(trim((string)($row['enrollment_status'] ?? ''))); if ($rowStatus === 'withdrawn student' || (int)($row['is_withdrawn'] ?? 0) === 1) { $rowStatus = 'withdrawn'; } $statusCache[$cacheKey] = $rowStatus; } catch (\Throwable $e) { $statusCache[$cacheKey] = ''; } } } if (($statusCache[$cacheKey] ?? '') !== '') { $status = $statusCache[$cacheKey]; } } return $status; } } if (!function_exists('student_is_non_active_for_editing')) { function student_is_non_active_for_editing(array $student, ?string $schoolYear = null): bool { $status = student_normalized_enrollment_status($student, $schoolYear); if (in_array($status, ['denied', 'withdrawn', 'waitlist'], true)) { return true; } return array_key_exists('is_active', $student) && (int)$student['is_active'] !== 1; } } if (!function_exists('student_enrollment_status_button')) { function student_enrollment_status_button(array $student, ?string $schoolYear = null): string { $status = student_normalized_enrollment_status($student, $schoolYear); $classes = [ 'denied' => 'btn-outline-danger', 'withdrawn' => 'btn-outline-secondary', 'waitlist' => 'btn-outline-warning', ]; if (!isset($classes[$status])) { return ''; } return '
' . esc(ucwords($status)) . '
'; } }