Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
24 / 24 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
AlphabeticBrowseCommand | |
100.00% |
24 / 24 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
getArguments | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
getSource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFrom | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLimit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOffsetDelta | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Fetch alphabrowse data from the backend (currently only supported by Solr) |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2021. |
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 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 |
28 | */ |
29 | |
30 | namespace VuFindSearch\Command; |
31 | |
32 | use VuFindSearch\Backend\Solr\Backend; |
33 | use VuFindSearch\ParamBag; |
34 | |
35 | /** |
36 | * Fetch alphabrowse data from the backend (currently only supported by Solr) |
37 | * |
38 | * @category VuFind |
39 | * @package Search |
40 | * @author Demian Katz <demian.katz@villanova.edu> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org |
43 | */ |
44 | class AlphabeticBrowseCommand extends CallMethodCommand |
45 | { |
46 | /** |
47 | * Name of index to search. |
48 | * |
49 | * @var string |
50 | */ |
51 | protected $source; |
52 | |
53 | /** |
54 | * Starting point for browse results. |
55 | * |
56 | * @var string |
57 | */ |
58 | protected $from; |
59 | |
60 | /** |
61 | * Result page to return. |
62 | * |
63 | * @var int |
64 | */ |
65 | protected $page; |
66 | |
67 | /** |
68 | * Number of results to return on each page. |
69 | * |
70 | * @var int |
71 | */ |
72 | protected $limit; |
73 | |
74 | /** |
75 | * Delta to use when calculating page offset. |
76 | * |
77 | * @var int |
78 | */ |
79 | protected $offsetDelta; |
80 | |
81 | /** |
82 | * Constructor. |
83 | * |
84 | * @param string $backendId Search backend identifier |
85 | * @param string $source Name of index to search |
86 | * @param string $from Starting point for browse results |
87 | * @param int $page Result page to return (starts at 0) |
88 | * @param int $limit Number of results to return on each page |
89 | * @param ?ParamBag $params Additional parameters |
90 | * @param int $offsetDelta Delta to use when calculating page |
91 | * offset (useful for showing a few results above the highlighted row) |
92 | */ |
93 | public function __construct( |
94 | string $backendId, |
95 | string $source, |
96 | string $from, |
97 | int $page, |
98 | int $limit = 20, |
99 | ParamBag $params = null, |
100 | int $offsetDelta = 0 |
101 | ) { |
102 | $this->source = $source; |
103 | $this->from = $from; |
104 | $this->page = $page; |
105 | $this->limit = $limit; |
106 | $this->offsetDelta = $offsetDelta; |
107 | parent::__construct( |
108 | $backendId, |
109 | Backend::class, // we should define interface, if needed in more places |
110 | 'alphabeticBrowse', |
111 | $params |
112 | ); |
113 | } |
114 | |
115 | /** |
116 | * Return search backend interface method arguments. |
117 | * |
118 | * @return array |
119 | */ |
120 | public function getArguments(): array |
121 | { |
122 | return [ |
123 | $this->getSource(), |
124 | $this->getFrom(), |
125 | $this->getPage(), |
126 | $this->getLimit(), |
127 | $this->getSearchParameters(), |
128 | $this->getOffsetDelta(), |
129 | ]; |
130 | } |
131 | |
132 | /** |
133 | * Return name of index to search. |
134 | * |
135 | * @return string |
136 | */ |
137 | public function getSource(): string |
138 | { |
139 | return $this->source; |
140 | } |
141 | |
142 | /** |
143 | * Return starting point for browse results. |
144 | * |
145 | * @return string |
146 | */ |
147 | public function getFrom(): string |
148 | { |
149 | return $this->from; |
150 | } |
151 | |
152 | /** |
153 | * Return result page to return. |
154 | * |
155 | * @return int |
156 | */ |
157 | public function getPage(): int |
158 | { |
159 | return $this->page; |
160 | } |
161 | |
162 | /** |
163 | * Return number of results to return on each page. |
164 | * |
165 | * @return int |
166 | */ |
167 | public function getLimit(): int |
168 | { |
169 | return $this->limit; |
170 | } |
171 | |
172 | /** |
173 | * Return delta to use when calculating page offset. |
174 | * |
175 | * @return int |
176 | */ |
177 | public function getOffsetDelta(): int |
178 | { |
179 | return $this->offsetDelta; |
180 | } |
181 | } |