Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
FacetList | |
0.00% |
0 / 31 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getHierarchicalFacets | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getHierarchicalFacetSortSettings | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
setConfig | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getContext | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * FacetList content block. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2018. |
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 ContentBlock |
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:plugins:recommendation_modules Wiki |
28 | */ |
29 | |
30 | namespace VuFind\ContentBlock; |
31 | |
32 | use Laminas\Config\Config; |
33 | use VuFind\Config\PluginManager as ConfigManager; |
34 | use VuFind\Search\FacetCache\PluginManager as FacetCacheManager; |
35 | |
36 | /** |
37 | * FacetList content block. |
38 | * |
39 | * @category VuFind |
40 | * @package ContentBlock |
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:plugins:recommendation_modules Wiki |
44 | */ |
45 | class FacetList implements ContentBlockInterface |
46 | { |
47 | /** |
48 | * Number of values to put in each column of results. |
49 | * |
50 | * @var int |
51 | */ |
52 | protected $columnSize = 10; |
53 | |
54 | /** |
55 | * Search class ID to use for retrieving facets. |
56 | * |
57 | * @var string |
58 | */ |
59 | protected $searchClassId = 'Solr'; |
60 | |
61 | /** |
62 | * Configuration manager |
63 | * |
64 | * @var ConfigManager |
65 | */ |
66 | protected $configManager; |
67 | |
68 | /** |
69 | * Facet cache plugin manager |
70 | * |
71 | * @var FacetCacheManager |
72 | */ |
73 | protected $facetCacheManager; |
74 | |
75 | /** |
76 | * Constructor |
77 | * |
78 | * @param FacetCacheManager $fcm Facet cache plugin manager |
79 | * @param ConfigManager $cm Configuration manager |
80 | */ |
81 | public function __construct(FacetCacheManager $fcm, ConfigManager $cm) |
82 | { |
83 | $this->facetCacheManager = $fcm; |
84 | $this->configManager = $cm; |
85 | } |
86 | |
87 | /** |
88 | * Get an array of hierarchical facets |
89 | * |
90 | * @param Config $facetConfig Facet configuration object. |
91 | * |
92 | * @return array Facets |
93 | */ |
94 | protected function getHierarchicalFacets($facetConfig) |
95 | { |
96 | return isset($facetConfig->SpecialFacets->hierarchical) |
97 | ? $facetConfig->SpecialFacets->hierarchical->toArray() |
98 | : []; |
99 | } |
100 | |
101 | /** |
102 | * Get hierarchical facet sort settings |
103 | * |
104 | * @param Config $facetConfig Facet configuration object. |
105 | * |
106 | * @return array Array of sort settings keyed by facet |
107 | */ |
108 | protected function getHierarchicalFacetSortSettings($facetConfig) |
109 | { |
110 | $baseConfig |
111 | = isset($facetConfig->SpecialFacets->hierarchicalFacetSortOptions) |
112 | ? $facetConfig->SpecialFacets->hierarchicalFacetSortOptions->toArray() |
113 | : []; |
114 | $homepageConfig |
115 | = isset($facetConfig->HomePage_Settings->hierarchicalFacetSortOptions) |
116 | ? $facetConfig->HomePage_Settings->hierarchicalFacetSortOptions |
117 | ->toArray() |
118 | : []; |
119 | |
120 | return array_merge($baseConfig, $homepageConfig); |
121 | } |
122 | |
123 | /** |
124 | * Store the configuration of the content block. |
125 | * |
126 | * @param string $settings Settings from searches.ini. |
127 | * |
128 | * @return void |
129 | */ |
130 | public function setConfig($settings) |
131 | { |
132 | $parts = explode(':', $settings); |
133 | $this->searchClassId = empty($parts[0]) ? $this->searchClassId : $parts[0]; |
134 | $this->columnSize = $parts[1] ?? $this->columnSize; |
135 | } |
136 | |
137 | /** |
138 | * Return context variables used for rendering the block's template. |
139 | * |
140 | * @return array |
141 | */ |
142 | public function getContext() |
143 | { |
144 | $facetCache = $this->facetCacheManager->get($this->searchClassId); |
145 | $results = $facetCache->getResults(); |
146 | $facetConfig = $this->configManager |
147 | ->get($results->getOptions()->getFacetsIni()); |
148 | return [ |
149 | 'searchClassId' => $this->searchClassId, |
150 | 'columnSize' => $this->columnSize, |
151 | 'facetList' => $facetCache->getList('HomePage'), |
152 | 'hierarchicalFacets' => $this->getHierarchicalFacets($facetConfig), |
153 | 'hierarchicalFacetSortOptions' => |
154 | $this->getHierarchicalFacetSortSettings($facetConfig), |
155 | 'results' => $results, |
156 | ]; |
157 | } |
158 | } |