@@ -1356,8 +1356,10 @@ public function downloadLoanHistoryAction()
1356
1356
throw new \Exception ('Invalid parameters. ' );
1357
1357
}
1358
1358
1359
+ $ page = (int )$ this ->params ()->fromQuery ('page ' , 1 );
1360
+ $ sort = $ this ->params ()->fromQuery ('sort ' , '' );
1359
1361
$ recordLoader = $ this ->serviceLocator ->get (\VuFind \Record \Loader::class);
1360
- $ page = 1 ;
1362
+ $ config = $ this -> getConfig () ;
1361
1363
try {
1362
1364
$ tmp = fopen ('php://temp/maxmemory: ' . (5 * 1024 * 1024 ), 'r+ ' );
1363
1365
$ header = [
@@ -1377,55 +1379,50 @@ public function downloadLoanHistoryAction()
1377
1379
if ('xlsx ' === $ fileFormat ) {
1378
1380
Cell::setValueBinder (new AdvancedValueBinder ());
1379
1381
}
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 ' ]);
1391
1389
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
+ }
1423
1394
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
+ }
1429
1426
if ('xlsx ' === $ fileFormat ) {
1430
1427
$ worksheet ->getStyle ('G2:I ' . $ worksheet ->getHighestRow ())
1431
1428
->getNumberFormat ()
@@ -1442,11 +1439,12 @@ public function downloadLoanHistoryAction()
1442
1439
);
1443
1440
$ writer = new $ this ->exportFormats [$ fileFormat ]['writer ' ]($ spreadsheet );
1444
1441
$ writer ->save ($ tmp );
1445
-
1442
+ $ fileName = implode ('- ' , ['finna-loan-history-page ' , $ page , $ sort ,]);
1443
+ $ fileName = str_replace (' ' , '- ' , $ fileName ) . '. ' . $ fileFormat ;
1446
1444
$ response ->getHeaders ()
1447
1445
->addHeaderLine (
1448
1446
'Content-Disposition ' ,
1449
- 'attachment; filename="finna-loan-history. ' . $ fileFormat . '" '
1447
+ 'attachment; filename=" ' . $ fileName . '" '
1450
1448
);
1451
1449
1452
1450
rewind ($ tmp );
0 commit comments