From a04b02245a48e8e7ce1f05535f2b3113515bba11 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 5 Nov 2020 11:36:32 -0500
Subject: [PATCH] Implement getContainerEndPage() for EDS (#1784)

---
 module/VuFind/src/VuFind/RecordDriver/EDS.php | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/module/VuFind/src/VuFind/RecordDriver/EDS.php b/module/VuFind/src/VuFind/RecordDriver/EDS.php
index 946a29af3b9..b9e09aab793 100644
--- a/module/VuFind/src/VuFind/RecordDriver/EDS.php
+++ b/module/VuFind/src/VuFind/RecordDriver/EDS.php
@@ -782,6 +782,29 @@ class EDS extends DefaultRecord
         return $pagination['StartPage'] ?? '';
     }
 
+    /**
+     * Get the end page of the item that contains this record.
+     *
+     * @return string
+     */
+    public function getContainerEndPage()
+    {
+        // EBSCO doesn't make this information readily available, but in some
+        // cases we can abstract it from an OpenURL.
+        $startPage = $this->getContainerStartPage();
+        if (!empty($startPage)) {
+            $regex = "/&pages={$startPage}-(\d+)/";
+            foreach ($this->getFTCustomLinks() as $link) {
+                if (preg_match($regex, $link['Url'] ?? '', $matches)) {
+                    if (isset($matches[1])) {
+                        return $matches[1];
+                    }
+                }
+            }
+        }
+        return '';
+    }
+
     /**
      * Returns an array of formats based on publication type.
      *
-- 
GitLab