/
Options.php
212 lines (196 loc) · 6.84 KB
/
Options.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* Summon Search Options
*
* PHP version 5
*
* Copyright (C) Villanova University 2011.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package Search_Summon
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://www.vufind.org Main Page
*/
namespace VuFind\Search\Summon;
/**
* Summon Search Options
*
* @category VuFind2
* @package Search_Summon
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://www.vufind.org Main Page
*/
class Options extends \VuFind\Search\Base\Options
{
/**
* Maximum number of results
*
* @var int
*/
protected $resultLimit = 400;
/**
* Maximum number of topic recommendations to show (false for none)
*
* @var int|bool
*/
protected $maxTopicRecommendations = false;
/**
* Constructor
*
* @param \VuFind\Config\PluginManager $configLoader Config loader
*/
public function __construct(\VuFind\Config\PluginManager $configLoader)
{
parent::__construct($configLoader);
$this->searchIni = $this->facetsIni = 'Summon';
// Load facet preferences:
$facetSettings = $configLoader->get($this->facetsIni);
if (isset($facetSettings->Advanced_Facet_Settings->translated_facets)
&& count($facetSettings->Advanced_Facet_Settings->translated_facets) > 0
) {
$list = $facetSettings->Advanced_Facet_Settings->translated_facets;
foreach ($list as $c) {
$this->translatedFacets[] = $c;
}
}
if (isset($facetSettings->Advanced_Facet_Settings->special_facets)) {
$this->specialAdvancedFacets
= $facetSettings->Advanced_Facet_Settings->special_facets;
}
// Load the search configuration file:
$searchSettings = $configLoader->get($this->searchIni);
// Set up limit preferences
if (isset($searchSettings->General->default_limit)) {
$this->defaultLimit = $searchSettings->General->default_limit;
}
if (isset($searchSettings->General->limit_options)) {
$this->limitOptions
= explode(",", $searchSettings->General->limit_options);
}
// Set up highlighting preference
if (isset($searchSettings->General->highlighting)) {
$this->highlight = $searchSettings->General->highlighting;
}
// Set up spelling preference
if (isset($searchSettings->Spelling->enabled)) {
$this->spellcheck = $searchSettings->Spelling->enabled;
}
// Load search preferences:
if (isset($searchSettings->General->default_view)) {
$this->defaultView = $searchSettings->General->default_view;
}
if (isset($searchSettings->General->retain_filters_by_default)) {
$this->retainFiltersByDefault
= $searchSettings->General->retain_filters_by_default;
}
if (isset($searchSettings->General->default_filters)) {
$this->defaultFilters = $searchSettings->General->default_filters
->toArray();
}
if (isset($searchSettings->General->result_limit)) {
$this->resultLimit = $searchSettings->General->result_limit;
}
// Search handler setup:
if (isset($searchSettings->Basic_Searches)) {
foreach ($searchSettings->Basic_Searches as $key => $value) {
$this->basicHandlers[$key] = $value;
}
}
if (isset($searchSettings->Advanced_Searches)) {
foreach ($searchSettings->Advanced_Searches as $key => $value) {
$this->advancedHandlers[$key] = $value;
}
}
// Load sort preferences:
if (isset($searchSettings->Sorting)) {
foreach ($searchSettings->Sorting as $key => $value) {
$this->sortOptions[$key] = $value;
}
}
if (isset($searchSettings->General->default_sort)) {
$this->defaultSort = $searchSettings->General->default_sort;
}
if (isset($searchSettings->DefaultSortingByType)
&& count($searchSettings->DefaultSortingByType) > 0
) {
foreach ($searchSettings->DefaultSortingByType as $key => $val) {
$this->defaultSortByHandler[$key] = $val;
}
}
// Load view preferences (or defaults if none in .ini file):
if (isset($searchSettings->Views)) {
foreach ($searchSettings->Views as $key => $value) {
$this->viewOptions[$key] = $value;
}
} elseif (isset($searchSettings->General->default_view)) {
$this->viewOptions = array($this->defaultView => $this->defaultView);
} else {
$this->viewOptions = array('list' => 'List');
}
}
/**
* Return the route name for the search results action.
*
* @return string
*/
public function getSearchAction()
{
return 'summon-search';
}
/**
* Return the route name of the action used for performing advanced searches.
* Returns false if the feature is not supported.
*
* @return string|bool
*/
public function getAdvancedSearchAction()
{
return 'summon-advanced';
}
/**
* If there is a limit to how many search results a user can access, this
* method will return that limit. If there is no limit, this will return
* -1.
*
* @return int
*/
public function getVisibleSearchResultLimit()
{
return intval($this->resultLimit);
}
/**
* Get the maximum number of topic recommendations (false for none)
*
* @return bool|int
*/
public function getMaxTopicRecommendations()
{
return $this->maxTopicRecommendations;
}
/**
* Set the maximum number of topic recommendations (false for none)
*
* @param bool|int $max New maximum setting
*
* @return void
*/
public function setMaxTopicRecommendations($max)
{
$this->maxTopicRecommendations = $max;
}
}