Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
AvailabilityStatus | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
getClass | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
renderStatusForAjaxResponse | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | /** |
4 | * Helper class for rendering availability statuses. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Hebis Verbundzentrale 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 Thomas Wagener <wagener@hebis.uni-frankfurt.de> |
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\View\Helper\Root; |
31 | |
32 | use VuFind\ILS\Logic\AvailabilityStatusInterface; |
33 | |
34 | /** |
35 | * Helper class for rendering availability statuses. |
36 | * |
37 | * @category VuFind |
38 | * @package View_Helpers |
39 | * @author Thomas Wagener <wagener@hebis.uni-frankfurt.de> |
40 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
41 | * @link https://vufind.org/wiki/development Wiki |
42 | */ |
43 | class AvailabilityStatus extends \Laminas\View\Helper\AbstractHelper |
44 | { |
45 | /** |
46 | * Html class for available items. |
47 | * |
48 | * @var string |
49 | */ |
50 | protected string $classAvailable = 'text-success'; |
51 | |
52 | /** |
53 | * Html class for unavailable items. |
54 | * |
55 | * @var string |
56 | */ |
57 | protected string $classUnavailable = 'text-danger'; |
58 | |
59 | /** |
60 | * Html class for items where status is uncertain. |
61 | * |
62 | * @var string |
63 | */ |
64 | protected string $classUncertain = 'text-warning'; |
65 | |
66 | /** |
67 | * Html class for items where status is unknown. |
68 | * |
69 | * @var string |
70 | */ |
71 | protected string $classUnknown = 'text-muted'; |
72 | |
73 | /** |
74 | * Message cache |
75 | * |
76 | * @var array |
77 | */ |
78 | protected array $messageCache = []; |
79 | |
80 | /** |
81 | * Get html class for availability status. |
82 | * |
83 | * @param AvailabilityStatusInterface $availabilityStatus Availability Status |
84 | * |
85 | * @return string |
86 | */ |
87 | public function getClass(AvailabilityStatusInterface $availabilityStatus): string |
88 | { |
89 | if ($availabilityStatus->is(\VuFind\ILS\Logic\AvailabilityStatusInterface::STATUS_UNAVAILABLE)) { |
90 | return $this->classUnavailable; |
91 | } |
92 | if ($availabilityStatus->is(\VuFind\ILS\Logic\AvailabilityStatusInterface::STATUS_AVAILABLE)) { |
93 | return $this->classAvailable; |
94 | } |
95 | if ($availabilityStatus->is(\VuFind\ILS\Logic\AvailabilityStatusInterface::STATUS_UNKNOWN)) { |
96 | return $this->classUnknown; |
97 | } |
98 | return $this->classUncertain; |
99 | } |
100 | |
101 | /** |
102 | * Render ajax status. |
103 | * |
104 | * @param AvailabilityStatusInterface $availabilityStatus Availability Status |
105 | * |
106 | * @return string |
107 | */ |
108 | public function renderStatusForAjaxResponse(AvailabilityStatusInterface $availabilityStatus): string |
109 | { |
110 | if ($availabilityStatus->is(\VuFind\ILS\Logic\AvailabilityStatusInterface::STATUS_UNKNOWN)) { |
111 | $key = 'ajax/status-unknown.phtml'; |
112 | } elseif ($availabilityStatus->is(\VuFind\ILS\Logic\AvailabilityStatusInterface::STATUS_AVAILABLE)) { |
113 | $key = 'ajax/status-available.phtml'; |
114 | } elseif ($availabilityStatus->is(\VuFind\ILS\Logic\AvailabilityStatusInterface::STATUS_UNAVAILABLE)) { |
115 | $key = 'ajax/status-unavailable.phtml'; |
116 | } else { |
117 | $key = 'ajax/status-uncertain.phtml'; |
118 | } |
119 | if (!isset($this->messageCache[$key])) { |
120 | $this->messageCache[$key] = $this->getView()->render($key); |
121 | } |
122 | return $this->messageCache[$key]; |
123 | } |
124 | } |