From 08252a8353a06b6413abcf70fc7fa6c0730c60e9 Mon Sep 17 00:00:00 2001
From: Robert Lange <robert.lange@uni-leipzig.de>
Date: Tue, 6 Jun 2023 21:21:53 +0200
Subject: [PATCH] refs #23952 [finc] refactor loanHistoryAction

* rename loanHistoryAction to historicloansAction as in VuFind MyResearchController
** rename in menu

* config: set historic_loan_page_size to 30 as it is obvious default???

* rename getMyLoanHistory to getMyTransactionHistory in LiberoWachtlTrait
** remove erronemous custom pagination
** rename also in AjaxHandler for badges count

* remove obsolete code for paginator in historicloans.phtml
---
 local/config/vufind/config.ini                |  2 +-
 .../finc/AjaxHandler/GetUserLoanHistory.php   |  2 +-
 .../src/finc/ILS/Driver/LiberoWachtlTrait.php | 49 +++----------------
 .../templates/myresearch/historicloans.phtml  | 20 +-------
 themes/finc/templates/myresearch/menu.phtml   |  4 +-
 5 files changed, 12 insertions(+), 65 deletions(-)

diff --git a/local/config/vufind/config.ini b/local/config/vufind/config.ini
index 94907f0f9e1..e40e2edcb2d 100644
--- a/local/config/vufind/config.ini
+++ b/local/config/vufind/config.ini
@@ -363,7 +363,7 @@ title_level_holds_mode = "disabled"
 
 ; The number of historic loans to display per page; 0 for no limit (may cause
 ; memory problems for users with a large number of historic loans). Default = 50
-;historic_loan_page_size = 50
+historic_loan_page_size = 30
 
 ; Whether to display the item barcode for each loan. Default is false.
 ;display_checked_out_item_barcode = true
diff --git a/module/finc/src/finc/AjaxHandler/GetUserLoanHistory.php b/module/finc/src/finc/AjaxHandler/GetUserLoanHistory.php
index 08e6b0ee39b..62291085896 100644
--- a/module/finc/src/finc/AjaxHandler/GetUserLoanHistory.php
+++ b/module/finc/src/finc/AjaxHandler/GetUserLoanHistory.php
@@ -55,7 +55,7 @@ class GetUserLoanHistory extends \VuFind\AjaxHandler\AbstractUserRequestAction
         if (!$this->ils->checkCapability('getMyTransactions')) {
             return $this->formatResponse('', self::STATUS_HTTP_ERROR, 405);
         }
-        $items = $this->ils->getMyLoanHistory($patron, 100);
+        $items = $this->ils->getMyTransactionHistory($patron, 0);
         $counts = [ 'ok' => $items['total'] ];
 
         return $this->formatResponse($counts);
diff --git a/module/finc/src/finc/ILS/Driver/LiberoWachtlTrait.php b/module/finc/src/finc/ILS/Driver/LiberoWachtlTrait.php
index d15ced6d27d..5648473798b 100644
--- a/module/finc/src/finc/ILS/Driver/LiberoWachtlTrait.php
+++ b/module/finc/src/finc/ILS/Driver/LiberoWachtlTrait.php
@@ -626,11 +626,10 @@ trait LiberoWachtlTrait
     }
 
     /**
-     * Customized getMyLoanHistory
+     * Customized getMyTransactionHistory method for LiberoWachtl
      *
-     * @param array $patron   Array returned from patronLogin()
-     * @param int   $lastLine Integer until LiberoWachtl should process history
-     *                        incrementally
+     * @param array $patron      Array returned from patronLogin()
+     * @param int   $currentPage Current page of loan history
      *
      * @return array $retval
      *     - ['items'] Array with items of loan history
@@ -638,12 +637,12 @@ trait LiberoWachtlTrait
      * @throws \Exception
      * @throws ILSException
      */
-    public function getMyLoanHistory($patron, $lastLine)
+    public function getMyTransactionHistory($patron, $currentPage = null)
     {
         $params = $this->getLiberoWachtlRequestParams();
         $params['memberCode'] = $patron['cat_username'];
         $params['password'] = $patron['cat_password'];
-        $params['pageNumber'] = 1;
+        $params['pageNumber'] = $currentPage ?? 1;
         try {
             $result = $this->httpService->get(
                 $this->getLiberoWachtlUrl() . 'getMyLoanHistory.jsp',
@@ -675,43 +674,7 @@ trait LiberoWachtlTrait
         }
         $retval = [];
         $retval['total'] = $details['rowCount'];
-        $retval['items'] = $details['getMyLoanHistory'];
-        // Check if more entries are required than in first called.
-        if (count($details['getMyLoanHistory']) < $lastLine) {
-            // iteration over Libero view pager and security anchor to not iterate
-            // over more pages than exists
-            for ($page = 2; $page <= $details['pageCount']; $page++) {
-                // overwrite param pageNumber
-                $params['pageNumber'] = $page;
-                try {
-                    $result = $this->httpService->get(
-                        $this->getLiberoWachtlUrl() . 'getMyLoanHistory.jsp',
-                        $params,
-                        null,
-                        $this->getLiberoWachtlRequestHeaders()
-                    );
-                } catch (\Exception $e) {
-                    throw new ILSException($e->getMessage());
-                }
-                if (!$result->isSuccess()) {
-                    // log error for debugging
-                    $this->debug(
-                        'HTTP status ' . $result->getStatusCode() .
-                        ' received'
-                    );
-                    return false;
-                }
-                // merge with previous request
-                $retval['items'] = array_merge(
-                    $retval['items'],
-                    $this->getLiberoWachtlResult($result, 'getMyLoanHistory')
-                );
-                // If there are requested lines collected break the iteration
-                if (count($retval['items']) > $lastLine) {
-                    break;
-                }
-            }
-        }
+        $retval['items'] = $this->getLiberoWachtlResult($result, 'getMyLoanHistory');
 
         $ids = $this->getAlternativeItemId(array_column($retval['items'], FincILS::ILS_IDENTIFIER_BARCODE), FincILS::ILS_IDENTIFIER_BARCODE);
         foreach ($retval['items'] as $number => &$current) {
diff --git a/themes/finc/templates/myresearch/historicloans.phtml b/themes/finc/templates/myresearch/historicloans.phtml
index 3a0aef9bb9e..c8308acf766 100644
--- a/themes/finc/templates/myresearch/historicloans.phtml
+++ b/themes/finc/templates/myresearch/historicloans.phtml
@@ -17,25 +17,9 @@
 
   <?=$this->context($this)->renderInContext('librarycards/selectcard.phtml', ['user' => $this->auth()->isLoggedIn()]); ?>
 
-  <?php if (!empty($this->transactions)): ?>
+  <?php if (!empty($this->recordList)): ?>
     <?php /* finc adds aria-label */ ?>
     <nav class="search-header hidden-print" aria-label="<?=$this->transEscAttr('aria_search_header')?>">
-      <?php if ($this->paginator): ?>
-        <div class="search-stats">
-          <?php
-            $end = min(
-              $this->paginator->getAbsoluteItemNumber($this->paginator->getItemCountPerPage()),
-              $this->paginator->getTotalItemCount()
-            );
-            $transParams = [
-              '%%start%%' => $this->localizedNumber($this->paginator->getAbsoluteItemNumber(1)),
-              '%%end%%' => $this->localizedNumber($end),
-              '%%total%%' => $this->localizedNumber($this->paginator->getTotalItemCount())
-            ];
-          ?>
-          <?=$this->translate('showing_items_of_html', $transParams); ?>
-        </div>
-      <?php endif; ?>
       <?php if ($this->sortList): ?>
         <?=$this->context($this)->renderInContext('myresearch/controls/sort.phtml', ['sortList' => $this->sortList]); ?>
       <?php endif; ?>
@@ -43,7 +27,7 @@
 
     <?php /* finc uses ul to present list structure correctly, adds empty 'lang' attribute #18535 */ ?>
     <ul class="record-list">
-    <?php $i = 0; foreach ($this->transactions as $resource): ?>
+    <?php $i = 0; foreach ($this->recordList as $resource): ?>
       <?php $ilsDetails = $resource->getExtraDetail('ils_details'); ?>
       <?php $describedById = $resource->getSourceIdentifier() . '|' . (empty($resource->getUniqueId()) ? md5(serialize($resource->getExtraDetail("ils_details"))) : $resource->getUniqueId()); ?>
       <li id="record<?=$this->escapeHtmlAttr($resource->getUniqueId())?>" class="result">
diff --git a/themes/finc/templates/myresearch/menu.phtml b/themes/finc/templates/myresearch/menu.phtml
index a143163ef6d..a3c4b72f1ec 100644
--- a/themes/finc/templates/myresearch/menu.phtml
+++ b/themes/finc/templates/myresearch/menu.phtml
@@ -78,9 +78,9 @@
     </li>
   <?php endif; ?>
   <?php /* finc: adds historic loans */ ?>
-  <?php if ($ilsOnline && $this->ils()->checkCapability('getMyLoanHistory', $capabilityParams) && $routeExists('myresearch-loanhistory')): ?>
+  <?php if ($ilsOnline && $this->ils()->checkCapability('getMyTransactionHistory', $capabilityParams) && $routeExists('myresearch-loanhistory')): ?>
     <li class="facet">
-      <a href="<?=$this->url('myresearch-loanhistory')?>"<?=$this->active == 'loanhistory' ? ' class="active" aria-current="page"' : ''?>>
+      <a href="<?=$this->url('myresearch-historicloans')?>"<?=$this->active == 'historicloans' ? ' class="active" aria-current="page"' : ''?>>
         <i class="fa fa-fw fa-history" aria-hidden="true"></i> <?=$this->transEsc('Loan History')?>
       </a>
     </li>
-- 
GitLab