aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/librarysearch/resultparsers/K10PlusLibraryResultParser.php
diff options
context:
space:
mode:
authorPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
committerPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
commit4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch)
tree5c07151ae61276d334e88f6309c30d439a85c12e /lib/classes/librarysearch/resultparsers/K10PlusLibraryResultParser.php
parentda0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff)
parent97a188592c679890a25c37ab78463add76a52ff7 (diff)
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'lib/classes/librarysearch/resultparsers/K10PlusLibraryResultParser.php')
-rw-r--r--lib/classes/librarysearch/resultparsers/K10PlusLibraryResultParser.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/classes/librarysearch/resultparsers/K10PlusLibraryResultParser.php b/lib/classes/librarysearch/resultparsers/K10PlusLibraryResultParser.php
new file mode 100644
index 0000000..b4b3a20
--- /dev/null
+++ b/lib/classes/librarysearch/resultparsers/K10PlusLibraryResultParser.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * This file is part of Stud.IP.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * @author Moritz Strohm <strohm@data-quest.de>
+ * @copyright 2020
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
+ * @category Stud.IP
+ * @since 4.6
+ */
+
+
+/**
+ * This is a LibraryResultParser implementation for the K10PlusZentral catalog.
+ *
+ * @see LibraryResultParser
+ */
+class K10PlusLibraryResultParser implements LibraryResultParser
+{
+ /**
+ * @see LibraryResultParser::readResultSet
+ */
+ public function readResultSet($data = '') : array
+ {
+ //Convert the data to JSON:
+ $json_data = json_decode($data, true);
+
+ $header = $json_data['responseHeader'];
+
+ if ($header['status'] != 0) {
+ //Probably an error!
+ return [];
+ }
+
+ if (!$json_data['response']) {
+ //JSON structure error!
+ return [];
+ }
+
+ if (!$json_data['response']['docs'] || ($json_data['response']['numFound'] == 0)) {
+ //No data found.
+ return [];
+ }
+
+ $result_set = [];
+ foreach ($json_data['response']['docs'] as $doc_data) {
+ $result = $this->readRecord($doc_data);
+ if ($result instanceof LibraryDocument) {
+ $result_set[] = $result;
+ }
+ }
+ return $result_set;
+ }
+
+
+ /**
+ * @see LibraryResultParser::readRecord
+ */
+ public function readRecord($data = '') : LibraryDocument
+ {
+ $parser = new MarcxmlLibraryResultParser();
+ //The result is one marcxml record in a collection:
+ $result = $parser->readResultSet($data['fullrecord_marcxml'])[0];
+ //Now we have to set the type using the data from the JSON fields:
+ $doc_type = $data['format'][0];
+ if (($doc_type == 'Article') || ($doc_type == 'electronic Article')) {
+ $result->type = 'article';
+ } elseif (($doc_type == 'Book') || ($doc_type == 'eBook')) {
+ $result->type = 'book';
+ } elseif ($doc_type == 'journal') {
+ $result->type = 'article-journal';
+ }
+ if (!isset($result->csl_data['URL'])) {
+ $result->csl_data['URL'] = $data['url'];
+ }
+ $result->filterCslFieldsByType();
+ return $result;
+ }
+}