Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
AbstractBase | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
showTree | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getTreeSource | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getTreeRenderer | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
render | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getTreeRendererType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getTreeSettings | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getTreeSourceType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
treeSorting | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getCollectionLinkType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getTreeCacheTime | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | /** |
4 | * Hierarchy interface. |
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 Hierarchy |
25 | * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Hierarchy\Driver; |
31 | |
32 | use VuFind\Hierarchy\TreeDataSource\PluginManager as DataManager; |
33 | use VuFind\Hierarchy\TreeRenderer\PluginManager as RendererManager; |
34 | |
35 | /** |
36 | * Hierarchy interface class. |
37 | * |
38 | * Interface Hierarchy based drivers. |
39 | * This should be extended to implement functionality for specific |
40 | * Hierarchy Systems (i.e. Calm etc.). |
41 | * |
42 | * @category VuFind |
43 | * @package Hierarchy |
44 | * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> |
45 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
46 | * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki |
47 | */ |
48 | abstract class AbstractBase |
49 | { |
50 | /** |
51 | * Driver configuration |
52 | * |
53 | * @var \Laminas\Config\Config |
54 | */ |
55 | protected $config; |
56 | |
57 | /** |
58 | * Tree data source plugin manager |
59 | * |
60 | * @var DataManager |
61 | */ |
62 | protected $dataManager; |
63 | |
64 | /** |
65 | * Are trees globally enabled? |
66 | * |
67 | * @var bool |
68 | */ |
69 | protected $enabled = true; |
70 | |
71 | /** |
72 | * Tree renderer plugin manager |
73 | * |
74 | * @var RendererManager |
75 | */ |
76 | protected $rendererManager; |
77 | |
78 | /** |
79 | * Find out whether or not to show the tree |
80 | * |
81 | * @return bool |
82 | */ |
83 | abstract public function showTree(); |
84 | |
85 | /** |
86 | * Constructor |
87 | * |
88 | * @param \Laminas\Config\Config $config Configuration |
89 | * @param DataManager $dataManager Tree data source plugin manager |
90 | * @param RendererManager $rendererManager Tree renderer plugin manager |
91 | * @param array $options Extra options (if any) |
92 | */ |
93 | public function __construct( |
94 | \Laminas\Config\Config $config, |
95 | DataManager $dataManager, |
96 | RendererManager $rendererManager, |
97 | $options = [] |
98 | ) { |
99 | $this->config = $config; |
100 | $this->dataManager = $dataManager; |
101 | $this->rendererManager = $rendererManager; |
102 | if (isset($options['enabled'])) { |
103 | $this->enabled = (bool)$options['enabled']; |
104 | } |
105 | } |
106 | |
107 | /** |
108 | * Returns the Source of the Tree |
109 | * |
110 | * @return object The tree data source object |
111 | */ |
112 | public function getTreeSource() |
113 | { |
114 | $source = $this->dataManager->get($this->getTreeSourceType()); |
115 | $source->setHierarchyDriver($this); |
116 | return $source; |
117 | } |
118 | |
119 | /** |
120 | * Returns the actual object for generating trees |
121 | * |
122 | * @param \VuFind\RecordDriver\AbstractBase $driver Record driver |
123 | * |
124 | * @return object |
125 | */ |
126 | public function getTreeRenderer(\VuFind\RecordDriver\AbstractBase $driver) |
127 | { |
128 | $renderer = $this->rendererManager->get($this->getTreeRendererType()); |
129 | $renderer->setRecordDriver($driver); |
130 | return $renderer; |
131 | } |
132 | |
133 | /** |
134 | * Render the tree for a given record. |
135 | * |
136 | * @param \VuFind\RecordDriver\AbstractBase $driver Record driver |
137 | * @param string $context Context in which the tree is being created |
138 | * @param string $mode Type of tree required |
139 | * @param string $hierarchyID Hierarchy ID to get the tree for |
140 | * @param array $options Additional options for the renderer |
141 | * |
142 | * @return string |
143 | */ |
144 | public function render( |
145 | \VuFind\RecordDriver\AbstractBase $driver, |
146 | string $context, |
147 | string $mode, |
148 | string $hierarchyID, |
149 | array $options |
150 | ) { |
151 | if (!$this->showTree()) { |
152 | return false; |
153 | } |
154 | return $this->getTreeRenderer($driver) |
155 | ->render($context, $mode, $hierarchyID, $driver->getUniqueID(), $options); |
156 | } |
157 | |
158 | /** |
159 | * Returns the Tree Renderer Type |
160 | * |
161 | * @return string |
162 | */ |
163 | abstract public function getTreeRendererType(); |
164 | |
165 | /** |
166 | * Get Tree Settings |
167 | * |
168 | * Returns all the configuration settings for a hierarchy tree |
169 | * |
170 | * @return array The values of the configuration setting |
171 | */ |
172 | abstract public function getTreeSettings(); |
173 | |
174 | /** |
175 | * Get Tree Data Source Type |
176 | * |
177 | * @return string |
178 | */ |
179 | abstract public function getTreeSourceType(); |
180 | |
181 | /** |
182 | * Check if sorting is enabled in the hierarchy Options |
183 | * |
184 | * @return bool |
185 | */ |
186 | abstract public function treeSorting(); |
187 | |
188 | /** |
189 | * Get Collection Link Type |
190 | * |
191 | * @return string |
192 | */ |
193 | abstract public function getCollectionLinkType(); |
194 | |
195 | /** |
196 | * Get tree cache time in seconds |
197 | * |
198 | * @return int |
199 | */ |
200 | abstract public function getTreeCacheTime(); |
201 | } |