Grades 1..11 -> Youth (12) -> any other ids (ascending)
$semester = $semester ?? (session()->get('semester') ?? 'Fall');
$schoolYear = $schoolYear ?? (session()->get('school_year') ?? date('Y') . '-' . (date('Y') + 1));
$requestedClassId = isset($requestedClassId) ? (int)$requestedClassId : 0;
$semesterOptions = $semesterOptions ?? [];
$scoreLocks = $scoreLocks ?? [];
if (empty($semesterOptions)) {
$semesterOptions = ['Fall', 'Spring'];
}
if ($semester !== '' && !in_array($semester, $semesterOptions, true)) {
$semesterOptions[] = $semester;
}
$semesterOptions = array_values(array_unique($semesterOptions));
// Slug from class_id
$slugFor = function (int $cid): string {
if ($cid === 13) return 'kg';
if ($cid === 12) return 'youth';
if ($cid >= 1 && $cid <= 11) return 'g' . $cid;
return (string)$cid;
};
// Compose ordered class ids from keys actually present in $grades
$presentIds = array_map('intval', array_keys($grades));
$presentSet = array_flip($presentIds);
$sortedClassIds = [];
if (isset($presentSet[13])) $sortedClassIds[] = 13; // KG first
for ($g = 1; $g <= 11; $g++) if (isset($presentSet[$g])) $sortedClassIds[] = $g; // Grades 1..11
if (isset($presentSet[12])) $sortedClassIds[] = 12; // Youth last
// Include any other unexpected ids (edge cases) without breaking
$others = array_diff($presentIds, $sortedClassIds);
sort($others, SORT_NUMERIC);
$sortedClassIds = array_merge($sortedClassIds, $others);
// Label overrides for non-standard class ids (e.g., Arabic-1)
$classLabelById = [];
foreach ($grades as $cid => $sections) {
if (!empty($sections[0]['class_section_name'])) {
$classLabelById[(int) $cid] = (string) $sections[0]['class_section_name'];
}
}
// Label from class_id
$labelFor = function (int $cid) use ($classLabelById): string {
if ($cid === 13) return 'KG';
if ($cid === 12) return 'Youth';
if ($cid >= 1 && $cid <= 11) return 'Grade ' . $cid;
if (!empty($classLabelById[$cid])) return $classLabelById[$cid];
return 'Class ' . $cid;
};
// Distinct student counts per class_id for tab badges
$studentsCountByClassId = [];
foreach ($grades as $cid => $sections) {
$uniq = [];
foreach ($sections as $section) {
$secId = (int)($section['class_section_id'] ?? 0);
if ($secId > 0 && !empty($studentsBySection[$secId])) {
foreach ($studentsBySection[$secId] as $stu) {
if (!empty($stu['id'])) $uniq[(int)$stu['id']] = true;
}
}
}
$studentsCountByClassId[(int)$cid] = count($uniq);
}
$scoreStatusByClass = [];
foreach ($grades as $cid => $sections) {
$allLocked = true;
$hasSection = false;
foreach ($sections as $section) {
$secId = (int)($section['class_section_id'] ?? 0);
if ($secId <= 0) {
continue;
}
$hasSection = true;
if (empty($scoreLocks[$secId])) {
$allLocked = false;
break;
}
}
$scoreStatusByClass[(int)$cid] = $hasSection && $allLocked;
}
// Default active tab
$defaultId = ($requestedClassId > 0 && isset($presentSet[$requestedClassId]))
? $requestedClassId
: ($sortedClassIds[0] ?? null);
// Sort each class’s sections by displayed name (e.g., 1-A, 1-B…)
foreach ($grades as $cid => &$sections) {
usort($sections, function ($a, $b) {
return strnatcasecmp($a['class_section_name'] ?? '', $b['class_section_name'] ?? '');
});
}
unset($sections);
?>
= esc(ucfirst($semester)) ?> • = esc($schoolYear) ?>
= esc($label) ?> — Class Sections
No sections in this class.
No students in this section.
| School ID |
Student First Name |
Student Last Name |
Homework Avg |
Project Avg |
Participation |
Test/Quiz Avg |
Attendance |
PTAP |
Midterm |
Final |
DBG Biz CSID |
DBG PK CSID |
Semester Score |
| = esc($student['school_id'] ?? 'N/A') ?> |
= esc($student['firstname'] ?? 'N/A') ?>
= esc($student['firstname'] ?? 'N/A') ?>
|
= esc($student['lastname'] ?? 'N/A') ?>
= esc($student['lastname'] ?? 'N/A') ?>
|
= $displayScore($student['homework_avg'] ?? null) ?> |
= $displayScore($student['project_avg'] ?? null) ?> |
= $displayScore($student['participation'] ?? null) ?> |
= $displayScore($student['quiz_avg'] ?? null) ?> |
= $displayScore($student['attendance'] ?? null) ?> |
|
= $displayScore($student['midterm_exam'] ?? null) ?> |
= $displayScore($student['final_exam'] ?? null) ?> |
= esc($student['matched_biz_csid'] ?? '') ?> |
= esc($student['matched_pk_csid'] ?? '') ?> |
|