Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Koha | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getUrl | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | /** |
4 | * Koha cover content loader. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2022. |
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 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 Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Content\Covers; |
31 | |
32 | use function in_array; |
33 | |
34 | /** |
35 | * Koha cover content loader. |
36 | * |
37 | * @category VuFind |
38 | * @package Content |
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:content_provider_components |
42 | */ |
43 | class Koha extends \VuFind\Content\AbstractCover |
44 | { |
45 | /** |
46 | * Base URL for Koha covers |
47 | * |
48 | * @var string |
49 | */ |
50 | protected $url; |
51 | |
52 | /** |
53 | * List of sizes for which we should return the thumbnail. Since Koha only has |
54 | * two sizes, this helps us control mapping between VuFind and Koha sizes. |
55 | * |
56 | * @var string[] |
57 | */ |
58 | protected $thumbnailSizes = ['small', 'medium']; |
59 | |
60 | /** |
61 | * Constructor |
62 | * |
63 | * @param string $url Base URL for Koha covers |
64 | */ |
65 | public function __construct(string $url) |
66 | { |
67 | $this->url = $url; |
68 | $this->supportsRecordid = true; |
69 | $this->cacheAllowed = true; |
70 | } |
71 | |
72 | /** |
73 | * Get image URL for a particular API key and set of IDs (or false if invalid). |
74 | * |
75 | * @param string $key API key |
76 | * @param string $size Size of image to load (small/medium/large) |
77 | * @param array $ids Associative array of identifiers (keys may include 'isbn' |
78 | * pointing to an ISBN object and 'issn' pointing to a string) |
79 | * |
80 | * @return string|bool |
81 | * |
82 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
83 | */ |
84 | public function getUrl($key, $size, $ids) |
85 | { |
86 | // We can only do Koha lookups by bib ID: |
87 | if (!isset($ids['recordid'])) { |
88 | return false; |
89 | } |
90 | $url = $this->url . '?'; |
91 | if (in_array($size, $this->thumbnailSizes)) { |
92 | $url .= 'thumbnail=1&'; |
93 | } |
94 | $url .= 'biblionumber=' . urlencode($ids['recordid']); |
95 | return $url; |
96 | } |
97 | } |