where([ 'class_section_id' => $classSectionId, 'semester' => $semester, 'school_year' => $school_year ])->findAll(); } /** * Get attendance record for a specific student in a class section. * * @param int $student_id * @param int $classSectionId * @param string $semester * @param string $school_year * @return array|null */ public function getAttendanceRecord($student_id, $classSectionId, $semester, $school_year) { return $this->where([ 'student_id' => $student_id, 'class_section_id' => $classSectionId, 'semester' => $semester, 'school_year' => $school_year ])->first(); } /** * Update an existing attendance record. * * @param int $attendanceId * @param array $data * @return bool */ public function updateAttendanceRecord($attendanceId, $data) { return $this->update($attendanceId, $data); } /** * Increment attendance counters for a student. * * @param int $student_id * @param int $classSectionId * @param string $semester * @param string $school_year * @param array $increments (e.g., ['total_absence' => 1, 'total_presence' => 0]) * @return bool */ public function incrementAttendanceCounters($student_id, $classSectionId, $semester, $school_year, $increments) { $record = $this->getAttendanceRecord($student_id, $classSectionId, $semester, $school_year); if ($record) { foreach ($increments as $field => $value) { if (isset($record[$field])) { $record[$field] += $value; } } return $this->update($record['id'], $record); } return false; } public function getTotalAbsences($studentId, $semester, $schoolYear) { $records = $this->where('student_id', $studentId) ->where('semester', $semester) ->where('school_year', $schoolYear) ->findAll(); if (empty($records)) { return 0; } $totalAbsences = 0; foreach ($records as $record) { $totalAbsences += (int) ($record['total_absence'] ?? 0); } return $totalAbsences; } }