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
+39
View File
@@ -27,6 +27,8 @@ class TeacherClassModel extends Model
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $skipValidation = false;
protected $afterInsert = ['syncStaffDirectoryAfterWrite'];
protected $afterUpdate = ['syncStaffDirectoryAfterWrite'];
/** Request-lifetime memo cache */
protected array $assignedCache = [];
protected array $assignedBySectionCache = [];
@@ -57,6 +59,43 @@ class TeacherClassModel extends Model
],
];
protected function syncStaffDirectoryAfterWrite(array $data): array
{
try {
$userIds = [];
$teacherId = (int) ($data['data']['teacher_id'] ?? 0);
if ($teacherId > 0) {
$userIds[] = $teacherId;
}
if ($userIds === [] && ! empty($data['id'])) {
$ids = is_array($data['id']) ? $data['id'] : [$data['id']];
$ids = array_values(array_filter(array_map('intval', $ids), static fn (int $id): bool => $id > 0));
if ($ids !== []) {
$rows = $this->db->table($this->table)
->select('teacher_id')
->whereIn($this->primaryKey, $ids)
->get()
->getResultArray();
foreach ($rows as $row) {
$rowTeacherId = (int) ($row['teacher_id'] ?? 0);
if ($rowTeacherId > 0) {
$userIds[] = $rowTeacherId;
}
}
}
}
foreach (array_unique($userIds) as $userId) {
service('staffDirectorySync')->syncUser((int) $userId);
}
} catch (\Throwable $e) {
log_message('error', 'TeacherClassModel staff directory sync failed: ' . $e->getMessage());
}
return $data;
}
public function getClassSectionIdByUserId($user_id)
{
$result = $this->where('teacher_id', $user_id)->first();