Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
21 / 21 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
Backend | |
100.00% |
21 / 21 |
|
100.00% |
8 / 8 |
10 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
search | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
retrieve | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getQueryBuilder | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setQueryBuilder | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRecordCollectionFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getConnector | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createRecordCollection | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * EIT backend. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Julia Bauder 2013. |
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 Julia Bauder <bauderj@grinnell.edu> |
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\EIT; |
31 | |
32 | use VuFindSearch\Backend\AbstractBackend; |
33 | use VuFindSearch\ParamBag; |
34 | use VuFindSearch\Query\AbstractQuery; |
35 | use VuFindSearch\Response\RecordCollectionFactoryInterface; |
36 | use VuFindSearch\Response\RecordCollectionInterface; |
37 | |
38 | /** |
39 | * EIT backend. |
40 | * |
41 | * @category VuFind |
42 | * @package Search |
43 | * @author Julia Bauder <bauderj@grinnell.edu> |
44 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
45 | * @link https://vufind.org |
46 | */ |
47 | class Backend extends AbstractBackend |
48 | { |
49 | /** |
50 | * Connector. |
51 | * |
52 | * @var Connector |
53 | */ |
54 | protected $connector; |
55 | |
56 | /** |
57 | * Query builder. |
58 | * |
59 | * @var QueryBuilder |
60 | */ |
61 | protected $queryBuilder; |
62 | |
63 | /** |
64 | * Constructor. |
65 | * |
66 | * @param Connector $connector EIT connector |
67 | * @param RecordCollectionFactoryInterface $factory Record collection factory |
68 | * |
69 | * @return void |
70 | */ |
71 | public function __construct( |
72 | Connector $connector, |
73 | RecordCollectionFactoryInterface $factory |
74 | ) { |
75 | $this->setRecordCollectionFactory($factory); |
76 | $this->connector = $connector; |
77 | } |
78 | |
79 | /** |
80 | * Perform a search and return record collection. |
81 | * |
82 | * @param AbstractQuery $query Search query |
83 | * @param int $offset Search offset |
84 | * @param int $limit Search limit |
85 | * @param ParamBag $params Search backend parameters |
86 | * |
87 | * @return RecordCollectionInterface |
88 | */ |
89 | public function search( |
90 | AbstractQuery $query, |
91 | $offset, |
92 | $limit, |
93 | ParamBag $params = null |
94 | ) { |
95 | if (null === $params) { |
96 | $params = new ParamBag(); |
97 | } |
98 | $params->mergeWith($this->getQueryBuilder()->build($query)); |
99 | $response = $this->connector->search($params, $offset, $limit); |
100 | $this->debug('Response: ' . $this->varDump($response)); |
101 | $collection = $this->createRecordCollection($response); |
102 | $this->injectSourceIdentifier($collection); |
103 | return $collection; |
104 | } |
105 | |
106 | /** |
107 | * Retrieve a single document. |
108 | * |
109 | * @param string $id Document identifier |
110 | * @param ParamBag $params Search backend parameters |
111 | * |
112 | * @return RecordCollectionInterface |
113 | */ |
114 | public function retrieve($id, ParamBag $params = null) |
115 | { |
116 | $response = $this->connector->getRecord($id, $params); |
117 | $collection = $this->createRecordCollection($response); |
118 | $this->injectSourceIdentifier($collection); |
119 | return $collection; |
120 | } |
121 | |
122 | /** |
123 | * Return query builder. |
124 | * |
125 | * Lazy loads an empty QueryBuilder if none was set. |
126 | * |
127 | * @return QueryBuilder |
128 | */ |
129 | public function getQueryBuilder() |
130 | { |
131 | if (!$this->queryBuilder) { |
132 | $this->queryBuilder = new QueryBuilder(); |
133 | } |
134 | return $this->queryBuilder; |
135 | } |
136 | |
137 | /** |
138 | * Set the query builder. |
139 | * |
140 | * @param QueryBuilder $queryBuilder Query builder |
141 | * |
142 | * @return void |
143 | */ |
144 | public function setQueryBuilder(QueryBuilder $queryBuilder) |
145 | { |
146 | $this->queryBuilder = $queryBuilder; |
147 | } |
148 | |
149 | /** |
150 | * Return the record collection factory. |
151 | * |
152 | * Lazy loads a generic collection factory. |
153 | * |
154 | * @return RecordCollectionFactoryInterface |
155 | */ |
156 | public function getRecordCollectionFactory() |
157 | { |
158 | return $this->collectionFactory; |
159 | } |
160 | |
161 | /** |
162 | * Return the EIT connector. |
163 | * |
164 | * @return Connector |
165 | */ |
166 | public function getConnector() |
167 | { |
168 | return $this->connector; |
169 | } |
170 | |
171 | /// Internal API |
172 | |
173 | /** |
174 | * Create record collection. |
175 | * |
176 | * @param array $records Records to process |
177 | * |
178 | * @return RecordCollectionInterface |
179 | */ |
180 | protected function createRecordCollection($records) |
181 | { |
182 | return $this->getRecordCollectionFactory()->factory($records); |
183 | } |
184 | } |