Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
SummaryTrait | |
0.00% |
0 / 29 |
|
0.00% |
0 / 3 |
132 | |
0.00% |
0 / 1 |
getFineSummary | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getRequestSummary | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
getTransactionSummary | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | /** |
4 | * Trait for getting a summary for checkouts, fines, holds, ILL requests or storage |
5 | * retrieval requests. |
6 | * |
7 | * PHP version 8 |
8 | * |
9 | * Copyright (C) Villanova University 2019. |
10 | * Copyright (C) The National Library of Finland 2023. |
11 | * |
12 | * This program is free software; you can redistribute it and/or modify |
13 | * it under the terms of the GNU General Public License version 2, |
14 | * as published by the Free Software Foundation. |
15 | * |
16 | * This program is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU General Public License for more details. |
20 | * |
21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | * |
25 | * @category VuFind |
26 | * @package ILS |
27 | * @author Demian Katz <demian.katz@villanova.edu> |
28 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
29 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
30 | * @link https://vufind.org/wiki/development Wiki |
31 | */ |
32 | |
33 | namespace VuFind\ILS\Logic; |
34 | |
35 | use VuFind\Service\CurrencyFormatter; |
36 | |
37 | /** |
38 | * Trait for getting a summary for checkouts, fines, holds, ILL requests or storage |
39 | * retrieval requests. |
40 | * |
41 | * @category VuFind |
42 | * @package ILS |
43 | * @author Demian Katz <demian.katz@villanova.edu> |
44 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
45 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
46 | * @link https://vufind.org/wiki/development Wiki |
47 | */ |
48 | trait SummaryTrait |
49 | { |
50 | /** |
51 | * Get a status summary for an array of fines |
52 | * |
53 | * @param iterable $fines Fines |
54 | * @param CurrencyFormatter $formatter Currency formatter |
55 | * |
56 | * @return array Associative array with keys total and display. |
57 | */ |
58 | protected function getFineSummary( |
59 | iterable $fines, |
60 | CurrencyFormatter $formatter |
61 | ): array { |
62 | $total = 0; |
63 | foreach ($fines as $fine) { |
64 | $total += $fine['balance']; |
65 | } |
66 | $display = $formatter->convertToDisplayFormat($total / 100); |
67 | return compact('total', 'display'); |
68 | } |
69 | |
70 | /** |
71 | * Get a status summary for an array of requests |
72 | * |
73 | * @param iterable $requests Requests |
74 | * |
75 | * @return array Associative array with keys available, in_transit and other. |
76 | */ |
77 | protected function getRequestSummary(iterable $requests): array |
78 | { |
79 | $available = 0; |
80 | $in_transit = 0; |
81 | $other = 0; |
82 | foreach ($requests as $request) { |
83 | if ($request['available'] ?? false) { |
84 | ++$available; |
85 | } elseif ($request['in_transit'] ?? false) { |
86 | ++$in_transit; |
87 | } else { |
88 | ++$other; |
89 | } |
90 | } |
91 | return compact('available', 'in_transit', 'other'); |
92 | } |
93 | |
94 | /** |
95 | * Get a status summary for an array of checkouts |
96 | * |
97 | * @param iterable $transactions Checkouts |
98 | * |
99 | * @return array Associative array with keys available, in_transit and other. |
100 | */ |
101 | protected function getTransactionSummary(iterable $transactions): array |
102 | { |
103 | $ok = 0; |
104 | $overdue = 0; |
105 | $warn = 0; |
106 | foreach ($transactions as $transaction) { |
107 | switch ($transaction['dueStatus'] ?? '') { |
108 | case 'due': |
109 | ++$warn; |
110 | break; |
111 | case 'overdue': |
112 | ++$overdue; |
113 | break; |
114 | default: |
115 | ++$ok; |
116 | break; |
117 | } |
118 | } |
119 | return compact('ok', 'overdue', 'warn'); |
120 | } |
121 | } |