Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
Options | |
0.00% |
0 / 26 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
getSearchAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRecommendationSettings | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getTabConfig | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
supportsCart | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | /** |
4 | * Combined search model. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
9 | * Copyright (C) The National Library of Finland 2024. |
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 Search_Base |
26 | * @author Demian Katz <demian.katz@villanova.edu> |
27 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
28 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
29 | * @link https://vufind.org Main Page |
30 | */ |
31 | |
32 | namespace VuFind\Search\Combined; |
33 | |
34 | /** |
35 | * Combined search model. |
36 | * |
37 | * @category VuFind |
38 | * @package Search_Base |
39 | * @author Demian Katz <demian.katz@villanova.edu> |
40 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org Main Page |
43 | */ |
44 | class Options extends \VuFind\Search\Base\Options |
45 | { |
46 | /** |
47 | * Options plugin manager |
48 | * |
49 | * @var \VuFind\Search\Options\PluginManager |
50 | */ |
51 | protected $optionsManager; |
52 | |
53 | /** |
54 | * Constructor |
55 | * |
56 | * @param \VuFind\Config\PluginManager $configLoader Config loader |
57 | * @param \VuFind\Search\Options\PluginManager $optionsManager Options plugin manager |
58 | */ |
59 | public function __construct( |
60 | \VuFind\Config\PluginManager $configLoader, |
61 | \VuFind\Search\Options\PluginManager $optionsManager |
62 | ) { |
63 | parent::__construct($configLoader); |
64 | $this->optionsManager = $optionsManager; |
65 | $searchSettings = $this->configLoader->get('combined'); |
66 | if (isset($searchSettings->Basic_Searches)) { |
67 | foreach ($searchSettings->Basic_Searches as $key => $value) { |
68 | $this->basicHandlers[$key] = $value; |
69 | } |
70 | } |
71 | } |
72 | |
73 | /** |
74 | * Return the route name for the search results action. |
75 | * |
76 | * @return string |
77 | */ |
78 | public function getSearchAction() |
79 | { |
80 | return 'combined-results'; |
81 | } |
82 | |
83 | /** |
84 | * Load all recommendation settings from the relevant ini file. Returns an |
85 | * associative array where the key is the location of the recommendations (top |
86 | * or side) and the value is the settings found in the file (which may be either |
87 | * a single string or an array of strings). |
88 | * |
89 | * @param string $handler Name of handler for which to load specific settings. |
90 | * |
91 | * @return array associative: location (top/side/etc.) => search settings |
92 | */ |
93 | public function getRecommendationSettings($handler = null) |
94 | { |
95 | $recommend = []; |
96 | $config = $this->configLoader->get('combined'); |
97 | foreach (['top', 'bottom'] as $location) { |
98 | if (isset($config->RecommendationModules->$location)) { |
99 | $recommend[$location] |
100 | = $config->RecommendationModules->$location->toArray(); |
101 | } |
102 | } |
103 | return $recommend; |
104 | } |
105 | |
106 | /** |
107 | * Get tab configuration based on the full combined results configuration. |
108 | * |
109 | * @return array |
110 | */ |
111 | public function getTabConfig() |
112 | { |
113 | $config = $this->configLoader->get('combined')->toArray(); |
114 | |
115 | // Strip out non-tab sections of the configuration: |
116 | unset($config['Basic_Searches']); |
117 | unset($config['HomePage']); |
118 | unset($config['Layout']); |
119 | unset($config['RecommendationModules']); |
120 | |
121 | return $config; |
122 | } |
123 | |
124 | /** |
125 | * Does this search option support the cart/book bag? |
126 | * |
127 | * @return bool |
128 | */ |
129 | public function supportsCart() |
130 | { |
131 | // Cart is supported if any of the tabs support cart: |
132 | foreach ($this->getTabConfig() as $current => $settings) { |
133 | [$searchClassId] = explode(':', $current); |
134 | $currentOptions = $this->optionsManager->get($searchClassId); |
135 | if ($currentOptions->supportsCart()) { |
136 | return true; |
137 | } |
138 | } |
139 | return false; |
140 | } |
141 | } |