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

[FINNA-2662] Adjust loan history export to use paging #3076

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9c2bf86
Paging for exporting transaction history until work processor is impl…
LuomaJuha Nov 4, 2024
3c602e0
Adjusted loan history to show form to download
LuomaJuha Nov 5, 2024
9a549d9
Added csrf
LuomaJuha Nov 5, 2024
0d6b1c2
QA
LuomaJuha Nov 5, 2024
4cfe9cc
Adjusted translations
LuomaJuha Nov 5, 2024
33616de
Adjustments to loan history downloading
LuomaJuha Nov 15, 2024
5573fca
Added comments to template
LuomaJuha Nov 15, 2024
2d99afd
Merge branch 'dev' into add-paging-to-history
LuomaJuha Jan 3, 2025
a19346e
Adjusted to fetch file from ajax handler
LuomaJuha Jan 13, 2025
c78eb63
Removed unused files and translations
LuomaJuha Jan 13, 2025
4497c6d
Adjusted translation, reverted change to demo driver
LuomaJuha Jan 13, 2025
81b6326
Adjusted page numbers
LuomaJuha Jan 13, 2025
42c1d18
Remove useless ilsdefaults
LuomaJuha Jan 13, 2025
00fe1dd
Adjusted comments
LuomaJuha Jan 13, 2025
7ab3039
Removed unused use
LuomaJuha Jan 13, 2025
701d067
Merge branch 'dev' into add-paging-to-history
LuomaJuha Jan 15, 2025
e473b62
Changed naming from transactions to checkouts
LuomaJuha Jan 15, 2025
39061ab
Added comments
LuomaJuha Jan 15, 2025
9ba8d20
Removed unused parameter type
LuomaJuha Jan 15, 2025
6ca8bb4
Adjusted js comments
LuomaJuha Jan 15, 2025
6931dbf
Removed test variable..
LuomaJuha Jan 16, 2025
1d742b5
Adjusted to calculate history properly
LuomaJuha Jan 16, 2025
6125ab8
Added test for GetCheckoutHistory
LuomaJuha Jan 16, 2025
c6a274c
small tuning to test
LuomaJuha Jan 16, 2025
dc5359c
Fix
LuomaJuha Jan 17, 2025
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
4 changes: 4 additions & 0 deletions local/config/finna/config.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ library_cards = true
; memory problems for users with a large number of historic loans). Default = 50
;historic_loan_page_size = 50

; Limit for how many historic transactions to fetch at most from ILS
; when downloading loan history
loan_history_download_batch_limit = 1000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tämä ei näytä vaikuttavan dropdownissa näkyvään sivumäärään.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ny pitäis taas vaikuttaa!


; Whether to display the item barcode for each loan. Default is false.
display_checked_out_item_barcode = true

Expand Down
9 changes: 5 additions & 4 deletions local/languages/finna/en-gb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,11 @@ list_order_saved = "Sort order saved"
list-tags-info = "Add a new keyword"
Loading = "Loading"
Loan Details = "Loan Details"
loan_history_download = "Export all"
loan_history_download_csv = "Export CSV"
loan_history_download_ods = "Export OpenOffice (ods)"
loan_history_download_xlsx = "Export Excel (xlsx)"
loan_history_download = "Download loan history"
loan_history_download_part = "Download loan history (part %%part%%/%%lastPart%%)"
loan_history_download_csv = "CSV"
loan_history_download_ods = "OpenOffice (ods)"
loan_history_download_xlsx = "Excel (xlsx)"
loan_history_purge = "Purge History"
loan_history_purge_prompt_html = "Are you sure you will purge the loan history? Cleared loan history cannot be retrieved anymore."
loan_history_purge_selected = "Purge Selected"
Expand Down
9 changes: 5 additions & 4 deletions local/languages/finna/fi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,11 @@ list_order_saved = "Järjestys tallennettu"
list-tags-info = "Lisää uusi avainsana"
Loading = "Ladataan"
Loan Details = "Lainan tiedot"
loan_history_download = "Vie kaikki"
loan_history_download_csv = "Vie CSV"
loan_history_download_ods = "Vie OpenOffice (ods)"
loan_history_download_xlsx = "Vie Excel (xlsx)"
loan_history_download = "Lataa lainaushistoria"
loan_history_download_part = "Lataa lainaushistoria (osa %%part%%/%%lastPart%%)"
loan_history_download_csv = "CSV"
loan_history_download_ods = "OpenOffice (ods)"
loan_history_download_xlsx = "Excel (xlsx)"
loan_history_purge = "Tyhjennä historia"
loan_history_purge_prompt_html = "Oletko varma, että haluat tyhjentää lainaushistoriasi? Tyhjennettyä historiaa ei saa takaisin."
loan_history_purge_selected = "Poista valitut"
Expand Down
1 change: 1 addition & 0 deletions local/languages/finna/se.ini
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ list-tags-info = "Lasit ođđa beassansáni"
Loading = "Láddejuvvo"
Loan Details = "Luoikama dieđut"
loan_history_download = "Doalvvo visot"
loan_history_download_part = "Doalvvo visot (siidu %%part%%/%%lastPart%%)"
loan_history_download_csv = "Doalvvo CSV"
loan_history_download_ods = "Doalvvo OpenOffice (ods)"
loan_history_download_xlsx = "Doalvvo Excel (xlsx)"
Expand Down
9 changes: 5 additions & 4 deletions local/languages/finna/sv.ini
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,11 @@ list_order_saved = "Sortering sparad"
list-tags-info = "Lägg till nytt nyckelord"
Loading = "Laddar"
Loan Details = "Information om lånet"
loan_history_download = "Exportera alla"
loan_history_download_csv = "Exportera CSV"
loan_history_download_ods = "Exportera OpenOffice (ods)"
loan_history_download_xlsx = "Exportera Excel (xlsx)"
loan_history_download = "Ladda lånehistorik"
loan_history_download_part = "Ladda lånehistorik (del %%part%%/%%lastPart%%)"
loan_history_download_csv = "CSV"
loan_history_download_ods = "OpenOffice (ods)"
loan_history_download_xlsx = "Excel (xlsx)"
loan_history_purge = "Rensa historiken"
loan_history_purge_prompt_html = "Är du säker på att du vill rensa din utlåningshistorik? Raderad historik kan inte återskapas."
loan_history_purge_selected = "Radera valda"
Expand Down
7 changes: 6 additions & 1 deletion module/Finna/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@
'Finna\AjaxHandler\GetUserListFactory',
'Finna\AjaxHandler\GetUserLists' =>
'Finna\AjaxHandler\GetUserListsFactory',
'Finna\AjaxHandler\GetCheckoutHistory' =>
'Finna\AjaxHandler\GetCheckoutHistoryFactory',
'Finna\AjaxHandler\GetCheckoutHistoryFile' =>
'Finna\AjaxHandler\GetCheckoutHistoryFactory',
'Finna\AjaxHandler\ReservationList' =>
'Finna\AjaxHandler\ReservationListFactory',
'Finna\AjaxHandler\ImportFavorites' =>
Expand All @@ -517,6 +521,8 @@
'getAccountNotifications' => 'Finna\AjaxHandler\GetAccountNotifications',
'getAuthorityInfo' => 'Finna\AjaxHandler\GetAuthorityInfo',
'getAuthorityFullInfo' => 'Finna\AjaxHandler\GetAuthorityFullInfo',
'getCheckoutHistory' => 'Finna\AjaxHandler\GetCheckoutHistory',
'getCheckoutHistoryFile' => 'Finna\AjaxHandler\GetCheckoutHistoryFile',
'getContentFeed' => 'Finna\AjaxHandler\GetContentFeed',
'getDescription' => 'Finna\AjaxHandler\GetDescription',
'getModel' => 'Finna\AjaxHandler\GetModel',
Expand Down Expand Up @@ -1110,7 +1116,6 @@
'LibraryCards/ResetPassword',
'LocationService/Modal',
'MetaLib/Home', 'MetaLib/Search', 'MetaLib/Advanced',
'MyResearch/DownloadLoanHistory',
'MyResearch/SaveCustomOrder', 'MyResearch/SaveHistoricLoans',
'OrganisationInfo/Home',
'PCI/Home', 'PCI/Search', 'PCI/Record',
Expand Down
150 changes: 150 additions & 0 deletions module/Finna/src/Finna/AjaxHandler/GetCheckoutHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

/**
* GetCheckoutHistory AJAX handler
*
* PHP version 8
*
* Copyright (C) The National Library of Finland 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package AJAX
* @author Juha Luoma <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/

namespace Finna\AjaxHandler;

use Laminas\Mvc\Controller\Plugin\Params;
use VuFind\Auth\ILSAuthenticator;
use VuFind\Db\Entity\UserEntityInterface;
use VuFind\ILS\Connection;
use VuFind\ILS\PaginationHelper;
use VuFind\Session\Settings as SessionSettings;

/**
* GetCheckoutHistory AJAX handler
*
* @category VuFind
* @package AJAX
* @author Juha Luoma <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class GetCheckoutHistory extends \VuFind\AjaxHandler\AbstractIlsAndUserAction
{
/**
* Cache for patron
*
* @var array
*/
protected array $cachedPatron = [];

/**
* Cache for function config.
*
* @var array
*/
protected array $cachedFunctionConfig = [];

/**
* Constructor
*
* @param SessionSettings $ss Session settings
* @param Connection $ils ILS connection
* @param ILSAuthenticator $ilsAuthenticator ILS authenticator
* @param ?UserEntityInterface $user Logged in user (or null)
* @param \VuFind\Record\Loader $recordLoader Record loader
* @param int $batchLimit Config specified default batch limit
* @param int $defaultPageSize Default page size set in config.ini
*/
public function __construct(
SessionSettings $ss,
Connection $ils,
ILSAuthenticator $ilsAuthenticator,
?UserEntityInterface $user,
protected \VuFind\Record\Loader $recordLoader,
protected int $batchLimit = 1000,
protected int $defaultPageSize = 50
) {
parent::__construct($ss, $ils, $ilsAuthenticator, $user);
}

/**
* Handle a request.
*
* @param Params $params Parameter helper from controller
*
* @return array [response data, HTTP status code]
*/
public function handleRequest(Params $params)
{
$this->disableSessionWrites(); // avoid session write timing bug
$result = $this->getCheckoutHistoryResult();
if ($result['success'] === false) {
return $this->formatResponse($result['message'], $result['status']);
}
return $this->formatResponse(['parts' => ceil(($result['function_result']['count'] ?? 1) / $this->batchLimit)]);
}

/**
* Get checkout history result for user if available
*
* @param int $page First page to get from ils
* @param ?int $limit Current limit for the page size or null for default
*
* @return array
*/
public function getCheckoutHistoryResult(int $page = 1, ?int $limit = null): array
{
$getErrorMessage = function ($message, $status) {
$success = false;
$message = $this->translate($message);
return compact('success', 'message', 'status');
};
if (!$this->cachedPatron) {
$this->cachedPatron = $this->ilsAuthenticator->storedCatalogLogin();
if (!$this->user || !$this->cachedPatron) {
return $getErrorMessage('You must be logged in first', self::STATUS_HTTP_NEED_AUTH);
}
}
// Check function config
if (!$this->cachedFunctionConfig) {
$this->cachedFunctionConfig = $this->ils->checkFunction('getMyTransactionHistory', $this->cachedPatron);
if (false === $this->cachedFunctionConfig) {
return $getErrorMessage('ils_action_unavailable', self::STATUS_HTTP_UNAVAILABLE);
}
}
$paginationHelper = new PaginationHelper();
$pageOptions = $paginationHelper->getOptions(
$page,
null,
$limit ?? $this->defaultPageSize,
$this->cachedFunctionConfig
);
$result = $this->ils->getMyTransactionHistory($this->cachedPatron, $pageOptions['ilsParams']);
if (isset($result['success']) && !$result['success']) {
return $getErrorMessage('An error has occurred', self::STATUS_HTTP_ERROR);
}
return [
'success' => true,
'status' => 'wat',
'function_result' => $result,
'pageOptions' => $pageOptions,
];
}
}
78 changes: 78 additions & 0 deletions module/Finna/src/Finna/AjaxHandler/GetCheckoutHistoryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* Factory for GetCheckoutHistory Ajax handler
*
* PHP version 8
*
* Copyright (C) The National Library of Finland 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package AJAX
* @author Juha Luoma <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/

namespace Finna\AjaxHandler;

use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Psr\Container\ContainerExceptionInterface as ContainerException;
use Psr\Container\ContainerInterface;
use VuFind\AjaxHandler\AbstractIlsAndUserActionFactory;

/**
* Factory for GetCheckoutHistory Ajax handler
*
* @category VuFind
* @package AJAX
* @author Juha Luoma <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class GetCheckoutHistoryFactory extends AbstractIlsAndUserActionFactory
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException&\Throwable if any other error occurs
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __invoke(
ContainerInterface $container,
$requestedName,
array $options = null
) {
$config = $container->get(\VuFind\Config\PluginManager::class)->get('config');
$options = [
$container->get(\VuFind\Record\Loader::class),
$config->Catalog->loan_history_download_batch_limit ?? 1000,
$config->Catalog->historic_loan_page_size ?? 50,
];
return parent::__invoke($container, $requestedName, $options);
}
}
Loading
Loading