Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
VisualFacets | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
setConfig | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
init | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPivotFacetSet | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * VisualFacets Recommendations Module |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Julia Bauder 2014. |
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 Julia Bauder <bauderj@grinnell.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\Recommend; |
31 | |
32 | use function is_callable; |
33 | |
34 | /** |
35 | * VisualFacets Recommendations Module |
36 | * |
37 | * This class supports visualizing pivot facet information as a treemap or circle |
38 | * packing visualization. |
39 | * |
40 | * It must be used in combination with a template file including the necessary |
41 | * Javascript in order to display the visualization to the user. |
42 | * |
43 | * @category VuFind |
44 | * @package Recommendations |
45 | * @author Julia Bauder <bauderj@grinnell.edu> |
46 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
47 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
48 | */ |
49 | class VisualFacets extends AbstractFacets |
50 | { |
51 | /** |
52 | * Facet configuration |
53 | * |
54 | * @var string |
55 | */ |
56 | protected $facets; |
57 | |
58 | /** |
59 | * Store the configuration of the recommendation module. |
60 | * |
61 | * VisualFacets:[ini section]:[ini name] |
62 | * Display facets listed in the specified section of the specified ini file; |
63 | * if [ini name] is left out, it defaults to "facets." |
64 | * |
65 | * @param string $settings Settings from searches.ini. |
66 | * |
67 | * @return void |
68 | */ |
69 | public function setConfig($settings) |
70 | { |
71 | $settings = explode(':', $settings); |
72 | $mainSection = empty($settings[0]) ? 'Visual_Settings' : $settings[0]; |
73 | $iniName = $settings[1] ?? 'facets'; |
74 | |
75 | // Load the desired facet information: |
76 | $config = $this->configLoader->get($iniName); |
77 | $this->facets = $config->$mainSection->visual_facets |
78 | ?? 'callnumber-first,topic_facet'; |
79 | } |
80 | |
81 | /** |
82 | * Called before the Search Results object performs its main search |
83 | * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED). |
84 | * This method is responsible for setting search parameters needed by the |
85 | * recommendation module and for reading any existing search parameters that may |
86 | * be needed. |
87 | * |
88 | * @param \VuFind\Search\Base\Params $params Search parameter object |
89 | * @param \Laminas\Stdlib\Parameters $request Parameter object representing user |
90 | * request. |
91 | * |
92 | * @return void |
93 | */ |
94 | public function init($params, $request) |
95 | { |
96 | // Turn on pivot facets: |
97 | $params->setPivotFacets($this->facets); |
98 | } |
99 | |
100 | /** |
101 | * Get facet information taken from the search. |
102 | * |
103 | * @return array |
104 | */ |
105 | public function getPivotFacetSet() |
106 | { |
107 | // Avoid fatal error in case of unexpected results object (e.g. EmptySet): |
108 | return is_callable([$this->results, 'getPivotFacetList']) |
109 | ? $this->results->getPivotFacetList() : []; |
110 | } |
111 | } |