fix parent, teacher and admin pages
This commit is contained in:
@@ -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
|
||||
* ============================================================
|
||||
|
||||
Reference in New Issue
Block a user