Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.33% |
14 / 15 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
SwitchTab | |
93.33% |
14 / 15 |
|
83.33% |
5 / 6 |
10.03 | |
0.00% |
0 / 1 |
setConfig | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
init | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
process | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setTabSelections | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
getActiveTab | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getInactiveTabs | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * SwitchTab Recommendations Module |
5 | * Recommends to use another SearchTab |
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 | /** |
34 | * SwitchType Recommendations Module |
35 | * |
36 | * This class recommends switching to a different search type. |
37 | * |
38 | * @category VuFind |
39 | * @package Recommendations |
40 | * @author Oliver Goldschmidt <o.goldschmidt@tuhh.de> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
43 | */ |
44 | class SwitchTab implements RecommendInterface |
45 | { |
46 | /** |
47 | * Current tab settings |
48 | * |
49 | * @var array |
50 | */ |
51 | protected $tabSelections = null; |
52 | |
53 | /** |
54 | * Store the configuration of the recommendation module. |
55 | * |
56 | * @param string $settings Settings from searches.ini. |
57 | * |
58 | * @return void |
59 | */ |
60 | public function setConfig($settings) |
61 | { |
62 | } |
63 | |
64 | /** |
65 | * Called before the Search Results object performs its main search |
66 | * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED). |
67 | * This method is responsible for setting search parameters needed by the |
68 | * recommendation module and for reading any existing search parameters that may |
69 | * be needed. |
70 | * |
71 | * @param \VuFind\Search\Base\Params $params Search parameter object |
72 | * @param \Laminas\Stdlib\Parameters $request Parameter object representing user |
73 | * request. |
74 | * |
75 | * @return void |
76 | */ |
77 | public function init($params, $request) |
78 | { |
79 | } |
80 | |
81 | /** |
82 | * Called after the Search Results object has performed its main search. This |
83 | * may be used to extract necessary information from the Search Results object |
84 | * or to perform completely unrelated processing. |
85 | * |
86 | * @param \VuFind\Search\Base\Results $results Search results object |
87 | * |
88 | * @return void |
89 | */ |
90 | public function process($results) |
91 | { |
92 | } |
93 | |
94 | /** |
95 | * Set the tab state based on the current tabConfig. |
96 | * |
97 | * @param array $tabEnv tabConfig |
98 | * |
99 | * @return void |
100 | */ |
101 | protected function setTabSelections($tabEnv) |
102 | { |
103 | $tabs = [ 'active' => null, 'inactive' => [] ]; |
104 | foreach ($tabEnv as $tab) { |
105 | if ($tab['selected'] === true) { |
106 | $tabs['active'] = $tab; |
107 | } else { |
108 | $tabs['inactive'][] = $tab; |
109 | } |
110 | } |
111 | $this->tabSelections = $tabs; |
112 | } |
113 | |
114 | /** |
115 | * Get the active tab. |
116 | * |
117 | * @param array $tabEnv tabConfig |
118 | * |
119 | * @return array|null |
120 | */ |
121 | public function getActiveTab($tabEnv) |
122 | { |
123 | if ($this->tabSelections === null) { |
124 | $this->setTabSelections($tabEnv); |
125 | } |
126 | return $this->tabSelections['active']; |
127 | } |
128 | |
129 | /** |
130 | * Get the other (inactive) tabs. |
131 | * |
132 | * @param array $tabEnv tabConfig |
133 | * |
134 | * @return array |
135 | */ |
136 | public function getInactiveTabs($tabEnv) |
137 | { |
138 | if ($this->tabSelections === null) { |
139 | $this->setTabSelections($tabEnv); |
140 | } |
141 | return $this->tabSelections['inactive']; |
142 | } |
143 | } |