fix parent, teacher and admin pages

This commit is contained in:
root
2026-04-25 00:00:23 -04:00
parent 4cd98f1d30
commit eafe4eb134
30 changed files with 1566 additions and 105 deletions
+56
View File
@@ -97,6 +97,62 @@ class User extends Authenticatable implements JWTSubject
->all();
}
/**
* Resolve the primary teacher class section to persist in auth/session payloads.
*
* @return array{class_section_id: ?int, class_section_name: ?string}
*/
public function teacherSessionContext(): array
{
$empty = [
'class_section_id' => null,
'class_section_name' => null,
];
$roles = array_map(
static fn ($role) => strtolower(trim((string) $role)),
$this->roleNamesLikeCodeIgniter(),
);
$isTeacherScoped = in_array('teacher', $roles, true)
|| in_array('teacher_assistant', $roles, true)
|| in_array('ta', $roles, true);
if (! $isTeacherScoped) {
return $empty;
}
$schoolYear = trim((string) (Configuration::getConfig('school_year') ?? ''));
$semester = trim((string) (Configuration::getConfig('semester') ?? ''));
$assignments = TeacherClass::getClassAssignmentsByUserId(
(int) $this->id,
$schoolYear !== '' ? $schoolYear : null,
$semester !== '' ? $semester : null,
);
if ($assignments === []) {
$assignments = TeacherClass::getClassAssignmentsByUserId(
(int) $this->id,
null,
$semester !== '' ? $semester : null,
);
}
$primary = $assignments[0] ?? null;
if (! is_array($primary)) {
return $empty;
}
$classSectionId = (int) ($primary['class_section_id'] ?? 0);
$classSectionName = trim((string) ($primary['class_section_name'] ?? ''));
return [
'class_section_id' => $classSectionId > 0 ? $classSectionId : null,
'class_section_name' => $classSectionName !== '' ? $classSectionName : null,
];
}
/* ============================================================
* Relationships
* ============================================================