fix teacher pages display between school years
Tests / PHPUnit (push) Failing after 1m12s

This commit is contained in:
root
2026-07-15 20:52:19 -04:00
parent 5f27dccd0f
commit 9de2ab2a9f
9 changed files with 106 additions and 53 deletions
+11 -1
View File
@@ -57,6 +57,7 @@ class LandingPageController extends BaseController
// Fetch Enrollment and Refund Deadlines from Configuration
$this->schoolYear = $this->configModel->getConfig('school_year');
$this->semester = $this->configModel->getConfig('semester');
$this->schoolYear = $this->selectedSchoolYearName((string) ($this->schoolYear ?? ''));
$this->lastDayOfRegistration = $this->configModel->getConfig('enrollment_deadline') ?? 'Not set';
$this->refundDeadline = $this->configModel->getConfig('refund_deadline') ?? 'Not set';
@@ -103,7 +104,7 @@ class LandingPageController extends BaseController
// Get all class assignments for this teacher in the current term
$assignments = $this->teacherClassModel->getClassAssignmentsByUserId(
(int)$user_id,
(string)$this->schoolYear,
$this->selectedSchoolYearName((string) ($this->schoolYear ?? '')),
(string)$this->semester
);
@@ -126,6 +127,15 @@ class LandingPageController extends BaseController
return $chosen;
}
private function selectedSchoolYearName(string $fallback): string
{
try {
return service('schoolYearContext')->resolve(service('request'))->yearName();
} catch (\Throwable) {
return $fallback;
}
}
public function administrator()
{
+4 -8
View File
@@ -1673,14 +1673,10 @@ class StudentController extends BaseController
$students = [];
if (in_array($role, ['parent', 'parent_dashboard'], true)) {
$schoolYear = $this->currentSchoolYearName((string) ($this->schoolYear ?? ''));
$parentId = (int)(session()->get('user_id') ?? 0);
if ($parentId > 0) {
$students = $this->studentModel
->select('id, school_id, firstname, lastname')
->where('parent_id', $parentId)
->orderBy('lastname', 'ASC')
->orderBy('firstname', 'ASC')
->findAll();
if ($parentId > 0 && $schoolYear !== '') {
$students = $this->studentModel->getByParentAndYear($parentId, $schoolYear);
}
} elseif (in_array($role, ['teacher', 'teacher_assistant', 'teacher_dashboard'], true)) {
$schoolYear = $this->currentSchoolYearName((string) ($this->schoolYear ?? ''));
@@ -1706,7 +1702,7 @@ class StudentController extends BaseController
)), static fn($v) => $v > 0));
if (!empty($sectionIds)) {
$studentClassModel = new \App\Models\StudentClassModel();
$rows = $studentClassModel->getStudentsByClassSectionIds($sectionIds);
$rows = $studentClassModel->getStudentsByClassSectionIds($sectionIds, $schoolYear);
$unique = [];
foreach ($rows as $r) {
$sid = (int)($r['student_id'] ?? 0);
+2 -2
View File
@@ -57,6 +57,7 @@ class TeacherController extends BaseController
// Retrieve the configuration values
$this->semester = $this->configModel->getConfig('semester');
$this->schoolYear = $this->configModel->getConfig('school_year');
$this->schoolYear = $this->currentSchoolYearName((string) ($this->schoolYear ?? ''));
}
@@ -123,7 +124,7 @@ class TeacherController extends BaseController
if (!empty($classSectionIds)) {
// 1) Fetch all students for the selected class sections
$students = $this->studentClassModel->getStudentsByClassSectionIds($classSectionIds);
$students = $this->studentClassModel->getStudentsByClassSectionIds($classSectionIds, (string) $this->schoolYear);
if (!empty($students)) {
// 2) Collect unique student IDs
@@ -344,7 +345,6 @@ class TeacherController extends BaseController
'section_id' => $sectionId,
'class_section_name' => $classNames[$sectionId] ?? 'N/A',
'role' => $role,
'semester' => (string)($assign['semester'] ?? $this->semester ?? ''),
'school_year' => (string)($assign['school_year'] ?? $schoolYear),
];
}