Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
RemoveFilters | |
0.00% |
0 / 9 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
setConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
init | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
process | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
hasFilters | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFilterlessUrl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getActiveFacetsCount | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * RemoveFilters Recommendations Module |
5 | * Recommends to remove filters |
6 | * |
7 | * PHP version 8 |
8 | * |
9 | * Copyright (C) Villanova University 2010. |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License version 2, |
13 | * as published by the Free Software Foundation. |
14 | * |
15 | * This program is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU General Public License for more details. |
19 | * |
20 | * You should have received a copy of the GNU General Public License |
21 | * along with this program; if not, write to the Free Software |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * |
24 | * @category VuFind |
25 | * @package Recommendations |
26 | * @author Oliver Goldschmidt <o.goldschmidt@tuhh.de> |
27 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
28 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
29 | */ |
30 | |
31 | namespace VuFind\Recommend; |
32 | |
33 | use function count; |
34 | |
35 | /** |
36 | * RemoveFilters Recommendations Module |
37 | * Recommends to remove filters |
38 | * |
39 | * This class recommends to remove filters from a query to extend the result. |
40 | * |
41 | * @category VuFind |
42 | * @package Recommendations |
43 | * @author Oliver Goldschmidt <o.goldschmidt@tuhh.de> |
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 | class RemoveFilters implements RecommendInterface |
48 | { |
49 | /** |
50 | * Search handler to try |
51 | * |
52 | * @var string |
53 | */ |
54 | protected $activeFacetsCount = 0; |
55 | |
56 | /** |
57 | * Search results object. |
58 | * |
59 | * @var \VuFind\Search\Base\Results |
60 | */ |
61 | protected $results; |
62 | |
63 | /** |
64 | * Store the configuration of the recommendation module. |
65 | * |
66 | * @param string $settings Settings from searches.ini. |
67 | * |
68 | * @return void |
69 | */ |
70 | public function setConfig($settings) |
71 | { |
72 | } |
73 | |
74 | /** |
75 | * Called before the Search Results object performs its main search |
76 | * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED). |
77 | * This method is responsible for setting search parameters needed by the |
78 | * recommendation module and for reading any existing search parameters that may |
79 | * be needed. |
80 | * |
81 | * @param \VuFind\Search\Base\Params $params Search parameter object |
82 | * @param \Laminas\Stdlib\Parameters $request Parameter object representing user |
83 | * request. |
84 | * |
85 | * @return void |
86 | */ |
87 | public function init($params, $request) |
88 | { |
89 | } |
90 | |
91 | /** |
92 | * Called after the Search Results object has performed its main search. This |
93 | * may be used to extract necessary information from the Search Results object |
94 | * or to perform completely unrelated processing. |
95 | * |
96 | * @param \VuFind\Search\Base\Results $results Search results object |
97 | * |
98 | * @return void |
99 | */ |
100 | public function process($results) |
101 | { |
102 | $filters = $results->getParams()->getFilterList(false); |
103 | foreach ($filters as $filter) { |
104 | $this->activeFacetsCount += count($filter); |
105 | } |
106 | $this->results = $results; |
107 | } |
108 | |
109 | /** |
110 | * Determines if filters are applied or not. |
111 | * |
112 | * @return bool |
113 | */ |
114 | public function hasFilters() |
115 | { |
116 | return $this->activeFacetsCount > 0; |
117 | } |
118 | |
119 | /** |
120 | * Get the URL for this query without filters. |
121 | * |
122 | * @return string |
123 | */ |
124 | public function getFilterlessUrl() |
125 | { |
126 | return $this->results->getUrlQuery()->removeAllFilters()->getParams(); |
127 | } |
128 | |
129 | /** |
130 | * Get the new search handler, or false if it does not apply. |
131 | * |
132 | * @return string |
133 | */ |
134 | public function getActiveFacetsCount() |
135 | { |
136 | return $this->activeFacetsCount; |
137 | } |
138 | } |