Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
Related | |
0.00% |
0 / 25 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getConfigForSource | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
getList | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
render | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Related records view helper |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
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 | use VuFind\Config\PluginManager as ConfigManager; |
33 | use VuFind\Related\PluginManager as RelatedManager; |
34 | use VuFind\Search\Options\PluginManager as OptionsManager; |
35 | |
36 | /** |
37 | * Related records view helper |
38 | * |
39 | * @category VuFind |
40 | * @package View_Helpers |
41 | * @author Demian Katz <demian.katz@villanova.edu> |
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 Related extends \Laminas\View\Helper\AbstractHelper |
46 | { |
47 | use ClassBasedTemplateRendererTrait; |
48 | |
49 | /** |
50 | * Config manager |
51 | * |
52 | * @var ConfigManager |
53 | */ |
54 | protected $configManager; |
55 | |
56 | /** |
57 | * Plugin manager for search options. |
58 | * |
59 | * @var OptionsManager |
60 | */ |
61 | protected $optionsManager; |
62 | |
63 | /** |
64 | * Plugin manager for related record modules. |
65 | * |
66 | * @var RelatedManager |
67 | */ |
68 | protected $pluginManager; |
69 | |
70 | /** |
71 | * Constructor |
72 | * |
73 | * @param RelatedManager $pluginManager Plugin manager for related record modules |
74 | * @param ConfigManager $cm Configuration manager |
75 | * @param OptionsManager $om Search options manager |
76 | */ |
77 | public function __construct( |
78 | RelatedManager $pluginManager, |
79 | ConfigManager $cm, |
80 | OptionsManager $om |
81 | ) { |
82 | $this->pluginManager = $pluginManager; |
83 | $this->configManager = $cm; |
84 | $this->optionsManager = $om; |
85 | } |
86 | |
87 | /** |
88 | * Given a record source ID, return the appropriate related record configuration. |
89 | * |
90 | * @param string $source Source identifier |
91 | * |
92 | * @return array |
93 | */ |
94 | protected function getConfigForSource($source) |
95 | { |
96 | $options = $this->optionsManager->get($source); |
97 | $configName = $options->getSearchIni(); |
98 | // Special case -- default Solr stores [Record] section in config.ini |
99 | if ($configName === 'searches') { |
100 | $configName = 'config'; |
101 | } |
102 | $config = $this->configManager->get($configName); |
103 | return $config->Record->related ?? []; |
104 | } |
105 | |
106 | /** |
107 | * Get a list of related records modules. |
108 | * |
109 | * @param \VuFind\RecordDriver\AbstractBase $driver Record driver |
110 | * |
111 | * @return array |
112 | */ |
113 | public function getList(\VuFind\RecordDriver\AbstractBase $driver) |
114 | { |
115 | $retVal = []; |
116 | $config = $this->getConfigForSource($driver->getSearchBackendIdentifier()); |
117 | foreach ($config as $current) { |
118 | $parts = explode(':', $current, 2); |
119 | $type = $parts[0]; |
120 | $params = $parts[1] ?? null; |
121 | if ($this->pluginManager->has($type)) { |
122 | $plugin = $this->pluginManager->get($type); |
123 | $plugin->init($params, $driver); |
124 | $retVal[] = $plugin; |
125 | } else { |
126 | throw new \Exception("Related module {$type} does not exist."); |
127 | } |
128 | } |
129 | return $retVal; |
130 | } |
131 | |
132 | /** |
133 | * Render the output of a related records module. |
134 | * |
135 | * @param \VuFind\Related\RelatedInterface $related The related records object to |
136 | * render |
137 | * |
138 | * @return string |
139 | */ |
140 | public function render($related) |
141 | { |
142 | $template = 'Related/%s.phtml'; |
143 | $className = $related::class; |
144 | $context = ['related' => $related]; |
145 | return $this->renderClassTemplate($template, $className, $context); |
146 | } |
147 | } |