Skip to content

Commit

Permalink
Comment to route and initiated cache array in construct.
Browse files Browse the repository at this point in the history
  • Loading branch information
siiriylonen committed Dec 4, 2024
1 parent 6b63f32 commit 27fde89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions module/Finna/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@
],
],
];
// @deprecated, use librarycards-displaybarcode
$config['router']['routes']['barcode-show'] = [
'type' => 'Laminas\Router\Http\Segment',
'options' => [
Expand Down
11 changes: 6 additions & 5 deletions module/Finna/src/Finna/Controller/LibraryCardsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function __construct(
protected SessionContainer $session,
) {
parent::__construct($sm);
$this->session->LibraryCards ??= [];
}

/**
Expand Down Expand Up @@ -920,14 +921,14 @@ public function displayBarcodeAction(): mixed
}
$userCardService = $this->getDbService(UserCardServiceInterface::class);
$card = $userCardService->getOrCreateLibraryCard($user, $id);
if (isset($this->session->LibraryCards[$id])) {
$barcode = $this->session->LibraryCards[$id];
return $this->createViewModel(['code' => $barcode]);
}
$username = $card->getCatUsername();
if (str_contains($username, '.')) {
[, $username] = explode('.', $username, 2);
}
if (isset($this->session->LibraryCards[$username . '|' . $id])) {
$barcode = $this->session->LibraryCards[$username . '|' . $id];
return $this->createViewModel(['code' => $barcode]);
}
$catalog = $this->getILS();
$auth = $this->getILSAuthenticator();
if ($card->getCatUsername() === $user->getCatUsername()) {
Expand All @@ -949,7 +950,7 @@ public function displayBarcodeAction(): mixed
}
}
$barcode ??= $username;
$this->session->LibraryCards[$id] = $barcode;
$this->session->LibraryCards[$username . '|' . $id] = $barcode;
return $this->createViewModel(['code' => $barcode]);
} catch (\Exception) {
$this->flashMessenger()->addErrorMessage('An error has occurred');
Expand Down

0 comments on commit 27fde89

Please sign in to comment.