fix issues related to school year
Tests / PHPUnit (push) Failing after 34s

This commit is contained in:
root
2026-07-31 18:52:25 -04:00
parent 8d7ee3b9fc
commit 09ea144bb2
23 changed files with 537 additions and 218 deletions
+6 -53
View File
@@ -7,6 +7,7 @@ use App\Models\StaffModel;
use App\Models\UserModel;
use App\Models\TeacherClassModel;
use App\Models\ConfigurationModel;
use App\Services\StaffDirectorySyncService;
class StaffController extends BaseController
{
@@ -16,6 +17,7 @@ class StaffController extends BaseController
protected $teacherClassModel;
protected $userModel;
protected $staffModel;
protected StaffDirectorySyncService $staffDirectorySync;
public function __construct()
{
@@ -24,6 +26,7 @@ class StaffController extends BaseController
$this->teacherClassModel = new TeacherClassModel();
$this->userModel = new UserModel();
$this->staffModel = new StaffModel();
$this->staffDirectorySync = service('staffDirectorySync');
// Retrieve the configuration values
$this->semester = $this->configModel->getConfig('semester');
@@ -38,61 +41,11 @@ class StaffController extends BaseController
$schoolYear = $this->currentSchoolYearName((string) ($this->schoolYear ?? ''));
// roles we never show
$excludedRoles = ['student', 'parent', 'guest', 'inactive']; // ← add inactive here
$staffList = $this->staffModel
->whereNotIn('LOWER(active_role)', array_map('strtolower', $excludedRoles))
->orderBy('created_at', 'DESC')
->findAll();
// Preload assignments for the selected school year (across all semesters),
// mirroring the logic used in teacher_class_assignment.
$assignRows = $this->teacherClassModel
->select('teacher_class.teacher_id, teacher_class.position, classSection.class_section_name')
->join('classSection', 'classSection.class_section_id = teacher_class.class_section_id', 'left')
->where('teacher_class.school_year', $schoolYear)
->findAll();
$assignByTeacher = [];
foreach ($assignRows as $r) {
$tid = (int)($r['teacher_id'] ?? 0);
if ($tid <= 0) { continue; }
$name = trim((string)($r['class_section_name'] ?? ''));
if ($name === '') { continue; }
$pos = strtolower((string)($r['position'] ?? ''));
if (!in_array($pos, ['main','ta'], true)) { continue; }
$assignByTeacher[$tid][] = $name . ' (' . $pos . ')';
}
$issuesCount = 0;
foreach ($staffList as &$staff) {
// attach school_id
$staff['school_id'] = $this->userModel->getSchoolIdByUserId($staff['user_id'] ?? null);
// Verify and attach class assignments for teacher/TA roles for the selected school year
$role = strtolower((string)($staff['active_role'] ?? ''));
if (in_array($role, ['teacher', 'teacher_assistant'], true)) {
$tid = (int)($staff['user_id'] ?? 0);
$labels = $assignByTeacher[$tid] ?? [];
if (!empty($labels)) {
$staff['class_section'] = implode(', ', array_unique($labels));
$staff['verification_issue'] = false;
} else {
$staff['class_section'] = 'No class assigned';
$staff['verification_issue'] = true;
$issuesCount++;
}
} else {
$staff['class_section'] = '—';
$staff['verification_issue'] = false;
}
}
unset($staff); // break reference
$directory = $this->staffDirectorySync->activeStaffForSchoolYear($schoolYear);
return view('staff/index', [
'staff' => $staffList,
'issues_count' => $issuesCount,
'staff' => $directory['staff'],
'issues_count' => $directory['issues_count'],
'semester' => $this->semester,
'school_year' => $schoolYear,
]);