Skip to content

Commit 9c2bf86

Browse files
committed
Paging for exporting transaction history until work processor is implemented
1 parent a4a66c3 commit 9c2bf86

File tree

5 files changed

+68
-57
lines changed

5 files changed

+68
-57
lines changed

local/languages/finna/en-gb.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ list_order_saved = "Sort order saved"
599599
list-tags-info = "Add a new keyword"
600600
Loading = "Loading"
601601
Loan Details = "Loan Details"
602-
loan_history_download = "Export all"
602+
loan_history_download = "Export all in page"
603603
loan_history_download_csv = "Export CSV"
604604
loan_history_download_ods = "Export OpenOffice (ods)"
605605
loan_history_download_xlsx = "Export Excel (xlsx)"

local/languages/finna/fi.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ list_order_saved = "Järjestys tallennettu"
589589
list-tags-info = "Lisää uusi avainsana"
590590
Loading = "Ladataan"
591591
Loan Details = "Lainan tiedot"
592-
loan_history_download = "Vie kaikki"
592+
loan_history_download = "Vie kaikki sivulta"
593593
loan_history_download_csv = "Vie CSV"
594594
loan_history_download_ods = "Vie OpenOffice (ods)"
595595
loan_history_download_xlsx = "Vie Excel (xlsx)"

local/languages/finna/sv.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ list_order_saved = "Sortering sparad"
587587
list-tags-info = "Lägg till nytt nyckelord"
588588
Loading = "Laddar"
589589
Loan Details = "Information om lånet"
590-
loan_history_download = "Exportera alla"
590+
loan_history_download = "Exportera alla på sidan"
591591
loan_history_download_csv = "Exportera CSV"
592592
loan_history_download_ods = "Exportera OpenOffice (ods)"
593593
loan_history_download_xlsx = "Exportera Excel (xlsx)"

module/Finna/src/Finna/Controller/MyResearchController.php

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,10 @@ public function downloadLoanHistoryAction()
13561356
throw new \Exception('Invalid parameters.');
13571357
}
13581358

1359+
$page = (int)$this->params()->fromQuery('page', 1);
1360+
$sort = $this->params()->fromQuery('sort', '');
13591361
$recordLoader = $this->serviceLocator->get(\VuFind\Record\Loader::class);
1360-
$page = 1;
1362+
$config = $this->getConfig();
13611363
try {
13621364
$tmp = fopen('php://temp/maxmemory:' . (5 * 1024 * 1024), 'r+');
13631365
$header = [
@@ -1377,55 +1379,50 @@ public function downloadLoanHistoryAction()
13771379
if ('xlsx' === $fileFormat) {
13781380
Cell::setValueBinder(new AdvancedValueBinder());
13791381
}
1380-
do {
1381-
// Try to use large page size, but take ILS limits into account
1382-
$pageOptions = $this->getPaginationHelper()
1383-
->getOptions($page, null, 1000, $functionConfig);
1384-
$result = $catalog
1385-
->getMyTransactionHistory($patron, $pageOptions['ilsParams']);
1386-
1387-
if (isset($result['success']) && !$result['success']) {
1388-
$this->flashMessenger()->addErrorMessage($result['status']);
1389-
return $this->redirect()->toRoute('checkouts-history');
1390-
}
1382+
$pageOptions = $this->getPaginationHelper()->getOptions(
1383+
$page,
1384+
$sort,
1385+
$config->Catalog->historic_loan_page_size ?? 50,
1386+
$functionConfig
1387+
);
1388+
$result = $catalog->getMyTransactionHistory($patron, $pageOptions['ilsParams']);
13911389

1392-
$ids = [];
1393-
foreach ($result['transactions'] as $current) {
1394-
$id = $current['id'] ?? '';
1395-
$source = $current['source'] ?? DEFAULT_SEARCH_BACKEND;
1396-
$ids[] = compact('id', 'source');
1397-
}
1398-
$records = $recordLoader->loadBatch($ids, true);
1399-
foreach ($result['transactions'] as $i => $current) {
1400-
$driver = $records[$i];
1401-
$format = $driver->getFormats();
1402-
$format = end($format);
1403-
$author = $driver->tryMethod('getNonPresenterAuthors');
1404-
1405-
$loan = [];
1406-
$loan[] = $current['title'] ?? $driver->getTitle() ?? '';
1407-
$loan[] = $this->translate($format);
1408-
$loan[] = $author[0]['name'] ?? '';
1409-
$loan[] = $current['publication_year'] ?? '';
1410-
$loan[] = empty($current['institution_name'])
1411-
? ''
1412-
: $this->translateWithPrefix('location_', $current['institution_name']);
1413-
$loan[] = empty($current['borrowingLocation'])
1414-
? ''
1415-
: $this->translateWithPrefix('location_', $current['borrowingLocation']);
1416-
$loan[] = $current['checkoutDate'] ?? '';
1417-
$loan[] = $current['returnDate'] ?? '';
1418-
$loan[] = $current['dueDate'] ?? '';
1419-
1420-
$nextRow = $worksheet->getHighestRow() + 1;
1421-
$worksheet->fromArray($loan, null, 'A' . (string)$nextRow);
1422-
}
1390+
if (isset($result['success']) && !$result['success']) {
1391+
$this->flashMessenger()->addErrorMessage($result['status']);
1392+
return $this->redirect()->toRoute('checkouts-history');
1393+
}
14231394

1424-
$pageEnd = $pageOptions['ilsPaging']
1425-
? ceil($result['count'] / $pageOptions['limit'])
1426-
: 1;
1427-
$page++;
1428-
} while ($page <= $pageEnd);
1395+
$ids = [];
1396+
foreach ($result['transactions'] as $current) {
1397+
$id = $current['id'] ?? '';
1398+
$source = $current['source'] ?? DEFAULT_SEARCH_BACKEND;
1399+
$ids[] = compact('id', 'source');
1400+
}
1401+
$records = $recordLoader->loadBatch($ids, true);
1402+
foreach ($result['transactions'] as $i => $current) {
1403+
$driver = $records[$i];
1404+
$format = $driver->getFormats();
1405+
$format = end($format);
1406+
$author = $driver->tryMethod('getNonPresenterAuthors');
1407+
1408+
$loan = [];
1409+
$loan[] = $current['title'] ?? $driver->getTitle() ?? '';
1410+
$loan[] = $this->translate($format);
1411+
$loan[] = $author[0]['name'] ?? '';
1412+
$loan[] = $current['publication_year'] ?? '';
1413+
$loan[] = empty($current['institution_name'])
1414+
? ''
1415+
: $this->translateWithPrefix('location_', $current['institution_name']);
1416+
$loan[] = empty($current['borrowingLocation'])
1417+
? ''
1418+
: $this->translateWithPrefix('location_', $current['borrowingLocation']);
1419+
$loan[] = $current['checkoutDate'] ?? '';
1420+
$loan[] = $current['returnDate'] ?? '';
1421+
$loan[] = $current['dueDate'] ?? '';
1422+
1423+
$nextRow = $worksheet->getHighestRow() + 1;
1424+
$worksheet->fromArray($loan, null, 'A' . (string)$nextRow);
1425+
}
14291426
if ('xlsx' === $fileFormat) {
14301427
$worksheet->getStyle('G2:I' . $worksheet->getHighestRow())
14311428
->getNumberFormat()
@@ -1442,11 +1439,12 @@ public function downloadLoanHistoryAction()
14421439
);
14431440
$writer = new $this->exportFormats[$fileFormat]['writer']($spreadsheet);
14441441
$writer->save($tmp);
1445-
1442+
$fileName = implode('-', ['finna-loan-history-page', $page, $sort,]);
1443+
$fileName = str_replace(' ', '-', $fileName) . '.' . $fileFormat;
14461444
$response->getHeaders()
14471445
->addHeaderLine(
14481446
'Content-Disposition',
1449-
'attachment; filename="finna-loan-history.' . $fileFormat . '"'
1447+
'attachment; filename="' . $fileName . '"'
14501448
);
14511449

14521450
rewind($tmp);

themes/finna2/templates/checkouts/history.phtml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,31 @@
8888
<?php endif; ?>
8989
</div>
9090
<?php if (!empty($this->transactions)): ?>
91+
<div class="btn-group">
92+
<a data-lightbox class="btn btn-primary btn-finna-toolbar" role="button" href="<?=$this->url('myresearch-savehistoricloans') ?>"><?=$this->transEsc('loan_history_save')?></a>
93+
</div>
9194
<div class="btn-group">
9295
<div class="dropdown loan-history-download">
9396
<button class="btn btn-primary btn-finna-toolbar dropdown-toggle download" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
9497
<?=$this->transEsc('loan_history_download')?> <span class="caret"></span>
9598
</button>
9699
<ul class="dropdown-menu dropdown-menu-<?php if ($purgeSelectedAllowed): ?>right<?php else: ?>left<?php endif;?> download">
97-
<li>
98-
<a data-lightbox href="<?=$this->url('myresearch-savehistoricloans') ?>"><?=$this->transEsc('loan_history_save')?></a>
99-
</li>
100+
<?php
101+
$queryParams = [];
102+
foreach ($this->sortList as $sortType => $sortData) {
103+
if ($sortData['selected']) {
104+
$queryParams['sort'] = $sortType;
105+
break;
106+
}
107+
}
108+
if ($this->paginator) {
109+
$queryParams['page'] = $this->paginator->getCurrentPageNumber();
110+
}
111+
?>
100112
<?php foreach (['csv', 'ods', 'xlsx'] as $format): ?>
113+
<?php $queryParams['format'] = $format; ?>
101114
<li>
102-
<a href="<?=$this->url('myresearch-downloadloanhistory', [], ['query' => ['format' => $format]])?>"><?=$this->transEsc('loan_history_download_' . $format)?></a>
115+
<a href="<?=$this->url('myresearch-downloadloanhistory', [], ['query' => $queryParams])?>"><?=$this->transEsc('loan_history_download_' . $format)?></a>
103116
</li>
104117
<?php endforeach; ?>
105118
</ul>

0 commit comments

Comments
 (0)