Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
RecordCollection | |
100.00% |
13 / 13 |
|
100.00% |
7 / 7 |
9 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
getTotal | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFacets | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSpellcheck | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
getBestBets | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDatabaseRecommendations | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTopicRecommendations | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * WorldCat record collection. |
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 Search |
25 | * @author David Maus <maus@hab.de> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org |
28 | */ |
29 | |
30 | namespace VuFindSearch\Backend\Summon\Response; |
31 | |
32 | use VuFindSearch\Response\AbstractRecordCollection; |
33 | |
34 | use function is_array; |
35 | |
36 | /** |
37 | * WorldCat record collection. |
38 | * |
39 | * @category VuFind |
40 | * @package Search |
41 | * @author David Maus <maus@hab.de> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org |
44 | */ |
45 | class RecordCollection extends AbstractRecordCollection |
46 | { |
47 | /** |
48 | * Raw response. |
49 | * |
50 | * @var array |
51 | */ |
52 | protected $response; |
53 | |
54 | /** |
55 | * Constructor. |
56 | * |
57 | * @param array $response Summon response |
58 | * |
59 | * @return void |
60 | */ |
61 | public function __construct(array $response) |
62 | { |
63 | $this->response = $response; |
64 | |
65 | // Determine the offset: |
66 | $page = isset($this->response['query']['pageNumber']) |
67 | ? $this->response['query']['pageNumber'] - 1 : 0; |
68 | $size = $this->response['query']['pageSize'] ?? 0; |
69 | $this->offset = $page * $size; |
70 | |
71 | $this->rewind(); |
72 | } |
73 | |
74 | /** |
75 | * Return total number of records found. |
76 | * |
77 | * @return int |
78 | */ |
79 | public function getTotal() |
80 | { |
81 | return $this->response['recordCount'] ?? 0; |
82 | } |
83 | |
84 | /** |
85 | * Return facet information. |
86 | * |
87 | * @return array |
88 | */ |
89 | public function getFacets() |
90 | { |
91 | return $this->response['facetFields'] ?? []; |
92 | } |
93 | |
94 | /** |
95 | * Get spelling suggestions. |
96 | * |
97 | * @return array |
98 | */ |
99 | public function getSpellcheck() |
100 | { |
101 | return is_array($this->response['didYouMeanSuggestions'] ?? null) |
102 | ? $this->response['didYouMeanSuggestions'] : []; |
103 | } |
104 | |
105 | /** |
106 | * Get best bets from Summon, if any. |
107 | * |
108 | * @return array|bool false if no recommendations, detailed array otherwise. |
109 | */ |
110 | public function getBestBets() |
111 | { |
112 | return $this->response['recommendationLists']['bestBet'] ?? false; |
113 | } |
114 | |
115 | /** |
116 | * Get database recommendations from Summon, if any. |
117 | * |
118 | * @return array|bool false if no recommendations, detailed array otherwise. |
119 | */ |
120 | public function getDatabaseRecommendations() |
121 | { |
122 | return $this->response['recommendationLists']['database'] ?? false; |
123 | } |
124 | |
125 | /** |
126 | * Get topic recommendations from Summon, if any. |
127 | * |
128 | * @return array|bool false if no recommendations, detailed array otherwise. |
129 | */ |
130 | public function getTopicRecommendations() |
131 | { |
132 | return $this->response['topicRecommendations'] ?? false; |
133 | } |
134 | } |