From d2abbc1458b69d00f2a2c0985c52b1bb3db6cdb5 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Mar 2026 23:50:20 -0400 Subject: [PATCH] fix duplicate restored student --- app/Controllers/View/AssignmentController.php | 6 ++++++ app/Controllers/View/AttendanceController.php | 5 +++++ app/Controllers/View/GradingController.php | 7 ++++--- app/Controllers/View/HomeworkController.php | 6 ++---- app/Controllers/View/ProjectController.php | 6 ++---- app/Controllers/View/ScorePredictor.php | 8 ++++---- app/Views/administrator/daily_attendance.php | 12 +++++++++++- .../cache/navbar_cd1336c7da8c3f064f0b3b9e0c0a2232 | 2 +- 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/app/Controllers/View/AssignmentController.php b/app/Controllers/View/AssignmentController.php index 491da9c..1a44497 100644 --- a/app/Controllers/View/AssignmentController.php +++ b/app/Controllers/View/AssignmentController.php @@ -119,7 +119,12 @@ class AssignmentController extends BaseController } $students = []; + $seenStudentIds = []; foreach ($studentClasses as $studentClass) { + $sid = (int)($studentClass['student_id'] ?? 0); + if ($sid <= 0 || isset($seenStudentIds[$sid])) { + continue; + } if ($sectionSemester === '' && !empty($studentClass['semester'])) { $sectionSemester = (string)$studentClass['semester']; } @@ -149,6 +154,7 @@ class AssignmentController extends BaseController 'tuition_paid' => esc($student['tuition_paid'] ? 'Yes' : 'No'), 'school_id' => esc($student['school_id']), ]; + $seenStudentIds[$sid] = true; } $sectionSemesterDisplay = $sectionSemester !== '' ? $sectionSemester : ((string)($this->semester ?? '')); diff --git a/app/Controllers/View/AttendanceController.php b/app/Controllers/View/AttendanceController.php index f3b0962..3fdb1d3 100644 --- a/app/Controllers/View/AttendanceController.php +++ b/app/Controllers/View/AttendanceController.php @@ -1004,9 +1004,13 @@ public function showUpdateAttendanceForm() } $hasRoster = false; + $seenStudents = []; foreach ($students as $sc) { $studentId = (int)$sc['student_id']; + if ($studentId <= 0 || isset($seenStudents[$studentId])) { + continue; + } $student = $this->studentModel ->select('id, firstname, lastname, school_id') ->find($studentId); @@ -1014,6 +1018,7 @@ public function showUpdateAttendanceForm() $studentsBySection[$secCode][] = $student; $hasRoster = true; + $seenStudents[$studentId] = true; // Attendance history $qb = $this->attendanceDataModel diff --git a/app/Controllers/View/GradingController.php b/app/Controllers/View/GradingController.php index 6aa2480..9d385c0 100644 --- a/app/Controllers/View/GradingController.php +++ b/app/Controllers/View/GradingController.php @@ -278,7 +278,7 @@ class GradingController extends Controller $semEsc = $this->db->escape($semester); $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 $quizCounts = []; @@ -424,7 +424,7 @@ class GradingController extends Controller } } // Reload rows after refresh - $rows = $this->buildGradingRows($semEsc, $yrEsc, $schoolYear); + $rows = $this->buildGradingRows($semEsc, $yrEsc, $schoolYear, $semester); } // 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 * @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') ->select([ @@ -1605,6 +1605,7 @@ class GradingController extends Controller 'ss_b.class_section_id AS matched_biz_csid', 'ss_p.class_section_id AS matched_pk_csid' ]) + ->distinct() ->join('`classSection` cs', 'cs.class_section_id = sc.class_section_id', 'left') ->join('students s', 's.id = sc.student_id', 'inner') ->join( diff --git a/app/Controllers/View/HomeworkController.php b/app/Controllers/View/HomeworkController.php index 47594e7..b0a238d 100644 --- a/app/Controllers/View/HomeworkController.php +++ b/app/Controllers/View/HomeworkController.php @@ -482,6 +482,7 @@ class HomeworkController extends Controller // Step 1: Get student IDs from student_class table $studentClassRows = $this->studentClassModel ->select('student_id') + ->distinct() ->where('class_section_id', $classSectionId) ->where('school_year', $schoolYear) ->findAll(); @@ -534,10 +535,7 @@ class HomeworkController extends Controller private function getStudentsWithHomeworkScores($classSectionId, $homeworkHeaders, $semester, $schoolYear) { $semVariants = $this->getSemesterVariants($semester); - $studentClasses = $this->studentClassModel - ->active() - ->where('student_class.class_section_id', $classSectionId) - ->findAll(); + $studentClasses = $this->studentClassModel->getClassStudents($classSectionId, $schoolYear, null); $students = []; foreach ($studentClasses as $sc) { diff --git a/app/Controllers/View/ProjectController.php b/app/Controllers/View/ProjectController.php index 21eea66..69c2901 100644 --- a/app/Controllers/View/ProjectController.php +++ b/app/Controllers/View/ProjectController.php @@ -438,6 +438,7 @@ class ProjectController extends Controller // Step 1: Get student IDs from student_class table $studentClassRows = $studentClassModel ->select('student_id') + ->distinct() ->where('class_section_id', $classSectionId) ->where('school_year', $schoolYear) ->findAll(); @@ -494,10 +495,7 @@ class ProjectController extends Controller $studentModel = new StudentModel(); $projectModel = new ProjectModel(); - $studentClasses = $studentClassModel - ->active() - ->where('student_class.class_section_id', $classSectionId) - ->findAll(); + $studentClasses = $studentClassModel->getClassStudents($classSectionId, $this->schoolYear, null); $students = []; foreach ($studentClasses as $sc) { diff --git a/app/Controllers/View/ScorePredictor.php b/app/Controllers/View/ScorePredictor.php index a17d1ef..80d54f5 100644 --- a/app/Controllers/View/ScorePredictor.php +++ b/app/Controllers/View/ScorePredictor.php @@ -81,10 +81,10 @@ class ScorePredictor extends Controller s.school_id, s.firstname, s.lastname, - fall.semester_score as fall_score, - spring.semester_score as spring_score'); - // Also select class section for per-class trophy decision - $builder->select('sc.class_section_id as class_section_id'); + MAX(fall.semester_score) as fall_score, + MAX(spring.semester_score) as spring_score'); + // Reduce duplication from restored students while keeping a stable class section. + $builder->select('MAX(sc.class_section_id) as class_section_id'); $yearEsc = $this->db->escape($selectedYear); $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'); diff --git a/app/Views/administrator/daily_attendance.php b/app/Views/administrator/daily_attendance.php index c80d250..97e1485 100644 --- a/app/Views/administrator/daily_attendance.php +++ b/app/Views/administrator/daily_attendance.php @@ -696,7 +696,17 @@ - + +