This commit is contained in:
@@ -256,31 +256,14 @@ class TeacherController extends BaseController
|
||||
|
||||
public function teacherClassAssignment()
|
||||
{
|
||||
$selectedYear = trim((string)($this->request->getGet('schoolYear') ?? $this->request->getGet('school_year') ?? ''));
|
||||
if ($selectedYear === '') {
|
||||
$selectedYear = (string)($this->schoolYear ?? 'Not Set');
|
||||
if ($redirect = $this->redirectWithoutLegacyTermFilters('administrator/teacher_class_assignment')) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
// Build distinct school years from classSection (fallback to configured year)
|
||||
try {
|
||||
$yearsRows = $this->db->table('classSection')
|
||||
->distinct()
|
||||
->select('school_year')
|
||||
->orderBy('school_year', 'DESC')
|
||||
->get()->getResultArray();
|
||||
$schoolYears = array_values(array_filter(array_map(static function ($r) {
|
||||
return isset($r['school_year']) ? (string)$r['school_year'] : null;
|
||||
}, $yearsRows)));
|
||||
if (empty($schoolYears) && !empty($this->schoolYear)) {
|
||||
$schoolYears = [(string)$this->schoolYear];
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$schoolYears = !empty($this->schoolYear) ? [(string)$this->schoolYear] : [];
|
||||
}
|
||||
$selectedYear = (string)($this->schoolYear ?? 'Not Set');
|
||||
|
||||
return view('administrator/teacher_class_assignment', [
|
||||
'schoolYear' => (string)$selectedYear,
|
||||
'schoolYears' => $schoolYears,
|
||||
'currentYear' => (string)($this->schoolYear ?? ''),
|
||||
'isCurrentYear' => ((string)$selectedYear === (string)($this->schoolYear ?? '')),
|
||||
'missingYear' => empty($this->schoolYear),
|
||||
@@ -292,6 +275,27 @@ class TeacherController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
private function redirectWithoutLegacyTermFilters(string $route): ?\CodeIgniter\HTTP\RedirectResponse
|
||||
{
|
||||
$legacyTermKeys = ['school_year', 'schoolYear', 'year', 'semester'];
|
||||
$query = $this->request->getGet();
|
||||
$hasLegacyTermFilter = false;
|
||||
|
||||
foreach ($legacyTermKeys as $key) {
|
||||
if (array_key_exists($key, $query)) {
|
||||
unset($query[$key]);
|
||||
$hasLegacyTermFilter = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasLegacyTermFilter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$target = site_url($route) . (!empty($query) ? '?' . http_build_query($query) : '');
|
||||
return redirect()->to($target);
|
||||
}
|
||||
|
||||
private function buildTeacherClassAssignmentPayload(?string $forYear = null): array
|
||||
{
|
||||
$classSectionModel = new ClassSectionModel();
|
||||
|
||||
Reference in New Issue
Block a user