Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Syndetics | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 1 |
loadByIsbn | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
90 |
1 | <?php |
2 | |
3 | /** |
4 | * Syndetics Summaries content loader. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) The University of Chicago 2017. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Content |
25 | * @author John Jung <jej@uchicago.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Content\Summaries; |
31 | |
32 | /** |
33 | * Syndetics Summaries content loader. |
34 | * |
35 | * @category VuFind |
36 | * @package Content |
37 | * @author John Jung <jej@uchicago.edu> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org/wiki/development Wiki |
40 | */ |
41 | class Syndetics extends \VuFind\Content\AbstractSyndetics |
42 | { |
43 | /** |
44 | * List of data sources for author notes. |
45 | * |
46 | * @var array |
47 | */ |
48 | protected $sourceList = [ |
49 | 'AVSUMMARY' => [ |
50 | 'title' => 'Summaries', |
51 | 'file' => 'AVSUMMARY.XML', |
52 | 'div' => '<div id="syn_avsummary"></div>', |
53 | ], |
54 | 'SUMMARY' => [ |
55 | 'title' => 'Summaries', |
56 | 'file' => 'SUMMARY.XML', |
57 | 'div' => '<div id="syn_summary"></div>', |
58 | ], |
59 | ]; |
60 | |
61 | /** |
62 | * This method is responsible for connecting to Syndetics for summaries. |
63 | * |
64 | * It first queries the master url for the ISBN entry seeking a summary URL. |
65 | * If a summary URL is found, the script will then use HTTP request to |
66 | * retrieve summaries. |
67 | * Configuration: Sources are processed in order - refer to $sourceList above. |
68 | * |
69 | * @param string $key API key |
70 | * @param \VuFindCode\ISBN $isbnObj ISBN object |
71 | * |
72 | * @throws \Exception |
73 | * @return array Returns array with summary data. |
74 | * @author John Jung <jej@uchicago.edu> |
75 | */ |
76 | public function loadByIsbn($key, \VuFindCode\ISBN $isbnObj) |
77 | { |
78 | // Initialize return value: |
79 | $summaries = []; |
80 | |
81 | // Find out if there are any summaries |
82 | $isbn = $this->getIsbn10($isbnObj); |
83 | $url = $this->getIsbnUrl($isbn, $key); |
84 | $result = $this->getHttpClient($url)->send(); |
85 | if (!$result->isSuccess()) { |
86 | return $summaries; |
87 | } |
88 | |
89 | // Test XML Response |
90 | if (!($xmldoc = $this->xmlToDOMDocument($result->getBody()))) { |
91 | throw new \Exception('Invalid XML'); |
92 | } |
93 | |
94 | foreach ($this->sourceList as $source => $sourceInfo) { |
95 | $nodes = $xmldoc->getElementsByTagName($source); |
96 | if ($nodes->length) { |
97 | // Load summary |
98 | $url = $this->getIsbnUrl($isbn, $key, $sourceInfo['file']); |
99 | $result2 = $this->getHttpClient($url)->send(); |
100 | if (!$result2->isSuccess()) { |
101 | continue; |
102 | } |
103 | |
104 | // Test XML Response |
105 | $xmldoc2 = $this->xmlToDOMDocument($result2->getBody()); |
106 | if (!$xmldoc2) { |
107 | throw new \Exception('Invalid XML'); |
108 | } |
109 | |
110 | // If we have syndetics plus, we don't actually want the content |
111 | // we'll just stick in the relevant div |
112 | if ($this->usePlus) { |
113 | $summaries[] = $sourceInfo['div']; |
114 | } else { |
115 | // Get the marc field for summaries. (520) |
116 | $nodes = $xmldoc2->GetElementsbyTagName('Fld520'); |
117 | foreach ($nodes as $node) { |
118 | $summaries[] = preg_replace( |
119 | '/<a>|<a [^>]*>|<\/a>/', |
120 | '', |
121 | html_entity_decode($node->nodeValue) |
122 | ); |
123 | } |
124 | } |
125 | } |
126 | } |
127 | |
128 | return $summaries; |
129 | } |
130 | } |