update the new school year model

This commit is contained in:
root
2026-06-07 20:01:58 -04:00
parent 6866aedf42
commit 68a5c9edca
19 changed files with 472 additions and 32 deletions
+16 -6
View File
@@ -17,7 +17,7 @@ class BadgeScanService
/**
* @return array{recognized: bool, message: string, user_id?: int, display_name?: string}
*/
public function processScan(string $badgeScan): array
public function processScan(string $badgeScan, ?string $schoolYear = null, ?string $semester = null): array
{
$tag = trim($badgeScan);
if ($tag === '') {
@@ -51,8 +51,8 @@ class BadgeScanService
'user_id' => $user->id,
'card_id' => $tag,
'scan_time' => now(),
'school_year' => Configuration::getConfigValueByKey('school_year'),
'semester' => Configuration::getConfigValueByKey('semester'),
'school_year' => $schoolYear ?: Configuration::getConfigValueByKey('school_year'),
'semester' => $semester ?: Configuration::getConfigValueByKey('semester'),
]);
return [
@@ -68,13 +68,13 @@ class BadgeScanService
*
* @return list<array<string, mixed>>
*/
public function scanLogRows(): array
public function scanLogRows(?string $schoolYear = null, ?string $semester = null): array
{
if (! Schema::hasTable('scan_log')) {
return [];
}
return DB::table('scan_log')
$query = DB::table('scan_log')
->select([
'scan_log.id',
'scan_log.user_id',
@@ -88,7 +88,17 @@ class BadgeScanService
'students.lastname as student_lastname',
])
->leftJoin('users', 'users.id', '=', 'scan_log.user_id')
->leftJoin('students', 'students.rfid_tag', '=', 'scan_log.card_id')
->leftJoin('students', 'students.rfid_tag', '=', 'scan_log.card_id');
if ($schoolYear !== null && trim($schoolYear) !== '') {
$query->where('scan_log.school_year', trim($schoolYear));
}
if ($semester !== null && trim($semester) !== '') {
$query->where('scan_log.semester', trim($semester));
}
return $query
->orderByDesc('scan_log.scan_time')
->limit(self::LOG_LIMIT)
->get()