Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ExplainElement | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
__invoke | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | /** |
4 | * Explain element view helper |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Hebis Verbundzentrale 2023. |
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 Dennis Schrittenlocher <Dennis.Schrittenlocher@outlook.de> |
26 | * @author Thomas Wagener <wagener@hebis.uni-frankfurt.de> |
27 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
28 | * @link https://vufind.org/wiki/development Wiki |
29 | */ |
30 | |
31 | namespace VuFind\View\Helper\Root; |
32 | |
33 | use function count; |
34 | |
35 | /** |
36 | * Explain element view helper |
37 | * |
38 | * @category VuFind |
39 | * @package View_Helpers |
40 | * @author Dennis Schrittenlocher <Dennis.Schrittenlocher@outlook.de> |
41 | * @author Thomas Wagener <wagener@hebis.uni-frankfurt.de> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org/wiki/development Wiki |
44 | */ |
45 | class ExplainElement extends \Laminas\View\Helper\AbstractHelper |
46 | { |
47 | /** |
48 | * Render the explain element. |
49 | * |
50 | * @param array $explainElement Explain element |
51 | * @param int $decimalPlaces Decimal places |
52 | * |
53 | * @return array |
54 | */ |
55 | public function __invoke($explainElement, $decimalPlaces) |
56 | { |
57 | $view = $this->getView(); |
58 | $fieldName = $explainElement['fieldName'] ?? []; |
59 | $fieldValue = $explainElement['fieldValue'] ?? []; |
60 | $fieldModifier = $explainElement['fieldModifier'] ?? []; |
61 | |
62 | $shortLabel = ''; |
63 | if (count($fieldName) > 1) { |
64 | $shortLabel .= $view->translate('Synonym') . '['; |
65 | } |
66 | $shortLabel .= implode( |
67 | ', ', |
68 | array_map(function ($name, $value) { |
69 | return $name . '(' . $value . ')'; |
70 | }, $fieldName, $fieldValue) |
71 | ); |
72 | if (count($fieldName) > 1) { |
73 | $shortLabel .= ']'; |
74 | } |
75 | |
76 | if ($fieldModifier) { |
77 | $shortLabel .= '^' . $view->localizedNumber($fieldModifier, $decimalPlaces); |
78 | } |
79 | |
80 | $shortValue = $explainElement['value']; |
81 | $completeLine = $view->render('RecordDriver/DefaultRecord/explain-line.phtml', [ |
82 | 'explainElement' => $explainElement, |
83 | 'fieldName' => $fieldName, |
84 | 'fieldValue' => $fieldValue, |
85 | 'fieldModifier' => $fieldModifier, |
86 | 'decimalPlaces' => $decimalPlaces, |
87 | ]); |
88 | return [ |
89 | 'shortLabel' => $shortLabel, |
90 | 'shortValue' => $shortValue, |
91 | 'completeLine' => $completeLine, |
92 | ]; |
93 | } |
94 | } |