From ccd47d82f9ac04d9f12795a00c6e1d15ef556d02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mathias=20Maa=C3=9F?= <mathias.maass@uni-leipzig.de>
Date: Thu, 24 Nov 2022 19:23:37 +0100
Subject: [PATCH] refs #22779 [finc] create ajax handler
 GetUserMediaReadyToPickup and GetUserPermanentLoans

---
 module/finc/config/module.config.php          | 10 ++-
 .../AjaxHandler/GetUserMediaReadyToPickup.php | 44 +++++++++++
 .../AjaxHandler/GetUserPermanentLoans.php     | 78 +++++++++++++++++++
 3 files changed, 131 insertions(+), 1 deletion(-)
 create mode 100644 module/finc/src/finc/AjaxHandler/GetUserMediaReadyToPickup.php
 create mode 100644 module/finc/src/finc/AjaxHandler/GetUserPermanentLoans.php

diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php
index 5969f502e6f..eaabdac9936 100644
--- a/module/finc/config/module.config.php
+++ b/module/finc/config/module.config.php
@@ -91,7 +91,11 @@ $config = [
                     'finc\AjaxHandler\GetResolverLinks' =>
                         'finc\AjaxHandler\GetResolverLinksFactory',
                     'finc\AjaxHandler\GetRecordCover' =>
-                        'finc\AjaxHandler\GetRecordCoverFactory'
+                        'finc\AjaxHandler\GetRecordCoverFactory',
+                    'finc\AjaxHandler\GetUserMediaReadyToPickup' =>
+                        'VuFind\AjaxHandler\AbstractIlsAndUserActionFactory',
+                    'finc\AjaxHandler\GetUserPermanentLoans' =>
+                        'VuFind\AjaxHandler\AbstractIlsAndUserActionFactory',
                 ],
                 'aliases' => [
                     'getAdditionalAccountInfo' =>
@@ -104,6 +108,10 @@ $config = [
                         'finc\AjaxHandler\GetResolverLinks',
                     'getRecordCover' =>
                         'finc\AjaxHandler\GetRecordCover',
+                    'getUserMediaReadyToPickup' =>
+                        'finc\AjaxHandler\GetUserMediaReadyToPickup',
+                    'getUserPermanentLoans' => 
+                        'finc\AjaxHandler\GetUserPermanentLoans',
                 ]
             ],
             'auth' => [
diff --git a/module/finc/src/finc/AjaxHandler/GetUserMediaReadyToPickup.php b/module/finc/src/finc/AjaxHandler/GetUserMediaReadyToPickup.php
new file mode 100644
index 00000000000..0d17ebbc927
--- /dev/null
+++ b/module/finc/src/finc/AjaxHandler/GetUserMediaReadyToPickup.php
@@ -0,0 +1,44 @@
+<?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;
+
+/**
+ *
+ * @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 GetUserMediaReadyToPickup extends \VuFind\AjaxHandler\AbstractUserRequestAction
+{
+    /**
+     * ILS driver method for data retrieval.
+     *
+     * @var string
+     */
+    protected $lookupMethod = 'getMyMediaReadyToPickup';
+}
diff --git a/module/finc/src/finc/AjaxHandler/GetUserPermanentLoans.php b/module/finc/src/finc/AjaxHandler/GetUserPermanentLoans.php
new file mode 100644
index 00000000000..b259aa2c3cf
--- /dev/null
+++ b/module/finc/src/finc/AjaxHandler/GetUserPermanentLoans.php
@@ -0,0 +1,78 @@
+<?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 GetUserPermanentLoans 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->getMyPermanentLoans($patron);
+        $counts = [
+            'ok' => 0,
+            'warn' => 0,
+            'overdue' => 0
+        ];
+        foreach ($items as $item) {
+            if (!isset($item['dueStatus'])) {
+                continue;
+            }
+            if ($item['dueStatus'] == 'overdue') {
+                $counts['overdue'] += 1;
+            } elseif ($item['dueStatus'] == 'due') {
+                $counts['warn'] += 1;
+            } else {
+                $counts['ok'] += 1;
+            }
+        }
+        return $this->formatResponse($counts);
+    }
+}
-- 
GitLab