fix duplicate restored student

This commit is contained in:
root
2026-03-30 23:50:20 -04:00
parent b52475ff0b
commit d2abbc1458
8 changed files with 35 additions and 17 deletions
@@ -119,7 +119,12 @@ class AssignmentController extends BaseController
} }
$students = []; $students = [];
$seenStudentIds = [];
foreach ($studentClasses as $studentClass) { foreach ($studentClasses as $studentClass) {
$sid = (int)($studentClass['student_id'] ?? 0);
if ($sid <= 0 || isset($seenStudentIds[$sid])) {
continue;
}
if ($sectionSemester === '' && !empty($studentClass['semester'])) { if ($sectionSemester === '' && !empty($studentClass['semester'])) {
$sectionSemester = (string)$studentClass['semester']; $sectionSemester = (string)$studentClass['semester'];
} }
@@ -149,6 +154,7 @@ class AssignmentController extends BaseController
'tuition_paid' => esc($student['tuition_paid'] ? 'Yes' : 'No'), 'tuition_paid' => esc($student['tuition_paid'] ? 'Yes' : 'No'),
'school_id' => esc($student['school_id']), 'school_id' => esc($student['school_id']),
]; ];
$seenStudentIds[$sid] = true;
} }
$sectionSemesterDisplay = $sectionSemester !== '' ? $sectionSemester : ((string)($this->semester ?? '')); $sectionSemesterDisplay = $sectionSemester !== '' ? $sectionSemester : ((string)($this->semester ?? ''));
@@ -1004,9 +1004,13 @@ public function showUpdateAttendanceForm()
} }
$hasRoster = false; $hasRoster = false;
$seenStudents = [];
foreach ($students as $sc) { foreach ($students as $sc) {
$studentId = (int)$sc['student_id']; $studentId = (int)$sc['student_id'];
if ($studentId <= 0 || isset($seenStudents[$studentId])) {
continue;
}
$student = $this->studentModel $student = $this->studentModel
->select('id, firstname, lastname, school_id') ->select('id, firstname, lastname, school_id')
->find($studentId); ->find($studentId);
@@ -1014,6 +1018,7 @@ public function showUpdateAttendanceForm()
$studentsBySection[$secCode][] = $student; $studentsBySection[$secCode][] = $student;
$hasRoster = true; $hasRoster = true;
$seenStudents[$studentId] = true;
// Attendance history // Attendance history
$qb = $this->attendanceDataModel $qb = $this->attendanceDataModel
+4 -3
View File
@@ -278,7 +278,7 @@ class GradingController extends Controller
$semEsc = $this->db->escape($semester); $semEsc = $this->db->escape($semester);
$yrEsc = $this->db->escape($schoolYear); $yrEsc = $this->db->escape($schoolYear);
$rows = $this->buildGradingRows($semEsc, $yrEsc, $schoolYear); $rows = $this->buildGradingRows($semEsc, $yrEsc, $schoolYear, $semester);
// Preload quiz/homework/project/participation/midterm score counts to distinguish true zeros from empty scores // Preload quiz/homework/project/participation/midterm score counts to distinguish true zeros from empty scores
$quizCounts = []; $quizCounts = [];
@@ -424,7 +424,7 @@ class GradingController extends Controller
} }
} }
// Reload rows after refresh // Reload rows after refresh
$rows = $this->buildGradingRows($semEsc, $yrEsc, $schoolYear); $rows = $this->buildGradingRows($semEsc, $yrEsc, $schoolYear, $semester);
} }
// Build structures keyed by BUSINESS section id // Build structures keyed by BUSINESS section id
@@ -1577,7 +1577,7 @@ class GradingController extends Controller
* @param string $schoolYear Raw school year value for filtering student_class * @param string $schoolYear Raw school year value for filtering student_class
* @return array * @return array
*/ */
private function buildGradingRows(string $semEsc, string $yrEsc, string $schoolYear): array private function buildGradingRows(string $semEsc, string $yrEsc, string $schoolYear, string $semesterRaw): array
{ {
$builder = $this->db->table('student_class sc') $builder = $this->db->table('student_class sc')
->select([ ->select([
@@ -1605,6 +1605,7 @@ class GradingController extends Controller
'ss_b.class_section_id AS matched_biz_csid', 'ss_b.class_section_id AS matched_biz_csid',
'ss_p.class_section_id AS matched_pk_csid' 'ss_p.class_section_id AS matched_pk_csid'
]) ])
->distinct()
->join('`classSection` cs', 'cs.class_section_id = sc.class_section_id', 'left') ->join('`classSection` cs', 'cs.class_section_id = sc.class_section_id', 'left')
->join('students s', 's.id = sc.student_id', 'inner') ->join('students s', 's.id = sc.student_id', 'inner')
->join( ->join(
+2 -4
View File
@@ -482,6 +482,7 @@ class HomeworkController extends Controller
// Step 1: Get student IDs from student_class table // Step 1: Get student IDs from student_class table
$studentClassRows = $this->studentClassModel $studentClassRows = $this->studentClassModel
->select('student_id') ->select('student_id')
->distinct()
->where('class_section_id', $classSectionId) ->where('class_section_id', $classSectionId)
->where('school_year', $schoolYear) ->where('school_year', $schoolYear)
->findAll(); ->findAll();
@@ -534,10 +535,7 @@ class HomeworkController extends Controller
private function getStudentsWithHomeworkScores($classSectionId, $homeworkHeaders, $semester, $schoolYear) private function getStudentsWithHomeworkScores($classSectionId, $homeworkHeaders, $semester, $schoolYear)
{ {
$semVariants = $this->getSemesterVariants($semester); $semVariants = $this->getSemesterVariants($semester);
$studentClasses = $this->studentClassModel $studentClasses = $this->studentClassModel->getClassStudents($classSectionId, $schoolYear, null);
->active()
->where('student_class.class_section_id', $classSectionId)
->findAll();
$students = []; $students = [];
foreach ($studentClasses as $sc) { foreach ($studentClasses as $sc) {
+2 -4
View File
@@ -438,6 +438,7 @@ class ProjectController extends Controller
// Step 1: Get student IDs from student_class table // Step 1: Get student IDs from student_class table
$studentClassRows = $studentClassModel $studentClassRows = $studentClassModel
->select('student_id') ->select('student_id')
->distinct()
->where('class_section_id', $classSectionId) ->where('class_section_id', $classSectionId)
->where('school_year', $schoolYear) ->where('school_year', $schoolYear)
->findAll(); ->findAll();
@@ -494,10 +495,7 @@ class ProjectController extends Controller
$studentModel = new StudentModel(); $studentModel = new StudentModel();
$projectModel = new ProjectModel(); $projectModel = new ProjectModel();
$studentClasses = $studentClassModel $studentClasses = $studentClassModel->getClassStudents($classSectionId, $this->schoolYear, null);
->active()
->where('student_class.class_section_id', $classSectionId)
->findAll();
$students = []; $students = [];
foreach ($studentClasses as $sc) { foreach ($studentClasses as $sc) {
+4 -4
View File
@@ -81,10 +81,10 @@ class ScorePredictor extends Controller
s.school_id, s.school_id,
s.firstname, s.firstname,
s.lastname, s.lastname,
fall.semester_score as fall_score, MAX(fall.semester_score) as fall_score,
spring.semester_score as spring_score'); MAX(spring.semester_score) as spring_score');
// Also select class section for per-class trophy decision // Reduce duplication from restored students while keeping a stable class section.
$builder->select('sc.class_section_id as class_section_id'); $builder->select('MAX(sc.class_section_id) as class_section_id');
$yearEsc = $this->db->escape($selectedYear); $yearEsc = $this->db->escape($selectedYear);
$builder->join('student_class sc', 'sc.student_id = s.id AND sc.school_year = ' . $yearEsc, 'left'); $builder->join('student_class sc', 'sc.student_id = s.id AND sc.school_year = ' . $yearEsc, 'left');
$builder->join('classSection cs', 'cs.class_section_id = sc.class_section_id', 'left'); $builder->join('classSection cs', 'cs.class_section_id = sc.class_section_id', 'left');
+11 -1
View File
@@ -696,7 +696,17 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($studentsBySection[$sectionKey] as $student): ?> <?php
$uniqueStudents = [];
foreach ($studentsBySection[$sectionKey] as $student) {
$sid = (int)($student['id'] ?? 0);
if ($sid <= 0 || isset($uniqueStudents[$sid])) {
continue;
}
$uniqueStudents[$sid] = $student;
}
?>
<?php foreach ($uniqueStudents as $student): ?>
<?php <?php
$sid = (int)$student['id']; $sid = (int)$student['id'];
$entryMap = $recAt($__attendanceData[$sectionKey][$sid] ?? []); $entryMap = $recAt($__attendanceData[$sectionKey][$sid] ?? []);
File diff suppressed because one or more lines are too long