Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
AbstractBase | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
setRecordDriver | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getRecordDriver | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getDataSource | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
getTreeList | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
render | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
getHierarchyName | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Hierarchy Tree Renderer |
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 HierarchyTree_Renderer |
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\TreeRenderer; |
31 | |
32 | use function is_object; |
33 | |
34 | /** |
35 | * Hierarchy Tree Renderer |
36 | * |
37 | * This is a base helper class for producing hierarchy Trees. |
38 | * |
39 | * @category VuFind |
40 | * @package HierarchyTree_Renderer |
41 | * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki |
44 | */ |
45 | abstract class AbstractBase |
46 | { |
47 | /** |
48 | * Hierarchical record to work on |
49 | * |
50 | * @var \VuFind\RecordDriver\AbstractBase |
51 | */ |
52 | protected $recordDriver = null; |
53 | |
54 | /** |
55 | * Source of hierarchy data |
56 | * |
57 | * @var \VuFind\Hierarchy\TreeDataSource\AbstractBase |
58 | */ |
59 | protected $dataSource = null; |
60 | |
61 | /** |
62 | * Set the record driver to operate on |
63 | * |
64 | * @param \VuFind\RecordDriver\AbstractBase $driver Record driver |
65 | * |
66 | * @return AbstractBase |
67 | */ |
68 | public function setRecordDriver(\VuFind\RecordDriver\AbstractBase $driver) |
69 | { |
70 | $this->recordDriver = $driver; |
71 | return $this; |
72 | } |
73 | |
74 | /** |
75 | * Get the current record driver |
76 | * |
77 | * @return \VuFind\RecordDriver\DefaultRecord |
78 | * @throws \Exception |
79 | */ |
80 | protected function getRecordDriver() |
81 | { |
82 | if (null === $this->recordDriver) { |
83 | throw new \Exception('Missing record driver object'); |
84 | } |
85 | return $this->recordDriver; |
86 | } |
87 | |
88 | /** |
89 | * Get the current hierarchy data source |
90 | * |
91 | * @return \VuFind\Hierarchy\TreeDataSource\AbstractBase |
92 | * @throws \Exception |
93 | */ |
94 | protected function getDataSource() |
95 | { |
96 | if (null === $this->dataSource) { |
97 | // Load the hierarchy driver from the record driver -- throw exception if |
98 | // this fails, since we shouldn't be using this class for drivers that do |
99 | // not support hierarchies! |
100 | $hierarchyDriver = $this->getRecordDriver() |
101 | ->tryMethod('getHierarchyDriver'); |
102 | if (!is_object($hierarchyDriver)) { |
103 | throw new \Exception( |
104 | 'Cannot load hierarchy driver from record driver.' |
105 | ); |
106 | } |
107 | $this->dataSource = $hierarchyDriver->getTreeSource(); |
108 | } |
109 | return $this->dataSource; |
110 | } |
111 | |
112 | /** |
113 | * Get a list of trees containing the item represented by the stored record |
114 | * driver. |
115 | * |
116 | * @param string $hierarchyID Optional filter: specific hierarchy ID to retrieve |
117 | * |
118 | * @return mixed An array of hierarchy IDS if a hierarchy tree exists, |
119 | * false if it does not |
120 | */ |
121 | abstract public function getTreeList($hierarchyID = false); |
122 | |
123 | /** |
124 | * Render the Hierarchy Tree |
125 | * |
126 | * @param string $context The context from which the call has been made |
127 | * @param string $mode The mode in which the tree should be generated |
128 | * @param string $hierarchyID The hierarchy ID of the tree to fetch (optional) |
129 | * @param ?string $selectedID The current record ID (optional) |
130 | * |
131 | * @return mixed The desired hierarchy tree output (or false on error) |
132 | */ |
133 | abstract public function render( |
134 | string $context, |
135 | string $mode, |
136 | string $hierarchyID, |
137 | ?string $selectedID = null |
138 | ); |
139 | |
140 | /** |
141 | * Get Hierarchy Name |
142 | * |
143 | * @param string $hierarchyID The hierarchy ID to find the title for |
144 | * @param array $inHierarchies An array of hierarchy IDs |
145 | * @param array $inHierarchiesTitle An array of hierarchy Titles |
146 | * |
147 | * @return string A hierarchy title |
148 | */ |
149 | public function getHierarchyName( |
150 | $hierarchyID, |
151 | $inHierarchies, |
152 | $inHierarchiesTitle |
153 | ) { |
154 | $keys = array_flip($inHierarchies); |
155 | $key = $keys[$hierarchyID]; |
156 | return $inHierarchiesTitle[$key]; |
157 | } |
158 | } |