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
+34 -15
View File
@@ -5,7 +5,7 @@ namespace App\Controllers\View;
use App\Models\HomeworkModel;
use App\Models\StudentModel;
use App\Models\StudentClassModel;
use CodeIgniter\Controller;
use App\Controllers\BaseController;
use App\Models\TeacherClassModel;
use App\Models\ConfigurationModel;
use App\Models\UserModel;
@@ -16,7 +16,7 @@ use App\Controllers\View\GradingController;
use App\Models\GradingLockModel;
use App\Models\MissingScoreOverrideModel;
class HomeworkController extends Controller
class HomeworkController extends BaseController
{
protected $db;
protected $semesterScoreService;
@@ -59,11 +59,12 @@ class HomeworkController extends Controller
}
}
public function updateHomeworkScores(array $scores = null, int $updatedBy = null, int $classSectionId = null)
public function updateHomeworkScores(?array $scores = null, ?int $updatedBy = null, ?int $classSectionId = null)
{
$scores = $this->request->getPost('scores');
$semester = $this->request->getPost('semester') ?? $this->semester;
$schoolYear = $this->request->getPost('school_year') ?? $this->schoolYear;
$schoolYear = $this->currentSchoolYearName((string) ($this->schoolYear ?? ''));
$this->assertSchoolYearWritable($this->resolveSchoolYearContext());
if ($updatedBy === null) {
$updatedBy = session()->get('user_id');
@@ -195,6 +196,8 @@ class HomeworkController extends Controller
$selectedSemester = $this->getSelectedSemester();
$normalized = $this->normalizeSemesterSelection($selectedSemester);
$semesterLabel = $normalized !== '' ? ucfirst($normalized) : $selectedSemester;
$schoolYear = $this->currentSchoolYearName((string) ($this->schoolYear ?? ''));
$this->assertSchoolYearWritable($this->resolveSchoolYearContext());
// Step 1: Get the highest existing homework_index
$existingIndexes = $this->homeworkModel
@@ -202,7 +205,7 @@ class HomeworkController extends Controller
->where('class_section_id', $classSectionId)
//->where('teacher_id', $updatedBy)
->whereIn('semester', $this->getSemesterVariants($semesterLabel))
->where('school_year', $this->schoolYear)
->where('school_year', $schoolYear)
->groupBy('homework_index')
->orderBy('homework_index', 'DESC')
->findAll();
@@ -219,6 +222,7 @@ class HomeworkController extends Controller
// Step 2: Get all students in the class
$students = $this->studentClassModel
->where('class_section_id', $classSectionId)
->where('school_year', $schoolYear)
->findAll();
// Step 3: Insert a new homework row for each student if not already exists
@@ -233,7 +237,7 @@ class HomeworkController extends Controller
->where('class_section_id', $classSectionId)
//->where('teacher_id', $updatedBy)
->whereIn('semester', $this->getSemesterVariants($semesterLabel))
->where('school_year', $this->schoolYear)
->where('school_year', $schoolYear)
->first();
if ($existing) continue;
@@ -246,7 +250,7 @@ class HomeworkController extends Controller
'homework_index' => $nextIndex,
'score' => null,
'semester' => $semesterLabel,
'school_year' => $this->schoolYear,
'school_year' => $schoolYear,
'created_at' => utc_now(),
'updated_at' => utc_now()
];
@@ -269,15 +273,23 @@ class HomeworkController extends Controller
public function showHomework()
{
$updatedBy = session()->get('user_id');
$classSectionId = $this->getClassSectionIdForTeacher($updatedBy);
$semester = $this->getSelectedSemester();
$schoolYear = $this->currentSchoolYearName((string) ($this->schoolYear ?? ''));
$classSectionId = (int) (
$this->request->getGet('class_section_id')
?? $this->request->getPost('class_section_id')
?? 0
);
if ($classSectionId <= 0) {
$classSectionId = (int) ($this->getClassSectionIdForTeacher($updatedBy, $schoolYear, $semester) ?? 0);
}
if (!$classSectionId) {
return redirect()->back()->with('status', 'No class section found for the current teacher.');
}
session()->set('class_section_id', $classSectionId);
$semester = $this->getSelectedSemester();
$homeworkHeaders = $this->getHomeworkHeaders($classSectionId, $semester, $this->schoolYear);
$homeworkHeaders = $this->getHomeworkHeaders($classSectionId, $semester, $schoolYear);
if (empty($homeworkHeaders)) {
$homeworkHeaders = [1];
}
@@ -285,15 +297,15 @@ class HomeworkController extends Controller
$classSectionId,
$homeworkHeaders,
$semester,
$this->schoolYear
$schoolYear
);
$missingOkMap = $this->missingScoreOverrideModel->getOverridesMap($classSectionId, $semester, $this->schoolYear, 'homework');
$missingOkMap = $this->missingScoreOverrideModel->getOverridesMap($classSectionId, $semester, $schoolYear, 'homework');
return view('teacher/add_homework', [
'students' => $students,
'homeworkHeaders' => $homeworkHeaders,
'semester' => $semester,
'schoolYear' => $this->schoolYear,
'schoolYear' => $schoolYear,
'class_section_id' => $classSectionId,
'missingOkMap' => $missingOkMap,
]);
@@ -503,9 +515,16 @@ class HomeworkController extends Controller
return $students;
}
private function getClassSectionIdForTeacher($updatedBy)
private function getClassSectionIdForTeacher($updatedBy, ?string $schoolYear = null, ?string $semester = null)
{
$class = $this->teacherClassModel->where('teacher_id', $updatedBy)->first();
$builder = $this->teacherClassModel->where('teacher_id', $updatedBy);
if ($schoolYear !== null && $schoolYear !== '') {
$builder->where('school_year', $schoolYear);
}
if ($semester !== null && $semester !== '') {
$builder->where('semester', $semester);
}
$class = $builder->first();
return $class['class_section_id'] ?? null;
}