From 3ac2935e0889dc7c129c46dd34076187db495a00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Lahmann?= <lahmann@ub.uni-leipzig.de>
Date: Thu, 5 May 2022 14:33:09 +0200
Subject: [PATCH] refs #21701 [finc] added parseDOI to finc Redi driver to
 reflect changed return array from
 https://github.com/vufind-org/vufind/pull/2419

---
 module/finc/src/finc/Resolver/Driver/Redi.php | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/module/finc/src/finc/Resolver/Driver/Redi.php b/module/finc/src/finc/Resolver/Driver/Redi.php
index c95c4a029c8..a75ad7db9a9 100644
--- a/module/finc/src/finc/Resolver/Driver/Redi.php
+++ b/module/finc/src/finc/Resolver/Driver/Redi.php
@@ -16,6 +16,7 @@
 namespace finc\Resolver\Driver;
 
 use VuFind\Resolver\Driver\Redi as RediBase;
+use Zend\Dom\DOMXPath;
 
 /**
  * Redi Link Resolver Driver
@@ -57,4 +58,42 @@ class Redi extends RediBase
         $feed = $this->httpClient->setUri($url)->send()->getBody();
         return $feed;
     }
+
+    /**
+     * Parse the Redi XML response and return array with DOI information.
+     *
+     * @param DOMDocument $xml Loaded xml document
+     *
+     * @deprecated with VuFind 9 - cf. https://github.com/vufind-org/vufind/pull/2419
+     * @return array Get back a array with title, URL and service_type
+     */
+    protected function parseDOI($xml)
+    {
+        $retval = [];
+
+        $xpath = new DOMXPath($xml);
+
+        $doiTerm = $xpath
+            ->query("//dt[@class='doi_t']");
+        $doiDefinition = $xpath
+            ->query("//dd[@class='doi_d']");
+
+        if ($doiTerm->length == $doiDefinition->length) {
+            for ($i = 0; $i < $doiTerm->length; $i++) {
+                $href = $xpath
+                    ->query(".//@href", $doiDefinition->item($i))
+                    ->item(0)->textContent;
+                $retval[] = [
+                    'title' => $doiTerm->item($i)->textContent
+                        . $doiDefinition->item($i)->textContent,
+                    'href' => $href,
+                    'access' => 'unknown',
+                    'coverage' => null,
+                    'service_type' => 'getDOI',
+                ];
+            }
+        }
+
+        return $retval;
+    }
 }
-- 
GitLab