fix parent and teacher pages to follow year filter
Tests / PHPUnit (push) Failing after 1m15s

This commit is contained in:
root
2026-07-15 20:03:36 -04:00
parent feb1b29a32
commit 5f27dccd0f
32 changed files with 582 additions and 364 deletions
+21 -35
View File
@@ -2,7 +2,7 @@
namespace App\Controllers\View;
use CodeIgniter\Controller;
use App\Controllers\BaseController;
use App\Models\TeacherClassModel;
use App\Models\StudentClassModel;
use App\Models\StudentModel;
@@ -28,7 +28,7 @@ use App\Models\MissingScoreOverrideModel;
class ScoreController extends Controller
class ScoreController extends BaseController
{
protected $semesterScoreService;
protected $db;
@@ -88,6 +88,8 @@ class ScoreController extends Controller
public function index()
{
log_message('debug', 'ScoreController::index invoked');
$schoolYearContext = $this->resolveSchoolYearContext();
$this->schoolYear = $schoolYearContext->yearName();
$semesterChoiceParam = $this->request->getGet('semester_choice');
$session = session();
if ($this->request->getGet('choose_semester') !== null) {
@@ -139,25 +141,13 @@ class ScoreController extends Controller
);
if (empty($assignments)) {
// Fallback: any class regardless of term
$fallback = $this->teacherClassModel
->where('teacher_id', $teacherId)
->first();
if ($fallback) {
$assignments = [[
'class_section_id' => $fallback['class_section_id'],
'class_section_name' => null,
'school_year' => $fallback['school_year'] ?? $effectiveSchoolYear,
'semester' => $fallback['semester'] ?? $effectiveSemester,
]];
$effectiveSemester = $fallback['semester'] ?? $effectiveSemester;
$effectiveSchoolYear = $fallback['school_year'] ?? $effectiveSchoolYear;
} else {
log_message('info', 'No class section assigned to teacher ID: ' . $teacherId);
return redirect()
->to('no-classes')
->with('message', 'You do not have an assigned class yet. Please contact the administration.');
}
log_message(
'info',
"No {$effectiveSchoolYear} {$effectiveSemester} class section assigned to teacher ID: {$teacherId}"
);
return redirect()
->to('no-classes')
->with('message', 'You do not have an assigned class for the selected school year and semester. Please contact the administration.');
}
$allowedIds = array_map(static fn($a) => (int)($a['class_section_id'] ?? 0), $assignments);
@@ -222,6 +212,7 @@ class ScoreController extends Controller
$csRow = $this->db->table('classSection')
->select('class_section_name')
->where('class_section_id', $classSectionId)
->where('school_year', $effectiveSchoolYear)
->get()->getRowArray();
$classSectionName = $csRow['class_section_name'] ?? '';
log_message('debug', "ScoreController::index teacher {$teacherId} classSection {$classSectionId} semester {$effectiveSemester}");
@@ -281,6 +272,7 @@ class ScoreController extends Controller
'focusTarget' => $focusTarget,
'schoolYear' => $effectiveSchoolYear,
'scoresLocked' => $scoresLocked,
'isSchoolYearReadonly' => $schoolYearContext->isReadonly(),
];
return view('/teacher/scores', $data);
@@ -288,11 +280,13 @@ class ScoreController extends Controller
public function submitScoresLock()
{
$schoolYearContext = $this->resolveSchoolYearContext();
$this->assertSchoolYearWritable($schoolYearContext);
$classSectionId = (int) ($this->request->getPost('class_section_id') ?? session()->get('class_section_id') ?? 0);
$semesterRaw = (string) ($this->request->getPost('semester') ?? $this->request->getPost('selected_semester') ?? '');
$semesterNormalized = $this->normalizeSemester($semesterRaw);
$semester = $semesterNormalized !== '' ? ucfirst($semesterNormalized) : $this->semester;
$schoolYear = (string) ($this->request->getPost('school_year') ?? $this->schoolYear);
$schoolYear = $schoolYearContext->yearName();
if ($classSectionId <= 0 || $semester === '' || $schoolYear === '') {
return redirect()->back()->with('error', 'Missing class section or term.');
@@ -496,6 +490,7 @@ class ScoreController extends Controller
$studentClasses = $this->studentClassModel
->active()
->where('student_class.class_section_id', $classSectionId)
->where('student_class.school_year', $schoolYear)
->findAll();
foreach ($studentClasses as $studentClass) {
@@ -1086,6 +1081,9 @@ class ScoreController extends Controller
public function updateScores(string $table, ?string $redirectUrl = null)
{
$schoolYearContext = $this->resolveSchoolYearContext();
$this->assertSchoolYearWritable($schoolYearContext);
$this->schoolYear = $schoolYearContext->yearName();
$builder = $this->db->table($table);
$scores = $this->request->getPost('final_score'); // name must match input form
@@ -1322,18 +1320,7 @@ public function viewStudentScore()
return redirect()->back()->with('error', 'Unable to retrieve student data. Please contact support.');
}
// Handle selected school year (parents can view scores for any available year)
$selectedYear = $this->request->getVar('school_year') ?? $this->schoolYear;
// Fetch distinct school years only from semester_scores
$query = $this->db->table('semester_scores')
->select('school_year')
->distinct()
->get();
$schoolYears = array_column($query->getResultArray(), 'school_year');
$schoolYears = array_unique($schoolYears);
rsort($schoolYears);
$selectedYear = $this->currentSchoolYearName((string) ($this->schoolYear ?? ''));
// Initialize scores array
$scores = [];
@@ -1402,7 +1389,6 @@ $students = $this->db->table('students')
return view('/parent/scores', [
'organizedScores' => $scores,
'schoolYears' => $schoolYears,
'selectedYear' => $selectedYear,
'semesterOrder' => ['Fall', 'Spring'],
'showExamScores' => $releaseAny,