Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
41.18% |
7 / 17 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
Doi | |
41.18% |
7 / 17 |
|
60.00% |
3 / 5 |
21.03 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
__invoke | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
renderTemplate | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
checkContext | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
isActive | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * DOI view helper |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2018. |
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 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/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFind\View\Helper\Root; |
31 | |
32 | /** |
33 | * DOI view helper |
34 | * |
35 | * @category VuFind |
36 | * @package View_Helpers |
37 | * @author Demian Katz <demian.katz@villanova.edu> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org/wiki/development Wiki |
40 | */ |
41 | class Doi extends \Laminas\View\Helper\AbstractHelper |
42 | { |
43 | /** |
44 | * Context helper |
45 | * |
46 | * @var \VuFind\View\Helper\Root\Context |
47 | */ |
48 | protected $context; |
49 | |
50 | /** |
51 | * VuFind OpenURL configuration |
52 | * |
53 | * @var \Laminas\Config\Config |
54 | */ |
55 | protected $config; |
56 | |
57 | /** |
58 | * Current RecordDriver |
59 | * |
60 | * @var \VuFind\RecordDriver |
61 | */ |
62 | protected $recordDriver; |
63 | |
64 | /** |
65 | * OpenURL context ('results', 'record' or 'holdings') |
66 | * |
67 | * @var string |
68 | */ |
69 | protected $area; |
70 | |
71 | /** |
72 | * Constructor |
73 | * |
74 | * @param Context $context Context helper |
75 | * @param \Laminas\Config\Config $config VuFind OpenURL config |
76 | */ |
77 | public function __construct(Context $context, $config = null) |
78 | { |
79 | $this->context = $context; |
80 | $this->config = $config; |
81 | } |
82 | |
83 | /** |
84 | * Set up context for helper |
85 | * |
86 | * @param \VuFind\RecordDriver $driver The current record driver |
87 | * @param string $area DOI context ('results', 'record' |
88 | * or 'holdings' |
89 | * |
90 | * @return object |
91 | */ |
92 | public function __invoke($driver, $area) |
93 | { |
94 | $this->recordDriver = $driver; |
95 | $this->area = $area; |
96 | return $this; |
97 | } |
98 | |
99 | /** |
100 | * Public method to render the OpenURL template |
101 | * |
102 | * @param bool $imagebased Indicates if an image based link |
103 | * should be displayed or not (null for system default) |
104 | * |
105 | * @return string |
106 | */ |
107 | public function renderTemplate($imagebased = null) |
108 | { |
109 | // Build parameters needed to display the control: |
110 | $doi = $this->recordDriver->tryMethod('getCleanDOI'); |
111 | $params = compact('doi'); |
112 | |
113 | // Render the subtemplate: |
114 | return ($this->context)($this->getView()) |
115 | ->renderInContext('Helpers/doi.phtml', $params); |
116 | } |
117 | |
118 | /** |
119 | * Does the configuration indicate that we should display DOI links in |
120 | * the specified context? |
121 | * |
122 | * @return bool |
123 | */ |
124 | protected function checkContext() |
125 | { |
126 | // Doesn't matter the target area if no resolver is specified: |
127 | if (empty($this->config->resolver)) { |
128 | return false; |
129 | } |
130 | |
131 | // If a setting exists, return that: |
132 | $key = 'show_in_' . $this->area; |
133 | if (isset($this->config->$key)) { |
134 | return $this->config->$key; |
135 | } |
136 | |
137 | // If we got this far, use the defaults -- true for results, false for |
138 | // everywhere else. |
139 | return $this->area == 'results'; |
140 | } |
141 | |
142 | /** |
143 | * Public method to check whether OpenURLs are active for current record |
144 | * |
145 | * @return bool |
146 | */ |
147 | public function isActive() |
148 | { |
149 | $doi = $this->recordDriver->tryMethod('getCleanDOI'); |
150 | return !empty($doi) && $this->checkContext(); |
151 | } |
152 | } |