From 02b05911f217a0e11861378b36cd7221df5c5914 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mathias=20Maa=C3=9F?= <mathias.maass@uni-leipzig.de>
Date: Fri, 21 Apr 2023 16:36:37 +0200
Subject: [PATCH] refs #22765 [finc] account menu: adjust in order to use new
 vufind features

---
 module/finc/config/module.config.php          |  4 ++
 .../finc/AjaxHandler/GetUserLoanHistory.php   | 63 +++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 module/finc/src/finc/AjaxHandler/GetUserLoanHistory.php

diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php
index d8ed744e0e4..c836410c342 100644
--- a/module/finc/config/module.config.php
+++ b/module/finc/config/module.config.php
@@ -90,6 +90,8 @@ $config = [
                         'finc\AjaxHandler\GetResolverLinksFactory',
                     'finc\AjaxHandler\GetUserILLRequestsStats' =>
                         'VuFind\AjaxHandler\AbstractIlsAndUserActionFactory',
+                    'finc\AjaxHandler\GetUserLoanHistory' =>
+                        'VuFind\AjaxHandler\AbstractIlsAndUserActionFactory',
                     'finc\AjaxHandler\GetUserMediaReadyToPickup' =>
                         'VuFind\AjaxHandler\AbstractIlsAndUserActionFactory',
                     'finc\AjaxHandler\GetUserPermanentLoans' =>
@@ -106,6 +108,8 @@ $config = [
                         'finc\AjaxHandler\GetResolverLinks',
                     'getUserILLRequestsStats' =>
                         'finc\AjaxHandler\GetUserILLRequestsStats',
+                    'getUserLoanHistory' =>
+                        'finc\AjaxHandler\GetUserLoanHistory',
                     'getUserMediaReadyToPickup' =>
                         'finc\AjaxHandler\GetUserMediaReadyToPickup',
                     'getUserPermanentLoans' =>
diff --git a/module/finc/src/finc/AjaxHandler/GetUserLoanHistory.php b/module/finc/src/finc/AjaxHandler/GetUserLoanHistory.php
new file mode 100644
index 00000000000..5f1ebed4a46
--- /dev/null
+++ b/module/finc/src/finc/AjaxHandler/GetUserLoanHistory.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * PHP version 7
+ *
+ * Copyright (C) Villanova University 2018.
+ *
+ * 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   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development Wiki
+ */
+namespace finc\AjaxHandler;
+
+use Zend\Mvc\Controller\Plugin\Params;
+
+/**
+ * "Get User Holds" AJAX handler
+ *
+ * @category VuFind
+ * @package  AJAX
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development Wiki
+ */
+class GetUserLoanHistory extends \VuFind\AjaxHandler\AbstractUserRequestAction
+{
+     /**
+      * Handle a request.
+      *
+      * @param Params $params Parameter helper from controller
+      *
+      * @return array [response data, internal status code, HTTP status code]
+      */
+    public function handleRequest(Params $params)
+    {
+        $this->disableSessionWrites();  // avoid session write timing bug
+        $patron = $this->ilsAuthenticator->storedCatalogLogin();
+        if (!$patron) {
+            return $this->formatResponse('', self::STATUS_HTTP_NEED_AUTH, 401);
+        }
+        if (!$this->ils->checkCapability('getMyTransactions')) {
+            return $this->formatResponse('', self::STATUS_HTTP_ERROR, 405);
+        }
+        $items = $this->ils->getMyLoanHistory($patron, 100);
+        $counts = [ 'ok' => $items['total'] ];
+
+        return $this->formatResponse($counts);
+    }
+}
-- 
GitLab