add test batches
This commit is contained in:
@@ -23,7 +23,8 @@ class BadgeService
|
||||
protected TeacherClass $teacherClassModel,
|
||||
protected ClassSection $classSectionModel,
|
||||
protected BadgePrintLog $badgePrintLogModel
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function generateBadgePdf(
|
||||
array $userIds,
|
||||
@@ -54,7 +55,7 @@ class BadgeService
|
||||
foreach ($userIds as $uid) {
|
||||
$info = $this->getUserInfoById($uid, $schoolYear);
|
||||
|
||||
if (! $info || ! is_array($info)) {
|
||||
if (!$info || !is_array($info)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -69,13 +70,13 @@ class BadgeService
|
||||
$roleResolved = $this->formatRole($roleResolved);
|
||||
$info['role_resolved'] = $roleResolved;
|
||||
|
||||
if (! empty($classesMap[$userId])) {
|
||||
if (!empty($classesMap[$userId])) {
|
||||
$info['class_section_name'] = (string) $classesMap[$userId];
|
||||
}
|
||||
|
||||
$class = $this->norm($info['class_section_name'] ?? '');
|
||||
|
||||
$badgeKey = strtolower(trim($userId.'|'.$name.'|'.$roleResolved.'|'.$class));
|
||||
$badgeKey = strtolower(trim($userId . '|' . $name . '|' . $roleResolved . '|' . $class));
|
||||
if (isset($seen[$badgeKey])) {
|
||||
continue;
|
||||
}
|
||||
@@ -116,7 +117,7 @@ class BadgeService
|
||||
1
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Failed to log badge prints: '.$e->getMessage());
|
||||
Log::error('Failed to log badge prints: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return response($pdfString, 200, [
|
||||
@@ -158,7 +159,7 @@ class BadgeService
|
||||
$users = $this->fetchStaffList($schoolYear, $selectedUserIds);
|
||||
|
||||
foreach ($users as &$u) {
|
||||
if (! isset($u['user_id'])) {
|
||||
if (!isset($u['user_id'])) {
|
||||
if (isset($u['id'])) {
|
||||
$u['user_id'] = (int) $u['id'];
|
||||
}
|
||||
@@ -189,7 +190,7 @@ class BadgeService
|
||||
$rolesDetect = strtolower($u['roles_raw'] ?? ($u['role_name_raw'] ?? ''));
|
||||
$isTeacherish = str_contains($rolesDetect, 'teacher') || preg_match('/\bta\b/', $rolesDetect);
|
||||
|
||||
if ($isTeacherish && ! empty($u['user_id'])) {
|
||||
if ($isTeacherish && !empty($u['user_id'])) {
|
||||
$assign = $this->getLatestClassForUser((int) $u['user_id'], $schoolYear);
|
||||
if ($assign) {
|
||||
$u['class_section_id'] = $assign['class_section_id'] ?? null;
|
||||
@@ -233,11 +234,11 @@ class BadgeService
|
||||
])
|
||||
->groupBy('users.id', 'users.firstname', 'users.lastname');
|
||||
|
||||
if (! empty($selectedUserIds)) {
|
||||
if (!empty($selectedUserIds)) {
|
||||
$query->whereIn('users.id', $selectedUserIds);
|
||||
}
|
||||
|
||||
if (! empty($schoolYear) && Schema::hasColumn('user_roles', 'school_year')) {
|
||||
if (!empty($schoolYear) && Schema::hasColumn('user_roles', 'school_year')) {
|
||||
$query->where('user_roles.school_year', $schoolYear);
|
||||
}
|
||||
|
||||
@@ -254,7 +255,7 @@ class BadgeService
|
||||
])
|
||||
->where('tc.teacher_id', $userId);
|
||||
|
||||
if (! empty($schoolYear)) {
|
||||
if (!empty($schoolYear)) {
|
||||
$query->where('tc.school_year', $schoolYear);
|
||||
}
|
||||
|
||||
@@ -264,7 +265,7 @@ class BadgeService
|
||||
->orderByDesc('tc.id')
|
||||
->first();
|
||||
|
||||
if (! $row || empty($row->class_section_id)) {
|
||||
if (!$row || empty($row->class_section_id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -281,12 +282,12 @@ class BadgeService
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
if (! $u) {
|
||||
if (!$u) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$userId = (int) $u->user_id;
|
||||
$fullname = trim(($u->firstname ?? '').' '.($u->lastname ?? ''));
|
||||
$fullname = trim(($u->firstname ?? '') . ' ' . ($u->lastname ?? ''));
|
||||
|
||||
$rolesRows = DB::table('user_roles as ur')
|
||||
->join('roles as r', 'r.id', '=', 'ur.role_id')
|
||||
@@ -309,7 +310,7 @@ class BadgeService
|
||||
->select(['class_section_id', 'updated_at', 'id', 'position', 'school_year'])
|
||||
->where('teacher_id', $userId);
|
||||
|
||||
if (! empty($schoolYear)) {
|
||||
if (!empty($schoolYear)) {
|
||||
$tcQuery->where('school_year', $schoolYear);
|
||||
}
|
||||
|
||||
@@ -321,7 +322,7 @@ class BadgeService
|
||||
$position = strtolower(trim((string) ($assignment->position ?? '')));
|
||||
$className = null;
|
||||
|
||||
if (! empty($classId)) {
|
||||
if (!empty($classId)) {
|
||||
$className = $this->resolveClassName((int) $classId);
|
||||
}
|
||||
|
||||
@@ -329,7 +330,7 @@ class BadgeService
|
||||
$roleLabel = 'Teacher Assistant';
|
||||
} elseif ($position === 'teacher' || $position === 'main') {
|
||||
$roleLabel = 'Teacher';
|
||||
} elseif (! empty($allRoles)) {
|
||||
} elseif (!empty($allRoles)) {
|
||||
$roleLabel = $allRoles[0];
|
||||
} else {
|
||||
$roleLabel = 'Staff';
|
||||
@@ -346,11 +347,11 @@ class BadgeService
|
||||
]);
|
||||
|
||||
$jobTitle = '';
|
||||
if (! empty($roleLabel) && ! empty($className)) {
|
||||
if (!empty($roleLabel) && !empty($className)) {
|
||||
$jobTitle = "{$roleLabel} - {$className}";
|
||||
} elseif (! empty($roleLabel)) {
|
||||
} elseif (!empty($roleLabel)) {
|
||||
$jobTitle = $roleLabel;
|
||||
} elseif (! empty($className)) {
|
||||
} elseif (!empty($className)) {
|
||||
$jobTitle = $className;
|
||||
}
|
||||
|
||||
@@ -378,10 +379,10 @@ class BadgeService
|
||||
$pdf->Rect($x, $y, $w, $h);
|
||||
|
||||
$logoSize = 6;
|
||||
if (! empty($data['school_logo']) && file_exists($data['school_logo'])) {
|
||||
if (!empty($data['school_logo']) && file_exists($data['school_logo'])) {
|
||||
$pdf->Image($data['school_logo'], $x + $w - 6 - $logoSize, $y + 4, $logoSize + 3, $logoSize - 1);
|
||||
}
|
||||
if (! empty($data['isgl_logo']) && file_exists($data['isgl_logo'])) {
|
||||
if (!empty($data['isgl_logo']) && file_exists($data['isgl_logo'])) {
|
||||
$pdf->Image($data['isgl_logo'], $x + 4, $y + 4, $logoSize + 3, $logoSize - 1);
|
||||
}
|
||||
|
||||
@@ -417,11 +418,11 @@ class BadgeService
|
||||
|
||||
if ($isTeacherish && $class !== '') {
|
||||
if (strtolower($class) === 'youth') {
|
||||
$display = 'Youth '.$roleResolved;
|
||||
$display = 'Youth ' . $roleResolved;
|
||||
} elseif ($class === 'KG') {
|
||||
$display = 'KG '.$roleResolved;
|
||||
$display = 'KG ' . $roleResolved;
|
||||
} else {
|
||||
$display = 'Grade '.$class.' '.$roleResolved;
|
||||
$display = 'Grade ' . $class . ' ' . $roleResolved;
|
||||
}
|
||||
} elseif ($roleResolved !== '') {
|
||||
$display = $roleResolved;
|
||||
@@ -460,7 +461,7 @@ class BadgeService
|
||||
'role',
|
||||
'active_role',
|
||||
'role_name',
|
||||
fn ($r) => ! empty($r['roles'])
|
||||
fn ($r) => !empty($r['roles'])
|
||||
? (array_filter(array_map('trim', explode(',', (string) $r['roles'])))[0] ?? '')
|
||||
: '',
|
||||
'job_title',
|
||||
@@ -478,7 +479,7 @@ class BadgeService
|
||||
return $this->norm($v);
|
||||
}
|
||||
} else {
|
||||
if (! empty($info[$key])) {
|
||||
if (!empty($info[$key])) {
|
||||
$v = $this->norm((string) $info[$key]);
|
||||
if ($v !== '') {
|
||||
return $v;
|
||||
@@ -578,7 +579,6 @@ class BadgeService
|
||||
|
||||
if ($start === false) {
|
||||
$out[] = ucfirst(mb_strtolower($tok, 'UTF-8'));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -594,12 +594,12 @@ class BadgeService
|
||||
$coreFmt = preg_replace_callback(
|
||||
'/\p{L}+/u',
|
||||
static fn ($m) => mb_strtoupper(mb_substr($m[0], 0, 1, 'UTF-8'), 'UTF-8')
|
||||
.mb_strtolower(mb_substr($m[0], 1, null, 'UTF-8'), 'UTF-8'),
|
||||
. mb_strtolower(mb_substr($m[0], 1, null, 'UTF-8'), 'UTF-8'),
|
||||
mb_strtolower($core, 'UTF-8')
|
||||
);
|
||||
}
|
||||
|
||||
$out[] = $pre.$coreFmt.$suf;
|
||||
$out[] = $pre . $coreFmt . $suf;
|
||||
}
|
||||
|
||||
return implode(' ', $out);
|
||||
@@ -640,7 +640,7 @@ class BadgeService
|
||||
protected function firstExisting(array $paths): ?string
|
||||
{
|
||||
foreach ($paths as $path) {
|
||||
if (! empty($path) && file_exists($path)) {
|
||||
if (!empty($path) && file_exists($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
@@ -697,4 +697,4 @@ class BadgeService
|
||||
|
||||
return $schoolYears;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user