From 31894348de6f6ff10bf0eee625336cdb3da91f22 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Tue, 15 Sep 2020 08:55:55 -0400
Subject: [PATCH] Refactor code to make username easier to override.

---
 .../src/VuFind/Controller/RelaisController.php | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/module/VuFind/src/VuFind/Controller/RelaisController.php b/module/VuFind/src/VuFind/Controller/RelaisController.php
index d66afb60c23..303c5fe8504 100644
--- a/module/VuFind/src/VuFind/Controller/RelaisController.php
+++ b/module/VuFind/src/VuFind/Controller/RelaisController.php
@@ -62,13 +62,29 @@ class RelaisController extends AbstractBase
         $q = $this->params()->fromQuery('query');
         $url = $baseUrl . '?LS=' . urlencode($symbol)
             . '&dest=discovery&group=patron&PI='
-            . urlencode($patron['cat_username']);
+            . urlencode($this->getRelaisUserIdentifier($patron));
         if (!empty($q)) {
             $url .= '&query=' . rawurlencode($q);
         }
         return $this->redirect()->toUrl($url);
     }
 
+    /**
+     * Given patron data from the catalogLogin() method, return the appropriate
+     * identifer for use with Relais.
+     *
+     * @param array $patron Patron details
+     *
+     * @return string
+     */
+    protected function getRelaisUserIdentifier($patron)
+    {
+        // By default we assume the cat_username field provides the appropriate
+        // username... but if you have a more complex situation at your local
+        // institution, you can extend the controller and override this method.
+        return $patron['cat_username'];
+    }
+
     /**
      * Relais request action.
      *
-- 
GitLab