fix duplicate restored student
This commit is contained in:
@@ -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 ?? ''));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user