Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
ExpandFacets | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
9 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setConfig | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
init | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
process | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getExpandedSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getEmptyResults | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * ExpandFacets Module Controller |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2011. |
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 Recommendations |
25 | * @author Mark Triggs <vufind-tech@lists.sourceforge.net> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Page |
28 | */ |
29 | |
30 | namespace VuFind\Recommend; |
31 | |
32 | /** |
33 | * Recommendation class to expand recommendation interfaces |
34 | * |
35 | * @category VuFind |
36 | * @package Recommendations |
37 | * @author Chris Hallberg <challber@villanova.edu> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org Main Page |
40 | */ |
41 | class ExpandFacets implements RecommendInterface |
42 | { |
43 | /** |
44 | * Facets to display |
45 | * |
46 | * @var array |
47 | */ |
48 | protected $facets; |
49 | |
50 | /** |
51 | * Settings from configuration |
52 | * |
53 | * @var string |
54 | */ |
55 | protected $settings; |
56 | |
57 | /** |
58 | * Search results |
59 | * |
60 | * @var \VuFind\Search\Base\Results |
61 | */ |
62 | protected $searchObject; |
63 | |
64 | /** |
65 | * Configuration loader |
66 | * |
67 | * @var \VuFind\Config\PluginManager |
68 | */ |
69 | protected $configLoader; |
70 | |
71 | /** |
72 | * Empty result set (used by the template as the basis for URL generation) |
73 | * |
74 | * @var \VuFind\Search\Solr\Results |
75 | */ |
76 | protected $emptyResults; |
77 | |
78 | /** |
79 | * Constructor |
80 | * |
81 | * @param \VuFind\Config\PluginManager $configLoader Configuration loader |
82 | * @param \VuFind\Search\Solr\Results $emptyResults Empty result set (used |
83 | * by the template as the basis for URL generation) |
84 | */ |
85 | public function __construct( |
86 | \VuFind\Config\PluginManager $configLoader, |
87 | \VuFind\Search\Solr\Results $emptyResults |
88 | ) { |
89 | $this->configLoader = $configLoader; |
90 | $this->emptyResults = $emptyResults; |
91 | } |
92 | |
93 | /** |
94 | * Store the configuration of the recommendation module. |
95 | * |
96 | * @param string $settings Settings from searches.ini. |
97 | * |
98 | * @return void |
99 | */ |
100 | public function setConfig($settings) |
101 | { |
102 | // Save the basic parameters: |
103 | $this->settings = $settings; |
104 | |
105 | // Parse the additional settings: |
106 | $settings = explode(':', $settings); |
107 | $mainSection = empty($settings[0]) ? 'Results' : $settings[0]; |
108 | $iniName = $settings[1] ?? 'facets'; |
109 | |
110 | // Load the desired facet information... |
111 | $config = $this->configLoader->get($iniName); |
112 | |
113 | // All standard facets to display: |
114 | $this->facets = isset($config->$mainSection) ? |
115 | $config->$mainSection->toArray() : []; |
116 | } |
117 | |
118 | /** |
119 | * Called before the Search Results object performs its main search |
120 | * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED). |
121 | * This method is responsible for setting search parameters needed by the |
122 | * recommendation module and for reading any existing search parameters that may |
123 | * be needed. |
124 | * |
125 | * @param \VuFind\Search\Base\Params $params Search parameter object |
126 | * @param \Laminas\Stdlib\Parameters $request Parameter object representing user |
127 | * request. |
128 | * |
129 | * @return void |
130 | */ |
131 | public function init($params, $request) |
132 | { |
133 | // Turn on side facets in the search results: |
134 | foreach ($this->facets as $name => $desc) { |
135 | $params->addFacet($name, $desc); |
136 | } |
137 | } |
138 | |
139 | /** |
140 | * Called after the Search Results object has performed its main search. This |
141 | * may be used to extract necessary information from the Search Results object |
142 | * or to perform completely unrelated processing. |
143 | * |
144 | * @param \VuFind\Search\Base\Results $results Search results object |
145 | * |
146 | * @return void |
147 | */ |
148 | public function process($results) |
149 | { |
150 | $this->searchObject = $results; |
151 | } |
152 | |
153 | /** |
154 | * Get the facet data |
155 | * |
156 | * @return array |
157 | */ |
158 | public function getExpandedSet() |
159 | { |
160 | return $this->searchObject->getFacetList($this->facets); |
161 | } |
162 | |
163 | /** |
164 | * Get an empty search object (the template uses this as the basis for URL |
165 | * generation). |
166 | * |
167 | * @return \VuFind\Search\Base\Results |
168 | */ |
169 | public function getEmptyResults() |
170 | { |
171 | return $this->emptyResults; |
172 | } |
173 | } |