add badge logic

This commit is contained in:
root
2026-04-25 01:23:21 -04:00
parent eafe4eb134
commit 5c544f93b9
13 changed files with 1468 additions and 169 deletions
+29 -6
View File
@@ -29,11 +29,30 @@ class BadgeUserLookupService
$query->whereIn('users.id', $selectedUserIds);
}
if (!empty($schoolYear) && Schema::hasColumn('user_roles', 'school_year')) {
$query->where('user_roles.school_year', $schoolYear);
if (Schema::hasColumn('user_roles', 'deleted_at')) {
$query->whereNull('user_roles.deleted_at');
}
return array_map(static fn ($row) => (array) $row, $query->get()->all());
$rows = array_map(static fn ($row) => (array) $row, $query->get()->all());
return array_values(array_filter($rows, static function (array $row): bool {
$roles = strtolower(trim((string) ($row['roles'] ?? '')));
if ($roles === '') {
return false;
}
$parts = array_values(array_filter(array_map('trim', explode(',', $roles))));
foreach ($parts as $part) {
if (in_array($part, ['parent', 'student'], true)) {
continue;
}
return true;
}
return false;
}));
}
public function getLatestClassForUser(int $userId, ?string $schoolYear = null): ?array
@@ -69,7 +88,7 @@ class BadgeUserLookupService
public function getUserInfoById(int $id, ?string $schoolYear = null): ?array
{
$u = DB::table('users')
->select(['id as user_id', 'firstname', 'lastname'])
->select(['id as user_id', 'firstname', 'lastname', 'school_id', 'account_id'])
->where('id', $id)
->first();
@@ -79,6 +98,10 @@ class BadgeUserLookupService
$userId = (int) $u->user_id;
$fullname = trim(($u->firstname ?? '') . ' ' . ($u->lastname ?? ''));
$schoolId = trim((string) ($u->school_id ?? ''));
if ($schoolId === '') {
$schoolId = trim((string) ($u->account_id ?? ''));
}
$rolesRows = DB::table('user_roles as ur')
->join('roles as r', 'r.id', '=', 'ur.role_id')
@@ -155,7 +178,7 @@ class BadgeUserLookupService
'class_section_name' => $className,
'job_title' => $jobTitle,
'school_name' => 'Al Rahma Sunday School',
'school_id' => $userId,
'school_id' => $schoolId,
'school_logo' => $schoolLogo,
'isgl_logo' => $isglLogo,
'school_year' => $assignment->school_year ?? $schoolYear,
@@ -208,4 +231,4 @@ class BadgeUserLookupService
return $row->class_section_name ?? null;
}
}
}