Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
84.62% |
11 / 13 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
AbstractFacets | |
84.62% |
11 / 13 |
|
83.33% |
5 / 6 |
11.44 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
process | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
excludeAllowed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFacetOperator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
getResults | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
loadBooleanConfigs | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
5.39 |
1 | <?php |
2 | |
3 | /** |
4 | * SideFacets Recommendations Module |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
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 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\Recommend; |
31 | |
32 | use Laminas\Config\Config; |
33 | |
34 | use function in_array; |
35 | |
36 | /** |
37 | * SideFacets Recommendations Module |
38 | * |
39 | * This class provides recommendations displaying facets beside search results |
40 | * |
41 | * @category VuFind |
42 | * @package Recommendations |
43 | * @author Demian Katz <demian.katz@villanova.edu> |
44 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
45 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
46 | */ |
47 | abstract class AbstractFacets implements RecommendInterface |
48 | { |
49 | /** |
50 | * Facets with "exclude" links enabled |
51 | * |
52 | * @var array |
53 | */ |
54 | protected $excludableFacets = []; |
55 | |
56 | /** |
57 | * Facets that are "ORed" instead of "ANDed." |
58 | * |
59 | * @var array |
60 | */ |
61 | protected $orFacets = []; |
62 | |
63 | /** |
64 | * Search results |
65 | * |
66 | * @var \VuFind\Search\Base\Results |
67 | */ |
68 | protected $results; |
69 | |
70 | /** |
71 | * Configuration loader |
72 | * |
73 | * @var \VuFind\Config\PluginManager |
74 | */ |
75 | protected $configLoader; |
76 | |
77 | /** |
78 | * Constructor |
79 | * |
80 | * @param \VuFind\Config\PluginManager $configLoader Configuration loader |
81 | */ |
82 | public function __construct(\VuFind\Config\PluginManager $configLoader) |
83 | { |
84 | $this->configLoader = $configLoader; |
85 | } |
86 | |
87 | /** |
88 | * Called after the Search Results object has performed its main search. This |
89 | * may be used to extract necessary information from the Search Results object |
90 | * or to perform completely unrelated processing. |
91 | * |
92 | * @param \VuFind\Search\Base\Results $results Search results object |
93 | * |
94 | * @return void |
95 | */ |
96 | public function process($results) |
97 | { |
98 | $this->results = $results; |
99 | } |
100 | |
101 | /** |
102 | * Is the specified field allowed to be excluded? |
103 | * |
104 | * @param string $field Field name |
105 | * |
106 | * @return bool |
107 | */ |
108 | public function excludeAllowed($field) |
109 | { |
110 | return in_array($field, $this->excludableFacets); |
111 | } |
112 | |
113 | /** |
114 | * Get the facet boolean operator |
115 | * |
116 | * @param string $field Field name |
117 | * |
118 | * @return string 'AND' or 'OR' |
119 | */ |
120 | public function getFacetOperator($field) |
121 | { |
122 | return in_array($field, $this->orFacets) ? 'OR' : 'AND'; |
123 | } |
124 | |
125 | /** |
126 | * Get results stored in the object. |
127 | * |
128 | * @return \VuFind\Search\Base\Results |
129 | */ |
130 | public function getResults() |
131 | { |
132 | return $this->results; |
133 | } |
134 | |
135 | /** |
136 | * Read boolean (OR/NOT) settings from the provided configuration |
137 | * |
138 | * @param Config $config Configuration to read |
139 | * @param array $allFacets All facets (to use when config = *) |
140 | * @param string $section Configuration section containing settings |
141 | * |
142 | * @return void |
143 | */ |
144 | protected function loadBooleanConfigs( |
145 | Config $config, |
146 | $allFacets, |
147 | $section = 'Results_Settings' |
148 | ) { |
149 | // Which facets are excludable? |
150 | if (isset($config->$section->exclude)) { |
151 | $this->excludableFacets = ($config->$section->exclude === '*') |
152 | ? $allFacets |
153 | : array_map('trim', explode(',', $config->$section->exclude)); |
154 | } |
155 | |
156 | // Which facets are ORed? |
157 | if (isset($config->$section->orFacets)) { |
158 | $this->orFacets = ($config->$section->orFacets === '*') |
159 | ? $allFacets |
160 | : array_map('trim', explode(',', $config->$section->orFacets)); |
161 | } |
162 | } |
163 | } |