Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sierra: Fix and improve item/bib handling with transaction history #3133

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions module/VuFind/src/VuFind/ILS/Driver/SierraRest.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ public function getMyTransactionHistory($patron, $params)
'offset' => $offset,
'sortField' => 'outDate',
'sortOrder' => $sortOrder,
'fields' => 'item,outDate',
'fields' => 'bib,item,outDate',
],
'GET',
$patron
Expand Down Expand Up @@ -1688,7 +1688,7 @@ protected function extractId($url)
*/
protected function extractVolume($item)
{
foreach ($item['varFields'] as $varField) {
foreach ($item['varFields'] ?? [] as $varField) {
if ($varField['fieldTag'] == 'v') {
return trim($varField['content']);
}
Expand Down Expand Up @@ -3265,10 +3265,17 @@ protected function getItemsWithBibsForTransactions(
if (!$transactions) {
return [];
}
// Fetch items
// Fetch items and collect bib id mappings if available:
$itemIds = [];
$bibIdsToItems = [];
foreach ($transactions as $transaction) {
$itemIds[] = $this->extractId($transaction['item']);
$itemId = $this->extractId($transaction['item']);
$itemIds[] = $itemId;
// Historical transactions include the bib id. Collect them here so that
// we can get the bib data even if the item doesn't exist anymore:
if ($bibId = $transaction['bib'] ?? null) {
$bibIdsToItems[$this->extractId($bibId)][$itemId] = true;
}
}
$itemsResult = $this->makeRequest(
[$this->apiBase, 'items'],
Expand All @@ -3279,15 +3286,17 @@ protected function getItemsWithBibsForTransactions(
'GET',
$patron
);
// Map items to an array and collect further bib id mappings:
$items = [];
$bibIdsToItems = [];
foreach ($itemsResult['entries'] as $item) {
$items[(string)$item['id']] = $item;
if (!empty($item['bibIds'][0])) {
$bibIdsToItems[(string)$item['bibIds'][0]] = (string)$item['id'];
$itemId = (string)$item['id'];
$items[$itemId] = $item;
if ($bibId = (string)($item['bibIds'][0] ?? '')) {
// Collect all item id's for each bib:
$bibIdsToItems[$bibId][$itemId] = true;
}
}
// Fetch bibs for the items
// Fetch bibs for the items:
$bibsResult = $this->makeRequest(
[$this->apiBase, 'bibs'],
[
Expand All @@ -3298,8 +3307,10 @@ protected function getItemsWithBibsForTransactions(
$patron
);
foreach ($bibsResult['entries'] as $bib) {
// Add bib data to the items
$items[$bibIdsToItems[(string)$bib['id']]]['bib'] = $bib;
// Add bib data to the items:
foreach (array_keys($bibIdsToItems[(string)$bib['id']]) as $itemId) {
$items[$itemId]['bib'] = $bib;
}
}

return $items;
Expand Down