Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 131 |
|
0.00% |
0 / 23 |
CRAP | |
0.00% |
0 / 1 |
AccountMenu | |
0.00% |
0 / 131 |
|
0.00% |
0 / 23 |
930 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getItems | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
getDefaultItems | |
0.00% |
0 / 90 |
|
0.00% |
0 / 1 |
2 | |||
checkFavorites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkCheckedout | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkHistoricloans | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkHolds | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkStorageRetrievalRequests | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkILLRequests | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkFines | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkLibraryCards | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
12 | |||
checkOverdrive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkHistory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkLogout | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkIlsCapability | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
checkIlsFunction | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
isIlsOnline | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCapabilityParams | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
12 | |||
finesIcon | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getAuthHelper | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIlsConnection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
render | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
getUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Account menu view helper |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Moravian library 2024. |
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 View_Helpers |
25 | * @author Josef Moravec <josef.moravec@mzk.cz> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Site |
28 | */ |
29 | |
30 | namespace VuFind\View\Helper\Root; |
31 | |
32 | use VuFind\Db\Entity\UserEntityInterface; |
33 | use VuFind\ILS\Connection as IlsConnection; |
34 | |
35 | /** |
36 | * Account menu view helper |
37 | * |
38 | * @category VuFind |
39 | * @package View_Helpers |
40 | * @author Josef Moravec <josef.moravec@mzk.cz> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org Main Site |
43 | */ |
44 | class AccountMenu extends \Laminas\View\Helper\AbstractHelper |
45 | { |
46 | /** |
47 | * Constructor |
48 | * |
49 | * @param array $config AccountMenu configuration |
50 | */ |
51 | public function __construct(protected array $config) |
52 | { |
53 | } |
54 | |
55 | /** |
56 | * Get available menu items |
57 | * |
58 | * @return array |
59 | */ |
60 | public function getItems(): array |
61 | { |
62 | return array_filter( |
63 | $this->config['MenuItems'] ?? $this->getDefaultItems(), |
64 | function ($item) { |
65 | return !isset($item['checkMethod']) || $this->{$item['checkMethod']}(); |
66 | } |
67 | ); |
68 | } |
69 | |
70 | /** |
71 | * Get default menu items |
72 | * |
73 | * @return array |
74 | */ |
75 | protected function getDefaultItems(): array |
76 | { |
77 | return [ |
78 | [ |
79 | 'name' => 'favorites', |
80 | 'label' => 'saved_items', |
81 | 'route' => 'myresearch-favorites', |
82 | 'icon' => 'user-favorites', |
83 | 'checkMethod' => 'checkFavorites', |
84 | ], |
85 | [ |
86 | 'name' => 'checkedout', |
87 | 'label' => 'Checked Out Items', |
88 | 'route' => 'myresearch-checkedout', |
89 | 'icon' => 'user-checked-out', |
90 | 'status' => true, |
91 | 'checkMethod' => 'checkCheckedout', |
92 | ], |
93 | [ |
94 | 'name' => 'historicloans', |
95 | 'label' => 'Loan History', |
96 | 'route' => 'checkouts-history', |
97 | 'icon' => 'user-loan-history', |
98 | 'checkMethod' => 'checkHistoricloans', |
99 | ], |
100 | [ |
101 | 'name' => 'holds', |
102 | 'label' => 'Holds and Recalls', |
103 | 'route' => 'holds-list', |
104 | 'icon' => 'user-holds', |
105 | 'status' => true, |
106 | 'checkMethod' => 'checkHolds', |
107 | ], |
108 | [ |
109 | 'name' => 'storageRetrievalRequests', |
110 | 'label' => 'Storage Retrieval Requests', |
111 | 'route' => 'myresearch-storageretrievalrequests', |
112 | 'icon' => 'user-storage-retrievals', |
113 | 'status' => true, |
114 | 'checkMethod' => 'checkStorageRetrievalRequests', |
115 | ], |
116 | [ |
117 | 'name' => 'ILLRequests', |
118 | 'label' => 'Interlibrary Loan Requests', |
119 | 'route' => 'myresearch-illrequests', |
120 | 'icon' => 'user-ill-requests', |
121 | 'status' => true, |
122 | 'checkMethod' => 'checkILLRequests', |
123 | ], |
124 | [ |
125 | 'name' => 'fines', |
126 | 'label' => 'Fines', |
127 | 'route' => 'myresearch-fines', |
128 | 'status' => true, |
129 | 'checkMethod' => 'checkFines', |
130 | 'iconMethod' => 'finesIcon', |
131 | ], |
132 | [ |
133 | 'name' => 'profile', |
134 | 'label' => 'Profile', |
135 | 'route' => 'myresearch-profile', |
136 | 'icon' => 'profile', |
137 | ], |
138 | [ |
139 | 'name' => 'librarycards', |
140 | 'label' => 'Library Cards', |
141 | 'route' => 'librarycards-home', |
142 | 'icon' => 'barcode', |
143 | 'checkMethod' => 'checkLibraryCards', |
144 | ], |
145 | [ |
146 | 'name' => 'dgcontent', |
147 | 'label' => 'Overdrive Content', |
148 | 'route' => 'overdrive-mycontent', |
149 | 'icon' => 'overdrive', |
150 | 'checkMethod' => 'checkOverdrive', |
151 | ], |
152 | [ |
153 | 'name' => 'history', |
154 | 'label' => 'Search History', |
155 | 'route' => 'search-history', |
156 | 'icon' => 'search', |
157 | 'checkMethod' => 'checkHistory', |
158 | ], |
159 | [ |
160 | 'name' => 'logout', |
161 | 'label' => 'Log Out', |
162 | 'route' => 'myresearch-logout', |
163 | 'icon' => 'sign-out', |
164 | 'checkMethod' => 'checkLogout', |
165 | ], |
166 | ]; |
167 | } |
168 | |
169 | /** |
170 | * Check whether to show favorites item |
171 | * |
172 | * @return bool |
173 | */ |
174 | public function checkFavorites(): bool |
175 | { |
176 | return $this->getView()->plugin('userlist')->getMode() !== 'disabled'; |
177 | } |
178 | |
179 | /** |
180 | * Check whether to show checkedout item |
181 | * |
182 | * @return bool |
183 | */ |
184 | public function checkCheckedout(): bool |
185 | { |
186 | return $this->checkIlsCapability('getMyTransactions'); |
187 | } |
188 | |
189 | /** |
190 | * Check whether to show historicloans item |
191 | * |
192 | * @return bool |
193 | */ |
194 | public function checkHistoricloans(): bool |
195 | { |
196 | return $this->checkIlsFunction('getMyTransactionHistory'); |
197 | } |
198 | |
199 | /** |
200 | * Check whether to show holds item |
201 | * |
202 | * @return bool |
203 | */ |
204 | public function checkHolds(): bool |
205 | { |
206 | return $this->checkIlsCapability('getMyHolds'); |
207 | } |
208 | |
209 | /** |
210 | * Check whether to show storageRetrievalRequests item |
211 | * |
212 | * @return bool |
213 | */ |
214 | public function checkStorageRetrievalRequests(): bool |
215 | { |
216 | return $this->checkIlsFunction('StorageRetrievalRequests'); |
217 | } |
218 | |
219 | /** |
220 | * Check whether to show ILLRequests item |
221 | * |
222 | * @return bool |
223 | */ |
224 | public function checkILLRequests(): bool |
225 | { |
226 | return $this->checkIlsFunction('ILLRequests'); |
227 | } |
228 | |
229 | /** |
230 | * Check whether to show fines item |
231 | * |
232 | * @return bool |
233 | */ |
234 | public function checkFines(): bool |
235 | { |
236 | return $this->checkIlsCapability('getMyFines'); |
237 | } |
238 | |
239 | /** |
240 | * Check whether to show librarycards item |
241 | * |
242 | * @return bool |
243 | */ |
244 | public function checkLibraryCards(): bool |
245 | { |
246 | return $this->isIlsOnline() && $this->getUser() |
247 | && $this->getView()->plugin('accountCapabilities')()->libraryCardsEnabled(); |
248 | } |
249 | |
250 | /** |
251 | * Check whether to show overdrive item |
252 | * |
253 | * @return bool |
254 | */ |
255 | public function checkOverdrive(): bool |
256 | { |
257 | return $this->getView()->plugin('overdrive')->showMyContentLink(); |
258 | } |
259 | |
260 | /** |
261 | * Check whether to show searchhistory item |
262 | * |
263 | * @return bool |
264 | */ |
265 | public function checkHistory(): bool |
266 | { |
267 | return $this->getView()->plugin('accountCapabilities')()->getSavedSearchSetting() === 'enabled'; |
268 | } |
269 | |
270 | /** |
271 | * Check whether to show logout item |
272 | * |
273 | * @return bool |
274 | */ |
275 | public function checkLogout(): bool |
276 | { |
277 | return (bool)$this->getUser(); |
278 | } |
279 | |
280 | /** |
281 | * Check ILS connection capability |
282 | * |
283 | * @param string $capability Name of then ILS method to check |
284 | * |
285 | * @return bool |
286 | */ |
287 | protected function checkIlsCapability(string $capability): bool |
288 | { |
289 | return $this->isIlsOnline() |
290 | && $this->getIlsConnection()->checkCapability($capability, $this->getCapabilityParams()); |
291 | } |
292 | |
293 | /** |
294 | * Check ILS function capability |
295 | * |
296 | * @param string $function The name of the ILS function to check. |
297 | * |
298 | * @return bool |
299 | */ |
300 | protected function checkIlsFunction(string $function): bool |
301 | { |
302 | return $this->isIlsOnline() |
303 | && $this->getIlsConnection()->checkFunction($function, $this->getCapabilityParams()); |
304 | } |
305 | |
306 | /** |
307 | * Check whether the ILS connection is available |
308 | * |
309 | * @return bool |
310 | */ |
311 | protected function isIlsOnline(): bool |
312 | { |
313 | return 'ils-none' !== $this->getIlsConnection()->getOfflineMode(); |
314 | } |
315 | |
316 | /** |
317 | * Get params for checking ILS capability/function |
318 | * |
319 | * @return array |
320 | */ |
321 | protected function getCapabilityParams(): array |
322 | { |
323 | $patron = $this->getUser() ? $this->getAuthHelper()->getILSPatron() : false; |
324 | return $patron ? compact('patron') : []; |
325 | } |
326 | |
327 | /** |
328 | * Create icon name for fines item |
329 | * |
330 | * @return string |
331 | */ |
332 | public function finesIcon(): string |
333 | { |
334 | $icon = 'currency-' |
335 | . strtolower($this->getView()->plugin('config')->get('config')->Site->defaultCurrency ?? 'usd'); |
336 | return $icon; |
337 | } |
338 | |
339 | /** |
340 | * Get authentication view helper |
341 | * |
342 | * @return Auth |
343 | */ |
344 | protected function getAuthHelper(): Auth |
345 | { |
346 | return $this->getView()->plugin('auth'); |
347 | } |
348 | |
349 | /** |
350 | * Get ILS connection view helper |
351 | * |
352 | * @return IlsConnection |
353 | */ |
354 | protected function getIlsConnection(): IlsConnection |
355 | { |
356 | return $this->getView()->plugin('ils')(); |
357 | } |
358 | |
359 | /** |
360 | * Render account menu |
361 | * |
362 | * @param string $activeItem The name of current active item |
363 | * @param string $idPrefix Element ID prefix |
364 | * |
365 | * @return string |
366 | */ |
367 | public function render(string $activeItem, string $idPrefix = ''): string |
368 | { |
369 | $contextHelper = $this->getView()->plugin('context'); |
370 | return $contextHelper->renderInContext( |
371 | 'myresearch/menu.phtml', |
372 | [ |
373 | 'items' => $this->getItems(), |
374 | 'active' => $activeItem, |
375 | 'idPrefix' => $idPrefix, |
376 | ] |
377 | ); |
378 | } |
379 | |
380 | /** |
381 | * Get authenticated user |
382 | * |
383 | * @return ?UserEntityInterface Object if user is logged in, null otherwise. |
384 | */ |
385 | protected function getUser(): ?UserEntityInterface |
386 | { |
387 | return $this->getAuthHelper()->getUserObject(); |
388 | } |
389 | } |