/
AbstractBase.php
201 lines (183 loc) · 5.49 KB
/
AbstractBase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* Hierarchy interface.
*
* PHP version 8
*
* Copyright (C) Villanova University 2010.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Hierarchy
* @author Luke O'Sullivan <l.osullivan@swansea.ac.uk>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki
*/
namespace VuFind\Hierarchy\Driver;
use VuFind\Hierarchy\TreeDataSource\PluginManager as DataManager;
use VuFind\Hierarchy\TreeRenderer\PluginManager as RendererManager;
/**
* Hierarchy interface class.
*
* Interface Hierarchy based drivers.
* This should be extended to implement functionality for specific
* Hierarchy Systems (i.e. Calm etc.).
*
* @category VuFind
* @package Hierarchy
* @author Luke O'Sullivan <l.osullivan@swansea.ac.uk>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki
*/
abstract class AbstractBase
{
/**
* Driver configuration
*
* @var \Laminas\Config\Config
*/
protected $config;
/**
* Tree data source plugin manager
*
* @var DataManager
*/
protected $dataManager;
/**
* Are trees globally enabled?
*
* @var bool
*/
protected $enabled = true;
/**
* Tree renderer plugin manager
*
* @var RendererManager
*/
protected $rendererManager;
/**
* Find out whether or not to show the tree
*
* @return bool
*/
abstract public function showTree();
/**
* Constructor
*
* @param \Laminas\Config\Config $config Configuration
* @param DataManager $dataManager Tree data source plugin manager
* @param RendererManager $rendererManager Tree renderer plugin manager
* @param array $options Extra options (if any)
*/
public function __construct(
\Laminas\Config\Config $config,
DataManager $dataManager,
RendererManager $rendererManager,
$options = []
) {
$this->config = $config;
$this->dataManager = $dataManager;
$this->rendererManager = $rendererManager;
if (isset($options['enabled'])) {
$this->enabled = (bool)$options['enabled'];
}
}
/**
* Returns the Source of the Tree
*
* @return object The tree data source object
*/
public function getTreeSource()
{
$source = $this->dataManager->get($this->getTreeSourceType());
$source->setHierarchyDriver($this);
return $source;
}
/**
* Returns the actual object for generating trees
*
* @param \VuFind\RecordDriver\AbstractBase $driver Record driver
*
* @return object
*/
public function getTreeRenderer(\VuFind\RecordDriver\AbstractBase $driver)
{
$renderer = $this->rendererManager->get($this->getTreeRendererType());
$renderer->setRecordDriver($driver);
return $renderer;
}
/**
* Render the tree for a given record.
*
* @param \VuFind\RecordDriver\AbstractBase $driver Record driver
* @param string $context Context in which the tree is being created
* @param string $mode Type of tree required
* @param string $hierarchyID Hierarchy ID to get the tree for
* @param array $options Additional options for the renderer
*
* @return string
*/
public function render(
\VuFind\RecordDriver\AbstractBase $driver,
string $context,
string $mode,
string $hierarchyID,
array $options
) {
if (!$this->showTree()) {
return false;
}
return $this->getTreeRenderer($driver)
->render($context, $mode, $hierarchyID, $driver->getUniqueID(), $options);
}
/**
* Returns the Tree Renderer Type
*
* @return string
*/
abstract public function getTreeRendererType();
/**
* Get Tree Settings
*
* Returns all the configuration settings for a hierarchy tree
*
* @return array The values of the configuration setting
*/
abstract public function getTreeSettings();
/**
* Get Tree Data Source Type
*
* @return string
*/
abstract public function getTreeSourceType();
/**
* Check if sorting is enabled in the hierarchy Options
*
* @return bool
*/
abstract public function treeSorting();
/**
* Get Collection Link Type
*
* @return string
*/
abstract public function getCollectionLinkType();
/**
* Get tree cache time in seconds
*
* @return int
*/
abstract public function getTreeCacheTime();
}