diff --git a/.github/workflows/ci-e2e.yml b/.github/workflows/ci-e2e.yml index ea538e7da..46639cfad 100644 --- a/.github/workflows/ci-e2e.yml +++ b/.github/workflows/ci-e2e.yml @@ -434,6 +434,7 @@ jobs: - group: catalogue specs: >- tests/attendance-090.spec.js + tests/attendance-member-search.spec.js tests/catalogue-cards-090.spec.js tests/feature-toggle-catalogue-cards.spec.js tests/feature-toggles-followups.spec.js diff --git a/app/Controllers/AttendanceController.php b/app/Controllers/AttendanceController.php index 7f184a0e0..76c85743a 100644 --- a/app/Controllers/AttendanceController.php +++ b/app/Controllers/AttendanceController.php @@ -60,10 +60,15 @@ public function scan(Request $request, Response $response, mysqli $db): Response $body = (array) $request->getParsedBody(); $repo = new AttendanceRepository($db); $card = is_string($body['codice_tessera'] ?? null) ? $body['codice_tessera'] : ''; + // A member picked from the name search arrives as utente_id, and the + // field then holds the label, not a code: the id wins over the card. + $pickedId = filter_var($body['utente_id'] ?? null, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]); try { - $member = $repo->findMemberByCard($card); + $member = $pickedId !== false ? $repo->findMemberById($pickedId) : $repo->findMemberByCard($card); if ($member === null) { - $_SESSION['error_message'] = __('Tessera non riconosciuta. Controlla il codice o registra la visita come ospite.'); + $_SESSION['error_message'] = $pickedId !== false + ? __('Utente non trovato') + : __('Tessera non riconosciuta. Controlla il codice o registra la visita come ospite.'); return $this->back($response); } $repo->recordMember($member['id'], $this->rememberBranch($repo, $body)); diff --git a/app/Models/AttendanceRepository.php b/app/Models/AttendanceRepository.php index 9c55226a0..5939596b0 100644 --- a/app/Models/AttendanceRepository.php +++ b/app/Models/AttendanceRepository.php @@ -57,9 +57,35 @@ public function findMemberByCard(string $card): ?array $stmt->execute(); $row = $stmt->get_result()->fetch_assoc(); $stmt->close(); - if (!$row) { + return $row ? self::member($row) : null; + } + + /** + * The member picked by name in the desk search, for a reader who forgot + * the card. Same reach as findMemberByCard(). + * + * @return array{id:int, nome:string, cognome:string, stato:string}|null + */ + public function findMemberById(int $userId): ?array + { + if ($userId <= 0) { return null; } + $scope = Permissions::accountScopeSql('', Permissions::SCOPE_BORROWER); + $stmt = $this->db->prepare('SELECT id, nome, cognome, stato FROM utenti WHERE id = ?' . $scope . ' LIMIT 1'); + $stmt->bind_param('i', $userId); + $stmt->execute(); + $row = $stmt->get_result()->fetch_assoc(); + $stmt->close(); + return $row ? self::member($row) : null; + } + + /** + * @param array $row + * @return array{id:int, nome:string, cognome:string, stato:string} + */ + private static function member(array $row): array + { return [ 'id' => (int) $row['id'], 'nome' => (string) $row['nome'], diff --git a/app/Views/attendance/index.php b/app/Views/attendance/index.php index cecde403d..7068d8401 100644 --- a/app/Views/attendance/index.php +++ b/app/Views/attendance/index.php @@ -85,9 +85,14 @@
- +
- +
+ +
+
+
+