Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
2.04% covered (danger)
2.04%
1 / 49
5.00% covered (danger)
5.00%
1 / 20
CRAP
0.00% covered (danger)
0.00%
0 / 1
Primo
2.04% covered (danger)
2.04%
1 / 49
5.00% covered (danger)
5.00%
1 / 20
876.01
0.00% covered (danger)
0.00%
0 / 1
 getShortTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHighlightedTitle
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getPrimaryAuthors
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getCreators
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAllSubjectHeadings
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getContainerReference
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getContainerEndPage
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFormats
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getIsPartOf
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSource
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getISSNs
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getLanguages
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getThumbnail
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getURLs
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
 getUniqueID
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getCitations
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getSupportedCitationFormats
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 exportDisabled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Model for Primo Central records.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2010.
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  RecordDrivers
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development:plugins:record_drivers Wiki
28 */
29
30namespace VuFind\RecordDriver;
31
32use function in_array;
33
34/**
35 * Model for Primo Central records.
36 *
37 * @category VuFind
38 * @package  RecordDrivers
39 * @author   Demian Katz <demian.katz@villanova.edu>
40 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
41 * @link     https://vufind.org/wiki/development:plugins:record_drivers Wiki
42 */
43class Primo extends DefaultRecord
44{
45    /**
46     * Get the short (pre-subtitle) title of the record.
47     *
48     * @return string
49     */
50    public function getShortTitle()
51    {
52        return $this->getTitle();
53    }
54
55    /**
56     * Get the full title of the record.
57     *
58     * @return string
59     */
60    public function getTitle()
61    {
62        return $this->fields['title'] ?? '';
63    }
64
65    /**
66     * Get a highlighted title string, if available.
67     *
68     * @return string
69     */
70    public function getHighlightedTitle()
71    {
72        // Don't check for highlighted values if highlighting is disabled:
73        if (!$this->highlight) {
74            return '';
75        }
76        return $this->fields['highlightDetails']['title'][0] ?? '';
77    }
78
79    /**
80     * Get the main authors of the record.
81     *
82     * @return array
83     */
84    public function getPrimaryAuthors()
85    {
86        return isset($this->fields['creator'])
87            ? array_map('trim', $this->fields['creator']) : [];
88    }
89
90    /**
91     * Get the authors of the record.
92     *
93     * @return array
94     */
95    public function getCreators()
96    {
97        return $this->fields['creator'] ?? [];
98    }
99
100    /**
101     * Get an array of all subject headings associated with the record
102     * (may be empty).
103     *
104     * @param bool $extended Whether to return a keyed array with the following
105     * keys:
106     * - heading: the actual subject heading chunks
107     * - type: heading type
108     * - source: source vocabulary
109     *
110     * @return array
111     */
112    public function getAllSubjectHeadings($extended = false)
113    {
114        $base = $this->fields['subjects'] ?? [];
115        $callback = function ($str) use ($extended) {
116            $s = array_map('trim', explode(' -- ', $str));
117            return $extended
118                ? ['heading' => $s, 'type' => '', 'source' => '']
119                : $s;
120        };
121        return array_map($callback, $base);
122    }
123
124    /**
125     * Get a full, free-form reference to the context of the item that contains this
126     * record (i.e. volume, year, issue, pages).
127     *
128     * @return string
129     */
130    public function getContainerReference()
131    {
132        $parts = explode(',', $this->getIsPartOf(), 2);
133        return isset($parts[1]) ? trim($parts[1]) : '';
134    }
135
136    /**
137     * Get the end page of the item that contains this record.
138     *
139     * @return string
140     */
141    public function getContainerEndPage()
142    {
143        return $this->fields['container_end_page'] ?? '';
144    }
145
146    /**
147     * Get an array of all the formats associated with the record.
148     *
149     * @return array
150     */
151    public function getFormats()
152    {
153        // Convert to displayable words and return as an array:
154        return array_map(
155            function ($s) {
156                return ucwords(str_replace('_', ' ', $s));
157            },
158            (array)($this->fields['format'])
159        );
160    }
161
162    /**
163     * Get the item's "is part of".
164     *
165     * @return string
166     */
167    public function getIsPartOf()
168    {
169        return $this->fields['ispartof'] ?? '';
170    }
171
172    /**
173     * Get the item's description.
174     *
175     * @return array
176     */
177    public function getDescription()
178    {
179        return $this->fields['description'] ?? [];
180    }
181
182    /**
183     * Get the item's source.
184     *
185     * @return array
186     */
187    public function getSource()
188    {
189        $base = $this->fields['source'] ?? '';
190        // Trim off unwanted image and any other tags:
191        return strip_tags($base);
192    }
193
194    /**
195     * Get an array of all ISSNs associated with the record (may be empty).
196     *
197     * @return array
198     */
199    public function getISSNs()
200    {
201        $issns = [];
202        if (isset($this->fields['issn'])) {
203            $issns = $this->fields['issn'];
204        }
205        return $issns;
206    }
207
208    /**
209     * Get the language associated with the record.
210     *
211     * @return array
212     */
213    public function getLanguages()
214    {
215        return isset($this->fields['language'])
216            ? (array)$this->fields['language'] : [];
217    }
218
219    /**
220     * Returns one of three things: a full URL to a thumbnail preview of the record
221     * if an image is available in an external system; an array of parameters to
222     * send to VuFind's internal cover generator if no fixed URL exists; or false
223     * if no thumbnail can be generated.
224     *
225     * @param string $size Size of thumbnail (small, medium or large -- small is
226     * default).
227     *
228     * @return string|array|bool
229     */
230    public function getThumbnail($size = 'small')
231    {
232        if ($isbn = $this->getCleanISBN()) {
233            return ['size' => $size, 'isn' => $isbn];
234        }
235        return ['size' => $size, 'contenttype' => 'JournalArticle'];
236    }
237
238    /**
239     * Return an array of associative URL arrays with one or more of the following
240     * keys:
241     *
242     * <li>
243     *   <ul>desc: URL description text to display (optional)</ul>
244     *   <ul>url: fully-formed URL (required if 'route' is absent)</ul>
245     *   <ul>route: VuFind route to build URL with (required if 'url' is absent)</ul>
246     *   <ul>routeParams: Parameters for route (optional)</ul>
247     *   <ul>queryString: Query params to append after building route (optional)</ul>
248     * </li>
249     *
250     * @return array
251     */
252    public function getURLs()
253    {
254        $retVal = [];
255
256        if (isset($this->fields['url'])) {
257            $retVal[] = [];
258            $retVal[0]['url'] = $this->fields['url'];
259            if (isset($this->fields['fulltext'])) {
260                $desc = $this->fields['fulltext'] == 'fulltext'
261                    ? 'Get full text' : 'Request full text';
262                $retVal[0]['desc'] = $this->translate($desc);
263            }
264        }
265
266        return $retVal;
267    }
268
269    /**
270     * Return the unique identifier of this record within the Solr index;
271     * useful for retrieving additional information (like tags and user
272     * comments) from the external MySQL database.
273     *
274     * @return string Unique identifier.
275     */
276    public function getUniqueID()
277    {
278        return $this->fields['recordid'];
279    }
280
281    /**
282     * Get citation references
283     *
284     * @return array
285     */
286    public function getCitations(): array
287    {
288        return [
289            'cites' => $this->fields['cites'] ?? [],
290            'cited_by' => $this->fields['cited_by'] ?? [],
291        ];
292    }
293
294    /**
295     * Get an array of strings representing citation formats supported
296     * by this record's data (empty if none). For possible legal values,
297     * see /application/themes/root/helpers/Citation.php, getCitation()
298     * method.
299     *
300     * @return array Strings representing citation formats.
301     */
302    protected function getSupportedCitationFormats()
303    {
304        return [];
305    }
306
307    /**
308     * Indicate whether export is disabled for a particular format.
309     *
310     * @param string $format Export format
311     *
312     * @return bool
313     *
314     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
315     */
316    public function exportDisabled($format)
317    {
318        // Support export for EndNote and RefWorks
319        return !in_array($format, ['EndNote', 'RefWorks']);
320    }
321}