Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
ConfigurationBased | |
0.00% |
0 / 17 |
|
0.00% |
0 / 8 |
182 | |
0.00% |
0 / 1 |
showTree | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getTreeRendererType | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getTreeSourceType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTreeCacheTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
treeSorting | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTreeSettings | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getCollectionLinkType | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getCollectionField | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | /** |
4 | * Configuration-Based Hierarchy Driver |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2007. |
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_Drivers |
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 | /** |
33 | * Configuration-Based Hierarchy Driver |
34 | * |
35 | * @category VuFind |
36 | * @package Hierarchy_Drivers |
37 | * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki |
40 | */ |
41 | class ConfigurationBased extends AbstractBase |
42 | { |
43 | /** |
44 | * Default tree renderer |
45 | * |
46 | * @var string |
47 | */ |
48 | protected $defaultTreeRenderer = 'HTMLTree'; |
49 | |
50 | /** |
51 | * Show Tree |
52 | * |
53 | * Returns the configuration setting for displaying a hierarchy tree |
54 | * |
55 | * @return bool The boolean value of the configuration setting |
56 | */ |
57 | public function showTree() |
58 | { |
59 | $treeConfigDriver = $this->config->HierarchyTree->show ?? false; |
60 | return $this->enabled && $treeConfigDriver; |
61 | } |
62 | |
63 | /** |
64 | * Get Tree Renderer Type |
65 | * |
66 | * Returns the configuration setting for generating a hierarchy tree |
67 | * |
68 | * @return string The value of the configuration setting |
69 | */ |
70 | public function getTreeRendererType() |
71 | { |
72 | return $this->config->HierarchyTree->treeRenderer |
73 | ?? $this->defaultTreeRenderer; |
74 | } |
75 | |
76 | /** |
77 | * Get Tree Data Source Type |
78 | * |
79 | * @return string |
80 | */ |
81 | public function getTreeSourceType() |
82 | { |
83 | return $this->config->HierarchyTree->treeSource ?? 'Solr'; |
84 | } |
85 | |
86 | /** |
87 | * Get Tree Cache Time |
88 | * |
89 | * Returns the configuration setting for hierarchy tree caching time when |
90 | * using solr to build the tree |
91 | * |
92 | * @return int The value of the configuration setting |
93 | */ |
94 | public function getTreeCacheTime() |
95 | { |
96 | return $this->config->HierarchyTree->solrCacheTime ?? 43200; |
97 | } |
98 | |
99 | /** |
100 | * Check if sorting is enabled in the hierarchy Options |
101 | * |
102 | * Returns the configuration setting for hierarchy tree sorting |
103 | * |
104 | * @return bool The value of the configuration setting |
105 | */ |
106 | public function treeSorting() |
107 | { |
108 | return $this->config->HierarchyTree->sorting ?? false; |
109 | } |
110 | |
111 | /** |
112 | * Get Tree Settings |
113 | * |
114 | * Returns all the configuration settings for a hierarchy tree |
115 | * |
116 | * @return array The values of the configuration setting |
117 | */ |
118 | public function getTreeSettings() |
119 | { |
120 | return isset($this->config->HierarchyTree) |
121 | ? $this->config->HierarchyTree->toArray() : []; |
122 | } |
123 | |
124 | /** |
125 | * Get Collection Link Type from the config file |
126 | * |
127 | * @return string |
128 | */ |
129 | public function getCollectionLinkType() |
130 | { |
131 | return isset($this->config->Collections->link_type) |
132 | ? ucwords(strtolower($this->config->Collections->link_type)) : 'All'; |
133 | } |
134 | |
135 | /** |
136 | * Get the Solr field name used for grouping together collection contents |
137 | * |
138 | * @param bool $hasSearch Is the user performing a search? |
139 | * |
140 | * @return string |
141 | */ |
142 | public function getCollectionField(bool $hasSearch): string |
143 | { |
144 | if ($hasSearch && null !== ($field = $this->config->Collections->search_container_id_field ?? null)) { |
145 | return $field; |
146 | } |
147 | return match ($this->getCollectionLinkType()) { |
148 | 'All' => 'hierarchy_parent_id', |
149 | 'Top' => 'hierarchy_top_id', |
150 | }; |
151 | } |
152 | } |