1 |
6657531f
|
Andreas Kohlbecker
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Search related functions.
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
a6ae799b
|
Andreas Kohlbecker
|
define("SESSION_KEY_SEARCH_REGISTRATION_FILTER", "SESSION_KEY_SEARCH_REGISTRATION_FILTER");
|
8 |
efbff4b3
|
Andreas Kohlbecker
|
define('SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER', 'SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER');
|
9 |
a6ae799b
|
Andreas Kohlbecker
|
|
10 |
6657531f
|
Andreas Kohlbecker
|
/**
|
11 |
|
|
* Returns a Drupal path to a search form for a CDM webservice.
|
12 |
|
|
*
|
13 |
|
|
* For a given CDM webservice end-point, the drupal page path to the
|
14 |
|
|
* according search form is returned.
|
15 |
|
|
* cdm webservice end points are defined in constant variables like:
|
16 |
|
|
* <code>CDM_WS_PORTAL_TAXON_FIND</code> and
|
17 |
|
|
* <code>CDM_WS_PORTAL_TAXON_FINDBY_DESCRIPTIONELEMENT_FULLTEXT</code>
|
18 |
|
|
*
|
19 |
|
|
* @param string $ws_endpoint
|
20 |
|
|
* The cdm webservice endpoint for which to find the search form path.
|
21 |
|
|
*
|
22 |
|
|
* @return string
|
23 |
|
|
* The Drupal path found.
|
24 |
|
|
*/
|
25 |
|
|
function cdm_dataportal_search_form_path_for_ws($ws_endpoint) {
|
26 |
|
|
static $form_ws_map = array(
|
27 |
|
|
CDM_WS_PORTAL_TAXON_FIND => "cdm_dataportal/search",
|
28 |
dc435632
|
Andreas Kohlbecker
|
CDM_WS_PORTAL_TAXON_SEARCH => "cdm_dataportal/search",
|
29 |
6657531f
|
Andreas Kohlbecker
|
CDM_WS_PORTAL_TAXON_FINDBY_DESCRIPTIONELEMENT_FULLTEXT => "cdm_dataportal/search/taxon_by_description",
|
30 |
|
|
);
|
31 |
|
|
return $form_ws_map[$ws_endpoint];
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
|
|
* Prepares a form array for a general purpose search form.
|
36 |
|
|
*
|
37 |
|
|
* The form is used for general purpose search functionality in the
|
38 |
103a1463
|
Andreas Kohlbecker
|
* dataportal. The form returned is populated with all necessary fields
|
39 |
6657531f
|
Andreas Kohlbecker
|
* for internal processing and has the textfield element $form['query']
|
40 |
|
|
* which holds the query term.
|
41 |
|
|
*
|
42 |
|
|
* @param string $action_path
|
43 |
|
|
* The Drupal path to be put into the action url to which the form will
|
44 |
|
|
* be submitted.
|
45 |
|
|
* @param string $search_webservice
|
46 |
|
|
* The cdm-remote webservice to be used, valid values are defined by
|
47 |
|
|
* the constants: FIXME.
|
48 |
|
|
* @param string $query_field_default_value
|
49 |
632a697a
|
Andreas Kohlbecker
|
* A default text for the query field
|
50 |
6657531f
|
Andreas Kohlbecker
|
* @param string $query_field_description
|
51 |
632a697a
|
Andreas Kohlbecker
|
* The description text for the query field
|
52 |
6657531f
|
Andreas Kohlbecker
|
*
|
53 |
|
|
* @return array
|
54 |
|
|
* The prepared form array.
|
55 |
|
|
*/
|
56 |
24797d7f
|
Andreas Kohlbecker
|
function cdm_dataportal_search_form_prepare($action_path, $search_webservice, $query_field_default_value, $query_field_description) {
|
57 |
2d0d855a
|
Andreas Kohlbecker
|
|
58 |
|
|
|
59 |
6657531f
|
Andreas Kohlbecker
|
$form['#method'] = 'get';
|
60 |
|
|
$form['#action'] = url($action_path, array(
|
61 |
|
|
'absolute' => TRUE,
|
62 |
|
|
));
|
63 |
|
|
|
64 |
|
|
$form['ws'] = array(
|
65 |
|
|
'#type' => 'hidden',
|
66 |
|
|
'#value' => $search_webservice,
|
67 |
|
|
'#name' => 'ws',
|
68 |
|
|
);
|
69 |
|
|
|
70 |
|
|
$form['query'] = array(
|
71 |
|
|
'#weight' => 0,
|
72 |
|
|
'#type' => 'textfield',
|
73 |
|
|
'#size' => 68,
|
74 |
632a697a
|
Andreas Kohlbecker
|
// This causes the description to display also when hovering over
|
75 |
2d0d855a
|
Andreas Kohlbecker
|
// the textfield.
|
76 |
|
|
// This is wanted behaviour for the simple seach but could
|
77 |
632a697a
|
Andreas Kohlbecker
|
// be disabled for the advances search.
|
78 |
6657531f
|
Andreas Kohlbecker
|
'#attributes' => array(
|
79 |
|
|
'title' => $query_field_description,
|
80 |
|
|
),
|
81 |
|
|
'#description' => $query_field_description,
|
82 |
|
|
'#value' => $query_field_default_value,
|
83 |
|
|
// '#description' => $query_field_description,
|
84 |
|
|
);
|
85 |
023c4a03
|
Patrick Plitzner
|
if(variable_get(SIMPLE_SEARCH_AUTO_SUGGEST)){
|
86 |
24f57e45
|
Patrick Plitzner
|
$form['query']['#autocomplete_path'] = 'cdm_dataportal/taxon/autosuggest////';
|
87 |
35bea66c
|
Patrick Plitzner
|
}
|
88 |
6657531f
|
Andreas Kohlbecker
|
|
89 |
93ae67cc
|
Patrick Plitzner
|
$form['search'] = array(
|
90 |
6657531f
|
Andreas Kohlbecker
|
'#weight' => 3,
|
91 |
|
|
'#tree' => TRUE,
|
92 |
7b4c053d
|
Andreas Kohlbecker
|
// '#type' => $advanced_form ? 'fieldset': 'hidden',
|
93 |
6657531f
|
Andreas Kohlbecker
|
'#title' => t('Options'),
|
94 |
|
|
);
|
95 |
|
|
|
96 |
|
|
// Clean URL get forms breaks if we don't give it a 'q'.
|
97 |
|
|
if (!(bool) variable_get('clean_url', '0')) {
|
98 |
|
|
$form['search']['q'] = array(
|
99 |
|
|
'#type' => 'hidden',
|
100 |
|
|
'#value' => $action_path,
|
101 |
|
|
'#name' => 'q',
|
102 |
|
|
);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
$form['submit'] = array(
|
106 |
|
|
'#weight' => 5,
|
107 |
|
|
'#type' => 'submit',
|
108 |
|
|
'#name' => '',
|
109 |
|
|
'#value' => t('Search'),
|
110 |
|
|
);
|
111 |
|
|
|
112 |
|
|
return $form;
|
113 |
|
|
}
|
114 |
|
|
|
115 |
24f57e45
|
Patrick Plitzner
|
function cdm_dataportal_taxon_autosuggest($classificationUuid = NULL, $areaUuid = NULL, $status = NULL, $string) {
|
116 |
93ae67cc
|
Patrick Plitzner
|
$matches = array();
|
117 |
|
|
|
118 |
|
|
$queryParams = array();
|
119 |
04a1d647
|
Patrick Plitzner
|
$queryParams['query'] = $string.'*';
|
120 |
24f57e45
|
Patrick Plitzner
|
if((is_null($classificationUuid) || $classificationUuid=='') && isset($_SESSION['cdm']['taxonomictree_uuid'])){
|
121 |
|
|
$classificationUuid = $_SESSION['cdm']['taxonomictree_uuid'];// if no classification uuid is set use the current one
|
122 |
|
|
}
|
123 |
|
|
if($classificationUuid){
|
124 |
|
|
$queryParams['classificationUuid'] = $classificationUuid;
|
125 |
04a1d647
|
Patrick Plitzner
|
}
|
126 |
|
|
if($areaUuid){
|
127 |
|
|
$queryParams['area'] = $areaUuid;
|
128 |
|
|
}
|
129 |
|
|
if($status){
|
130 |
|
|
$queryParams['status'] = $status ;
|
131 |
|
|
}
|
132 |
93ae67cc
|
Patrick Plitzner
|
$queryParams['pageNumber'] = '0';
|
133 |
04a1d647
|
Patrick Plitzner
|
$queryParams['pageSize'] = '10';
|
134 |
93ae67cc
|
Patrick Plitzner
|
$queryParams['doTaxa'] = true;
|
135 |
|
|
$queryParams['doSynonyms'] = true;
|
136 |
|
|
$queryParams['doMisappliedNames'] = true;
|
137 |
|
|
$queryParams['doTaxaByCommonNames'] = true;
|
138 |
|
|
|
139 |
|
|
$search_results = cdm_ws_get(CDM_WS_TAXON_SEARCH, NULL, queryString($queryParams));
|
140 |
|
|
foreach($search_results->records as $record){
|
141 |
|
|
$titleCache = $record->entity->titleCache;
|
142 |
01fff74a
|
Andreas Kohlbecker
|
preg_match('/(.*) sec.*/', $titleCache, $trimmedTitle); //remove sec reference
|
143 |
93ae67cc
|
Patrick Plitzner
|
$trimmedTitle = trim($trimmedTitle[1]);
|
144 |
f35d3f4a
|
Patrick Plitzner
|
$matches[$trimmedTitle] = check_plain($trimmedTitle);
|
145 |
93ae67cc
|
Patrick Plitzner
|
}
|
146 |
|
|
drupal_json_output($matches);
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
/**
|
151 |
dbf4b8a8
|
Andreas Kohlbecker
|
* Creates a search form for searching on taxa.
|
152 |
|
|
*
|
153 |
7b4c053d
|
Andreas Kohlbecker
|
* If advanced $advanced_form id TRUE the form will offer additional choices
|
154 |
dbf4b8a8
|
Andreas Kohlbecker
|
*
|
155 |
73874c48
|
Andreas Kohlbecker
|
* @param array $form
|
156 |
7b4c053d
|
Andreas Kohlbecker
|
* A drupal form array
|
157 |
73874c48
|
Andreas Kohlbecker
|
* @param array $form_state
|
158 |
7b4c053d
|
Andreas Kohlbecker
|
* The drupal form state passed as reference
|
159 |
|
|
* @param bool $advanced_form
|
160 |
73874c48
|
Andreas Kohlbecker
|
* default is FALSE
|
161 |
7b4c053d
|
Andreas Kohlbecker
|
* @param bool $classification_select
|
162 |
01fff74a
|
Andreas Kohlbecker
|
* set TRUE to offer a classification selector in the form - default is FALSE
|
163 |
73874c48
|
Andreas Kohlbecker
|
* if only available in the advanced mode
|
164 |
dbf4b8a8
|
Andreas Kohlbecker
|
*
|
165 |
7b4c053d
|
Andreas Kohlbecker
|
* @return array
|
166 |
dbf4b8a8
|
Andreas Kohlbecker
|
* the form array
|
167 |
6657531f
|
Andreas Kohlbecker
|
*/
|
168 |
6eaec849
|
Katja Luther
|
function cdm_dataportal_search_taxon_form($form, &$form_state, $advanced_form = FALSE, $classification_select = TRUE)
|
169 |
|
|
{
|
170 |
6657531f
|
Andreas Kohlbecker
|
|
171 |
6eaec849
|
Katja Luther
|
if ($form_state['build_info']['form_id'] == 'cdm_dataportal_search_blast_form') {
|
172 |
|
|
$form = cdm_dataportal_search_blast_form($form, $form_state);
|
173 |
|
|
} else {
|
174 |
6657531f
|
Andreas Kohlbecker
|
|
175 |
2d0d855a
|
Andreas Kohlbecker
|
|
176 |
6eaec849
|
Katja Luther
|
$query_field_default_value = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
|
177 |
|
|
|
178 |
|
|
if ($advanced_form || variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, FALSE)) {
|
179 |
|
|
$search_service_endpoint = CDM_WS_PORTAL_TAXON_SEARCH;
|
180 |
|
|
} else {
|
181 |
|
|
$search_service_endpoint = CDM_WS_PORTAL_TAXON_FIND;
|
182 |
|
|
}
|
183 |
cd64df61
|
Andreas Kohlbecker
|
|
184 |
6eaec849
|
Katja Luther
|
$form = cdm_dataportal_search_form_prepare(
|
185 |
|
|
'cdm_dataportal/search/results/taxon',
|
186 |
|
|
$search_service_endpoint,
|
187 |
|
|
$query_field_default_value,
|
188 |
|
|
t('Enter the name or part of a name you wish to search for.
|
189 |
|
|
The asterisk character * can be used as wildcard, but must not be used as first character.')
|
190 |
|
|
);
|
191 |
|
|
}
|
192 |
7b4c053d
|
Andreas Kohlbecker
|
if (!$advanced_form) {
|
193 |
6657531f
|
Andreas Kohlbecker
|
$form['query']['#size'] = 20;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
$form['search']['pageSize'] = array(
|
197 |
|
|
'#weight' => -1,
|
198 |
|
|
'#type' => 'hidden',
|
199 |
|
|
'#value' => variable_get('cdm_dataportal_search_items_on_page', 25),
|
200 |
|
|
);
|
201 |
|
|
|
202 |
|
|
$form['search']['pageNumber'] = array(
|
203 |
|
|
'#weight' => -1,
|
204 |
|
|
'#type' => 'hidden',
|
205 |
|
|
'#value' => 0,
|
206 |
|
|
);
|
207 |
|
|
|
208 |
7b4c053d
|
Andreas Kohlbecker
|
$search_taxa_mode_settings = get_array_variable_merged(
|
209 |
|
|
CDM_SEARCH_TAXA_MODE,
|
210 |
|
|
CDM_SEARCH_TAXA_MODE_DEFAULT
|
211 |
|
|
);
|
212 |
|
|
$preset_do_taxa = $search_taxa_mode_settings['doTaxa'] !== 0;
|
213 |
|
|
$preset_do_synonyms = $search_taxa_mode_settings['doSynonyms'] !== 0;
|
214 |
|
|
$preset_do_taxa_by_common_names = $search_taxa_mode_settings['doTaxaByCommonNames'] !== 0;
|
215 |
|
|
$preset_do_misapplied_names = $search_taxa_mode_settings['doMisappliedNames'] !== 0;
|
216 |
6657531f
|
Andreas Kohlbecker
|
|
217 |
7b4c053d
|
Andreas Kohlbecker
|
if ($advanced_form) {
|
218 |
642b323b
|
Andreas Kohlbecker
|
|
219 |
6280e639
|
Andreas Kohlbecker
|
// --- ADVANCED SEARCH FORM ---
|
220 |
61b6ee11
|
Andreas Kohlbecker
|
//
|
221 |
dbf4b8a8
|
Andreas Kohlbecker
|
|
222 |
6657531f
|
Andreas Kohlbecker
|
// Get presets from settings.
|
223 |
7663cd0b
|
Andreas Kohlbecker
|
$preset_classification_uuid = get_current_classification_uuid();
|
224 |
6657531f
|
Andreas Kohlbecker
|
|
225 |
|
|
// Overwrite presets by user choice stored in session.
|
226 |
6280e639
|
Andreas Kohlbecker
|
if (isset($_SESSION['cdm']['search'])) {
|
227 |
7b4c053d
|
Andreas Kohlbecker
|
$preset_do_taxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
|
228 |
|
|
$preset_do_synonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
|
229 |
|
|
$preset_do_misapplied_names = (isset($_SESSION['cdm']['search']['doMisappliedNames']) ? 1 : 0);
|
230 |
|
|
$preset_do_taxa_by_common_names = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
|
231 |
61b6ee11
|
Andreas Kohlbecker
|
if (isset($_SESSION['cdm']['search']['tree'])) {
|
232 |
|
|
$preset_classification_uuid = $_SESSION['cdm']['search']['tree'];
|
233 |
|
|
}
|
234 |
6657531f
|
Andreas Kohlbecker
|
}
|
235 |
dbf4b8a8
|
Andreas Kohlbecker
|
|
236 |
7b4c053d
|
Andreas Kohlbecker
|
if ($classification_select === TRUE) {
|
237 |
f56b1626
|
Andreas Kohlbecker
|
$form['search']['tree'] = array(
|
238 |
642b323b
|
Andreas Kohlbecker
|
'#title' => t('Classification'),
|
239 |
|
|
'#weight' => 1,
|
240 |
|
|
'#type' => 'select',
|
241 |
7d42c393
|
Andreas Kohlbecker
|
'#default_value' => $preset_classification_uuid,
|
242 |
f56b1626
|
Andreas Kohlbecker
|
'#options' => cdm_get_taxontrees_as_options(TRUE),
|
243 |
8ae3cfe3
|
Andreas Kohlbecker
|
'#description' => t('A filter to limit the search to a specific classification. Choosing <em>--- ALL ---</em> will disable this filter.'),
|
244 |
dbf4b8a8
|
Andreas Kohlbecker
|
);
|
245 |
632a697a
|
Andreas Kohlbecker
|
}
|
246 |
dbf4b8a8
|
Andreas Kohlbecker
|
|
247 |
6657531f
|
Andreas Kohlbecker
|
// General search parameters.
|
248 |
|
|
$form['search']['doTaxa'] = array(
|
249 |
|
|
'#weight' => 2,
|
250 |
|
|
'#type' => 'checkbox',
|
251 |
51384c70
|
Andreas Kohlbecker
|
'#title' => t('Include') . ' ' . t('accepted taxa'),
|
252 |
7b4c053d
|
Andreas Kohlbecker
|
'#value' => $preset_do_taxa,
|
253 |
6657531f
|
Andreas Kohlbecker
|
);
|
254 |
|
|
$form['search']['doSynonyms'] = array(
|
255 |
|
|
'#weight' => 3,
|
256 |
|
|
'#type' => 'checkbox',
|
257 |
51384c70
|
Andreas Kohlbecker
|
'#title' => t('Include') . ' ' . t('synonyms'),
|
258 |
7b4c053d
|
Andreas Kohlbecker
|
'#value' => $preset_do_synonyms,
|
259 |
6657531f
|
Andreas Kohlbecker
|
);
|
260 |
|
|
$form['search']['doMisappliedNames'] = array(
|
261 |
|
|
'#weight' => 4,
|
262 |
|
|
'#type' => 'checkbox',
|
263 |
51384c70
|
Andreas Kohlbecker
|
'#title' => t('Include') . ' ' . t('misapplied names'),
|
264 |
7b4c053d
|
Andreas Kohlbecker
|
'#value' => $preset_do_misapplied_names,
|
265 |
6657531f
|
Andreas Kohlbecker
|
);
|
266 |
|
|
$form['search']['doTaxaByCommonNames'] = array(
|
267 |
|
|
'#weight' => 5,
|
268 |
|
|
'#type' => 'checkbox',
|
269 |
51384c70
|
Andreas Kohlbecker
|
'#title' => t('Include') . ' ' . t('common names'),
|
270 |
7b4c053d
|
Andreas Kohlbecker
|
'#value' => $preset_do_taxa_by_common_names,
|
271 |
6657531f
|
Andreas Kohlbecker
|
);
|
272 |
|
|
|
273 |
7b4c053d
|
Andreas Kohlbecker
|
$area_term_dtos = cdm_ws_fetch_all(
|
274 |
|
|
CDM_WS_DESCRIPTION_NAMEDAREAS_IN_USE,
|
275 |
|
|
array('includeAllParents' => 'true')
|
276 |
|
|
);
|
277 |
446cffc5
|
Andreas Kohlbecker
|
|
278 |
86424a78
|
Andreas Kohlbecker
|
// create map: term_uuid => term
|
279 |
41c6dd13
|
Andreas Kohlbecker
|
$term_map = array();
|
280 |
7b4c053d
|
Andreas Kohlbecker
|
foreach ($area_term_dtos as $term_dto) {
|
281 |
41c6dd13
|
Andreas Kohlbecker
|
$term_map[$term_dto->uuid] = $term_dto;
|
282 |
632a697a
|
Andreas Kohlbecker
|
}
|
283 |
41c6dd13
|
Andreas Kohlbecker
|
|
284 |
632a697a
|
Andreas Kohlbecker
|
$term_tree = array();
|
285 |
41c6dd13
|
Andreas Kohlbecker
|
// mixed_vocabularies will contain the uuid vocabularies which
|
286 |
86424a78
|
Andreas Kohlbecker
|
// also contain terms of foreign vocabularies due to the term
|
287 |
41c6dd13
|
Andreas Kohlbecker
|
// hierarchy
|
288 |
|
|
$mixed_vocabularies = array();
|
289 |
|
|
|
290 |
|
|
// Build hierarchy of the terms regardless of the vocabulary.
|
291 |
a783afbc
|
Andreas Kohlbecker
|
foreach ($term_map as $term_dto) {
|
292 |
|
|
if (!empty($term_dto->partOfUuid)) {
|
293 |
|
|
// Children.
|
294 |
|
|
$parent =& $term_map[$term_dto->partOfUuid];
|
295 |
|
|
if ($parent) {
|
296 |
|
|
if (!isset($parent->children)) {
|
297 |
|
|
$parent->children = array();
|
298 |
446cffc5
|
Andreas Kohlbecker
|
}
|
299 |
a783afbc
|
Andreas Kohlbecker
|
$parent->children[$term_dto->uuid] = $term_dto;
|
300 |
|
|
if ($parent->vocabularyUuid != $term_dto->vocabularyUuid) {
|
301 |
|
|
$mixed_vocabularies[$parent->vocabularyUuid] = $parent->vocabularyUuid;
|
302 |
41c6dd13
|
Andreas Kohlbecker
|
}
|
303 |
632a697a
|
Andreas Kohlbecker
|
}
|
304 |
446cffc5
|
Andreas Kohlbecker
|
}
|
305 |
a783afbc
|
Andreas Kohlbecker
|
else {
|
306 |
|
|
// group root nodes by vocabulary
|
307 |
|
|
if (!isset($term_tree[$term_dto->vocabularyUuid])) {
|
308 |
|
|
$term_tree[$term_dto->vocabularyUuid] = array();
|
309 |
|
|
}
|
310 |
|
|
$term_tree[$term_dto->vocabularyUuid][$term_dto->uuid] = $term_dto;
|
311 |
|
|
}
|
312 |
|
|
}
|
313 |
|
|
|
314 |
072122ee
|
Andreas Kohlbecker
|
$show_area_filter = ! variable_get(CDM_SEARCH_AREA_FILTER_PRESET, '');
|
315 |
446cffc5
|
Andreas Kohlbecker
|
|
316 |
072122ee
|
Andreas Kohlbecker
|
if($show_area_filter){
|
317 |
|
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/search_area_filter.js');
|
318 |
|
|
|
319 |
|
|
drupal_add_js('jQuery(document).ready(function() {
|
320 |
446cffc5
|
Andreas Kohlbecker
|
jQuery(\'#edit-search-areas\').search_area_filter(\'#edit-search-areas-areas-filter\');
|
321 |
|
|
});
|
322 |
|
|
', array('type' => 'inline'));
|
323 |
|
|
|
324 |
072122ee
|
Andreas Kohlbecker
|
$form['search']['areas'] = array(
|
325 |
|
|
'#type' => 'fieldset',
|
326 |
|
|
'#title' => t('Filter by distribution areas'),
|
327 |
|
|
'#description' => t('The search will return taxa having distribution
|
328 |
722b1688
|
Andreas Kohlbecker
|
information for at least one of the selected areas.') . ' '
|
329 |
072122ee
|
Andreas Kohlbecker
|
.(count($term_tree) > 1 ? t('The areas are grouped
|
330 |
722b1688
|
Andreas Kohlbecker
|
by the vocabularies to which the highest level areas belong.') : ''),
|
331 |
632a697a
|
Andreas Kohlbecker
|
);
|
332 |
072122ee
|
Andreas Kohlbecker
|
$form['search']['areas']['areas_filter'] = array(
|
333 |
|
|
'#type' => 'textfield',
|
334 |
|
|
'#description' => t('Type to filter the areas listed below.'),
|
335 |
|
|
);
|
336 |
|
|
$vocab_cnt = 0;
|
337 |
|
|
$areas_defaults = array();
|
338 |
|
|
if (isset($_SESSION['cdm']['search']['area'])) {
|
339 |
|
|
$areas_defaults = explode(',', $_SESSION['cdm']['search']['area']);
|
340 |
|
|
}
|
341 |
6b605d3b
|
Andreas Kohlbecker
|
_add_js_resizable_element('.resizable-box', true);
|
342 |
072122ee
|
Andreas Kohlbecker
|
foreach ($term_tree as $vocab_uuid => $term_dto_tree) {
|
343 |
|
|
$vocabulary = cdm_ws_get(CDM_WS_TERMVOCABULARY, array($vocab_uuid));
|
344 |
|
|
$areas_options = term_tree_as_options($term_dto_tree);
|
345 |
|
|
$form['search']['areas']['area'][$vocab_cnt++] = array(
|
346 |
|
|
'#prefix' => '<strong>' . $vocabulary->representation_L10n
|
347 |
|
|
. (isset($mixed_vocabularies[$vocab_uuid]) ? ' <span title="Contains terms of at least one other area vocabulary.">(' . t('mixed') . ')</span>': '')
|
348 |
6b605d3b
|
Andreas Kohlbecker
|
. '</strong><div class="resizable-container"><div class="resizable-box">',
|
349 |
072122ee
|
Andreas Kohlbecker
|
'#type' => 'checkboxes',
|
350 |
|
|
'#default_value' => $areas_defaults,
|
351 |
|
|
'#options' => $areas_options,
|
352 |
6b605d3b
|
Andreas Kohlbecker
|
'#suffix' => '</div></div>'
|
353 |
072122ee
|
Andreas Kohlbecker
|
);
|
354 |
|
|
}
|
355 |
632a697a
|
Andreas Kohlbecker
|
}
|
356 |
446cffc5
|
Andreas Kohlbecker
|
|
357 |
7b4c053d
|
Andreas Kohlbecker
|
}
|
358 |
|
|
else {
|
359 |
61b6ee11
|
Andreas Kohlbecker
|
// --- SIMPLE SEARCH FORM ---
|
360 |
|
|
//
|
361 |
|
|
|
362 |
6657531f
|
Andreas Kohlbecker
|
// Overwrite presets by user choice stored in session.
|
363 |
6280e639
|
Andreas Kohlbecker
|
if (isset($_SESSION['cdm']['search'])) {
|
364 |
7b4c053d
|
Andreas Kohlbecker
|
$preset_do_misapplied_names = (isset($_SESSION['cdm']['search']['doMisappliedNames']) ? 1 : 0);
|
365 |
6657531f
|
Andreas Kohlbecker
|
}
|
366 |
|
|
|
367 |
|
|
$form['search']['doTaxa'] = array(
|
368 |
|
|
'#weight' => -2,
|
369 |
|
|
'#type' => 'hidden',
|
370 |
7b4c053d
|
Andreas Kohlbecker
|
'#value' => $preset_do_taxa,
|
371 |
6657531f
|
Andreas Kohlbecker
|
);
|
372 |
|
|
$form['search']['doSynonyms'] = array(
|
373 |
|
|
'#weight' => -3,
|
374 |
|
|
'#type' => 'hidden',
|
375 |
7b4c053d
|
Andreas Kohlbecker
|
'#value' => $preset_do_synonyms,
|
376 |
6657531f
|
Andreas Kohlbecker
|
);
|
377 |
|
|
$form['search']['doMisappliedNames'] = array(
|
378 |
|
|
'#weight' => -4,
|
379 |
|
|
'#type' => 'checkbox',
|
380 |
|
|
'#title' => t('Misapplied names'),
|
381 |
7b4c053d
|
Andreas Kohlbecker
|
'#value' => $preset_do_misapplied_names,
|
382 |
6657531f
|
Andreas Kohlbecker
|
);
|
383 |
|
|
$form['search']['doTaxaByCommonNames'] = array(
|
384 |
|
|
'#weight' => -5,
|
385 |
|
|
'#type' => 'hidden',
|
386 |
7b4c053d
|
Andreas Kohlbecker
|
'#value' => $preset_do_taxa_by_common_names,
|
387 |
6657531f
|
Andreas Kohlbecker
|
);
|
388 |
|
|
}
|
389 |
|
|
|
390 |
|
|
return $form;
|
391 |
|
|
}
|
392 |
632a697a
|
Andreas Kohlbecker
|
|
393 |
6eaec849
|
Katja Luther
|
/**
|
394 |
|
|
* Creates a search form for searching on taxa.
|
395 |
|
|
*
|
396 |
|
|
* If advanced $advanced_form id TRUE the form will offer additional choices
|
397 |
|
|
*
|
398 |
|
|
* @param array $form
|
399 |
|
|
* A drupal form array
|
400 |
|
|
* @param array $form_state
|
401 |
|
|
* The drupal form state passed as reference
|
402 |
|
|
* @param bool $advanced_form
|
403 |
|
|
* default is FALSE
|
404 |
|
|
* @param bool $classification_select
|
405 |
|
|
* set TRUE to offer a classification selector in the form - default is FALSE
|
406 |
|
|
* if only available in the advanced mode
|
407 |
|
|
*
|
408 |
|
|
* @return array
|
409 |
|
|
* the form array
|
410 |
|
|
*/
|
411 |
|
|
function cdm_dataportal_search_blast_form($form, &$form_state) {
|
412 |
|
|
|
413 |
|
|
$query_field_default_value = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
|
414 |
|
|
|
415 |
|
|
$search_service_endpoint = CDM_WS_PORTAL_BLAST;
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
$form = cdm_dataportal_search_blast_form_prepare(
|
419 |
|
|
'cdm_dataportal/search/results/specimen',
|
420 |
|
|
$search_service_endpoint,
|
421 |
|
|
$query_field_default_value,
|
422 |
|
|
t('Enter the sequence or part of a sequence you wish to search for.')
|
423 |
|
|
);
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
|
427 |
|
|
$form['search']['pageSize'] = array(
|
428 |
|
|
'#weight' => -1,
|
429 |
|
|
'#type' => 'hidden',
|
430 |
|
|
'#value' => variable_get('cdm_dataportal_search_items_on_page', 25),
|
431 |
|
|
);
|
432 |
|
|
|
433 |
|
|
$form['search']['pageNumber'] = array(
|
434 |
|
|
'#weight' => -1,
|
435 |
|
|
'#type' => 'hidden',
|
436 |
|
|
'#value' => 0,
|
437 |
|
|
);
|
438 |
|
|
|
439 |
|
|
|
440 |
|
|
|
441 |
|
|
|
442 |
|
|
|
443 |
|
|
return $form;
|
444 |
|
|
}
|
445 |
|
|
|
446 |
|
|
/**
|
447 |
|
|
* Prepares a form array for a general purpose search form.
|
448 |
|
|
*
|
449 |
|
|
* The form is used for general purpose search functionality in the
|
450 |
|
|
* dataportal. The form returned is populated with all necessary fields
|
451 |
|
|
* for internal processing and has the textfield element $form['query']
|
452 |
|
|
* which holds the query term.
|
453 |
|
|
*
|
454 |
|
|
* @param string $action_path
|
455 |
|
|
* The Drupal path to be put into the action url to which the form will
|
456 |
|
|
* be submitted.
|
457 |
|
|
* @param string $search_webservice
|
458 |
|
|
* The cdm-remote webservice to be used, valid values are defined by
|
459 |
|
|
* the constants: FIXME.
|
460 |
|
|
* @param string $query_field_default_value
|
461 |
|
|
* A default text for the query field
|
462 |
|
|
* @param string $query_field_description
|
463 |
|
|
* The description text for the query field
|
464 |
|
|
* @param string $process
|
465 |
|
|
* The value for #process, if NULL (default), 'cdm_dataportal_search_process'
|
466 |
|
|
* is used.
|
467 |
|
|
*
|
468 |
|
|
* @return array
|
469 |
|
|
* The prepared form array.
|
470 |
|
|
*/
|
471 |
|
|
function cdm_dataportal_search_blast_form_prepare($action_path, $search_webservice, $query_field_default_value, $query_field_description, $process = NULL) {
|
472 |
|
|
|
473 |
|
|
if ($process == NULL) {
|
474 |
|
|
$process = 'cdm_dataportal_search_process';
|
475 |
|
|
}
|
476 |
|
|
|
477 |
|
|
$form['#method'] = 'get';
|
478 |
|
|
//
|
479 |
|
|
// $form['#process'] = array(
|
480 |
|
|
// $process => array(),
|
481 |
|
|
// );
|
482 |
|
|
//
|
483 |
|
|
$form['#action'] = url($action_path, array(
|
484 |
|
|
'absolute' => TRUE,
|
485 |
|
|
));
|
486 |
|
|
|
487 |
|
|
$form['ws'] = array(
|
488 |
|
|
'#type' => 'hidden',
|
489 |
|
|
'#value' => $search_webservice,
|
490 |
|
|
'#name' => 'ws',
|
491 |
|
|
);
|
492 |
|
|
|
493 |
|
|
$form['query'] = array(
|
494 |
|
|
'#weight' => 0,
|
495 |
|
|
'#type' => 'textarea',
|
496 |
|
|
'#size' => 68,
|
497 |
|
|
// This causes the description to display also when hovering over
|
498 |
|
|
// the textfield.
|
499 |
|
|
// This is wanted behaviour for the simple seach but could
|
500 |
|
|
// be disabled for the advances search.
|
501 |
|
|
'#attributes' => array(
|
502 |
|
|
'title' => $query_field_description,
|
503 |
|
|
),
|
504 |
|
|
'#description' => $query_field_description,
|
505 |
|
|
// '#value' => $query_field_default_value,
|
506 |
|
|
// '#description' => $query_field_description,
|
507 |
|
|
);
|
508 |
|
|
|
509 |
|
|
|
510 |
|
|
$form['search'] = array(
|
511 |
|
|
'#weight' => 3,
|
512 |
|
|
'#tree' => TRUE,
|
513 |
|
|
// '#type' => $advanced_form ? 'fieldset': 'hidden',
|
514 |
|
|
'#title' => t('Options'),
|
515 |
|
|
);
|
516 |
|
|
|
517 |
|
|
// Clean URL get forms breaks if we don't give it a 'q'.
|
518 |
|
|
if (!(bool) variable_get('clean_url', '0')) {
|
519 |
|
|
$form['search']['q'] = array(
|
520 |
|
|
'#type' => 'hidden',
|
521 |
|
|
'#value' => $action_path,
|
522 |
|
|
'#name' => 'q',
|
523 |
|
|
);
|
524 |
|
|
}
|
525 |
|
|
|
526 |
|
|
$form['search']['word_size'] = array(
|
527 |
|
|
'#weight' => 1,
|
528 |
|
|
'#type' => 'textfield',
|
529 |
|
|
'#title' => t('Word size'),
|
530 |
|
|
'#default_value' => 7,
|
531 |
|
|
'#description' => t('Length of initial exact match'),
|
532 |
|
|
);
|
533 |
|
|
|
534 |
|
|
$form['search']['reward'] = array(
|
535 |
|
|
'#weight' => 2,
|
536 |
|
|
'#type' => 'textfield',
|
537 |
|
|
'#title' => t('Reward'),
|
538 |
|
|
'#default_value' => 1,
|
539 |
|
|
'#description' => t('Reward for Matching'),
|
540 |
|
|
);
|
541 |
|
|
|
542 |
|
|
$form['search']['penalty'] = array(
|
543 |
|
|
'#weight' => 3,
|
544 |
|
|
'#type' => 'textfield',
|
545 |
|
|
'#title' => t('Penalty'),
|
546 |
|
|
'#default_value' => -2,
|
547 |
|
|
'#description' => t('Penalty for mismatching'),
|
548 |
|
|
);
|
549 |
|
|
|
550 |
|
|
$form['search']['gap_open'] = array(
|
551 |
|
|
'#weight' => 4,
|
552 |
|
|
'#type' => 'textfield',
|
553 |
|
|
'#title' => t('Gap open'),
|
554 |
|
|
'#default_value' => 5,
|
555 |
|
|
'#description' => t('Cost to open a gap'),
|
556 |
|
|
);
|
557 |
|
|
|
558 |
|
|
$form['search']['gap_extend'] = array(
|
559 |
|
|
'#weight' => 5,
|
560 |
|
|
'#type' => 'textfield',
|
561 |
|
|
'#title' => t('Gap extend'),
|
562 |
|
|
'#default_value' => -2,
|
563 |
|
|
'#description' => t('Cost for extend a gap'),
|
564 |
|
|
);
|
565 |
|
|
|
566 |
|
|
$form['submit'] = array(
|
567 |
|
|
'#weight' => 5,
|
568 |
|
|
'#type' => 'submit',
|
569 |
|
|
'#name' => '',
|
570 |
|
|
'#value' => t('Search'),
|
571 |
|
|
);
|
572 |
|
|
|
573 |
|
|
return $form;
|
574 |
|
|
}
|
575 |
6657531f
|
Andreas Kohlbecker
|
/**
|
576 |
7b4c053d
|
Andreas Kohlbecker
|
* Wrapper function for cdm_dataportal_search_taxon_form().
|
577 |
|
|
*
|
578 |
|
|
* This function makes ot possible possible to just pass the
|
579 |
|
|
* correct $form_id 'cdm_dataportal_search_taxon_form_advanced' to
|
580 |
|
|
* drupal_get_form like:
|
581 |
|
|
* drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
|
582 |
|
|
*
|
583 |
|
|
* @param array $form
|
584 |
|
|
* A drupal form array
|
585 |
|
|
* @param array $form_state
|
586 |
|
|
* The drupal form state passed as reference
|
587 |
|
|
*
|
588 |
|
|
* @return array
|
589 |
|
|
* The form array
|
590 |
6657531f
|
Andreas Kohlbecker
|
*/
|
591 |
|
|
function cdm_dataportal_search_taxon_form_advanced($form, &$form_state) {
|
592 |
|
|
return cdm_dataportal_search_taxon_form($form, $form_state, TRUE);
|
593 |
|
|
}
|
594 |
|
|
|
595 |
|
|
/**
|
596 |
7b4c053d
|
Andreas Kohlbecker
|
* Form for searching taxa by the findByDescriptionElementFullText rest service.
|
597 |
6657531f
|
Andreas Kohlbecker
|
*/
|
598 |
|
|
function cdm_dataportal_search_taxon_by_description_form() {
|
599 |
|
|
$query_field_default_value = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
|
600 |
|
|
|
601 |
|
|
$form = cdm_dataportal_search_form_prepare(
|
602 |
632a697a
|
Andreas Kohlbecker
|
'cdm_dataportal/search/results/taxon',
|
603 |
|
|
CDM_WS_PORTAL_TAXON_FINDBY_DESCRIPTIONELEMENT_FULLTEXT,
|
604 |
|
|
$query_field_default_value,
|
605 |
|
|
t("Enter the text you wish to search for. The asterisk character * can be
|
606 |
20624f5a
|
Andreas Kohlbecker
|
used as wildcard, but must not be used as first character. Terms can be combined with 'AND'. To search for a
|
607 |
36af8b60
|
Andreas Kohlbecker
|
full phrase enclose the terms in parentheses. For more syntactical
|
608 |
7b4c053d
|
Andreas Kohlbecker
|
options please refer to the !link.",
|
609 |
|
|
array(
|
610 |
|
|
'!link' => l(
|
611 |
|
|
t('Apache Lucene - Query Parser Syntax'),
|
612 |
|
|
'http://lucene.apache.org/core/old_versioned_docs/versions/2_9_1/queryparsersyntax.html', array(
|
613 |
|
|
'attributes' => array(
|
614 |
|
|
'absolute' => TRUE,
|
615 |
|
|
'html' => TRUE),
|
616 |
|
|
)
|
617 |
|
|
),
|
618 |
|
|
)
|
619 |
a6ae799b
|
Andreas Kohlbecker
|
)
|
620 |
632a697a
|
Andreas Kohlbecker
|
);
|
621 |
6657531f
|
Andreas Kohlbecker
|
|
622 |
|
|
$form['search']['tree'] = array(
|
623 |
|
|
'#weight' => -1,
|
624 |
|
|
'#type' => 'hidden',
|
625 |
7663cd0b
|
Andreas Kohlbecker
|
'#value' => get_current_classification_uuid(),
|
626 |
6657531f
|
Andreas Kohlbecker
|
);
|
627 |
|
|
|
628 |
|
|
$form['search']['hl'] = array(
|
629 |
|
|
'#weight' => -1,
|
630 |
|
|
'#type' => 'hidden',
|
631 |
|
|
'#value' => 1,
|
632 |
|
|
);
|
633 |
|
|
|
634 |
b58fcc1f
|
Andreas Kohlbecker
|
// Only available to admins:
|
635 |
6657531f
|
Andreas Kohlbecker
|
if (!isset($_SESSION['cdm']['search']['clazz'])) {
|
636 |
|
|
$_SESSION['cdm']['search']['clazz'] = '';
|
637 |
|
|
}
|
638 |
|
|
if (module_exists("user") && user_access('administer')) {
|
639 |
|
|
$form['search']['clazz'] = array(
|
640 |
|
|
'#type' => 'select',
|
641 |
b58fcc1f
|
Andreas Kohlbecker
|
'#title' => t('Limit to description item type'),
|
642 |
6657531f
|
Andreas Kohlbecker
|
'#default_value' => $_SESSION['cdm']['search']['clazz'],
|
643 |
|
|
'#options' => cdm_descriptionElementTypes_as_option(TRUE),
|
644 |
|
|
);
|
645 |
|
|
}
|
646 |
|
|
|
647 |
7b4c053d
|
Andreas Kohlbecker
|
$profile_feature_tree = get_profile_feature_tree();
|
648 |
|
|
$feature_options = _featureTree_nodes_as_feature_options($profile_feature_tree->root);
|
649 |
6657531f
|
Andreas Kohlbecker
|
if (isset($_SESSION['cdm']['search']['features'])) {
|
650 |
|
|
$form['search']['features'] = array(
|
651 |
|
|
'#type' => 'checkboxes',
|
652 |
|
|
'#title' => t('Limit to selected features'),
|
653 |
|
|
'#default_value' => $_SESSION['cdm']['search']['features'],
|
654 |
|
|
'#options' => $feature_options,
|
655 |
|
|
);
|
656 |
|
|
}
|
657 |
|
|
else {
|
658 |
|
|
$form['search']['features'] = array(
|
659 |
|
|
'#type' => 'checkboxes',
|
660 |
|
|
'#title' => t('Limit to selected features'),
|
661 |
|
|
'#options' => $feature_options,
|
662 |
|
|
);
|
663 |
|
|
}
|
664 |
|
|
return $form;
|
665 |
|
|
}
|
666 |
|
|
|
667 |
|
|
/**
|
668 |
7b4c053d
|
Andreas Kohlbecker
|
* Processes the query parameters of the search form.
|
669 |
|
|
*
|
670 |
|
|
* Reads the query parameters from $_REQUEST and modifies and adds additional
|
671 |
103a1463
|
Andreas Kohlbecker
|
* query parameters if necessary.
|
672 |
dbf4b8a8
|
Andreas Kohlbecker
|
*
|
673 |
|
|
* - Filters $_REQUEST by a list of valid request parameters
|
674 |
|
|
* - modifies geographic_range parameters
|
675 |
|
|
* - adds taxon tree uuid if it is missing and if it should not be
|
676 |
|
|
* ignored (parameter value = 'IGNORE')
|
677 |
|
|
* - and more
|
678 |
|
|
*
|
679 |
b3d49e6e
|
Andreas Kohlbecker
|
* @param $search_endpoint string
|
680 |
|
|
* The web service endpoint which will be used for executing the search.
|
681 |
|
|
* Usually one of CDM_WS_PORTAL_TAXON_SEARCH, CDM_WS_PORTAL_TAXON_FIND,
|
682 |
|
|
* CDM_WS_PORTAL_TAXON_FINDBY_DESCRIPTIONELEMENT_FULLTEXT.
|
683 |
7b4c053d
|
Andreas Kohlbecker
|
* @return array
|
684 |
dbf4b8a8
|
Andreas Kohlbecker
|
* the processed request parameters submitted by the search form and
|
685 |
|
|
* also stores them in $_SESSION['cdm']['search']
|
686 |
6657531f
|
Andreas Kohlbecker
|
*/
|
687 |
b3d49e6e
|
Andreas Kohlbecker
|
function cdm_dataportal_search_request($search_endpoint)
|
688 |
f48cede0
|
Andreas Kohlbecker
|
{
|
689 |
61b6ee11
|
Andreas Kohlbecker
|
|
690 |
6657531f
|
Andreas Kohlbecker
|
$form_params = array();
|
691 |
61b6ee11
|
Andreas Kohlbecker
|
|
692 |
34dd7be9
|
Andreas Kohlbecker
|
if (isset($_REQUEST['search']) && is_array($_REQUEST['search'])) {
|
693 |
6657531f
|
Andreas Kohlbecker
|
array_deep_copy($_REQUEST['search'], $form_params);
|
694 |
|
|
}
|
695 |
34dd7be9
|
Andreas Kohlbecker
|
|
696 |
|
|
if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
|
697 |
|
|
$form_params = array_merge($form_params, $_REQUEST['pager']);
|
698 |
|
|
}
|
699 |
|
|
|
700 |
6657531f
|
Andreas Kohlbecker
|
$form_params['query'] = trim($_REQUEST['query']);
|
701 |
|
|
|
702 |
b3d49e6e
|
Andreas Kohlbecker
|
|
703 |
6657531f
|
Andreas Kohlbecker
|
// --- handle geographic range
|
704 |
|
|
// Split of geographic range.
|
705 |
44756fcd
|
Andreas Kohlbecker
|
unset($form_params['areas']);
|
706 |
072122ee
|
Andreas Kohlbecker
|
|
707 |
9bbe3bcd
|
Andreas Kohlbecker
|
$area_filter_preset = null;
|
708 |
f48cede0
|
Andreas Kohlbecker
|
if (variable_get(CDM_SEARCH_AREA_FILTER_PRESET, '')) {
|
709 |
|
|
$area_filter_preset = explode(',', variable_get(CDM_SEARCH_AREA_FILTER_PRESET, ''));
|
710 |
|
|
}
|
711 |
072122ee
|
Andreas Kohlbecker
|
|
712 |
30399ffa
|
Andreas Kohlbecker
|
$area_uuids = array();
|
713 |
072122ee
|
Andreas Kohlbecker
|
if($area_filter_preset){
|
714 |
|
|
$area_uuids = $area_filter_preset;
|
715 |
|
|
}
|
716 |
|
|
elseif (isset($_REQUEST['search']['areas']['area']) && is_array($_REQUEST['search']['areas']['area'])) {
|
717 |
7b4c053d
|
Andreas Kohlbecker
|
foreach ($_REQUEST['search']['areas']['area'] as $areas) {
|
718 |
|
|
$area_uuids = array_merge($area_uuids, $areas);
|
719 |
|
|
}
|
720 |
efa372e9
|
Andreas Kohlbecker
|
// The area filter is limited to areas with non absent distribution status
|
721 |
|
|
$presence_terms_options = cdm_vocabulary_as_option(UUID_PRESENCE_ABSENCE_TERM, null, FALSE, array('absenceTerm' => '/false/'));
|
722 |
|
|
$presence_term_uuids = array_keys($presence_terms_options);
|
723 |
|
|
$form_params['status'] = $presence_term_uuids;
|
724 |
072122ee
|
Andreas Kohlbecker
|
}
|
725 |
30399ffa
|
Andreas Kohlbecker
|
if(count($area_uuids) > 0){
|
726 |
7b4c053d
|
Andreas Kohlbecker
|
$form_params['area'] = implode(',', $area_uuids);
|
727 |
6657531f
|
Andreas Kohlbecker
|
}
|
728 |
|
|
|
729 |
7b4c053d
|
Andreas Kohlbecker
|
// Simple search will not submit a 'tree' query parameter,
|
730 |
|
|
// so we add it here from what is stored in the session unless
|
731 |
90a6166e
|
Andreas Kohlbecker
|
// SIMPLE_SEARCH_IGNORE_CLASSIFICATION is checked in the settings.
|
732 |
|
|
if (!isset($form_params['tree']) && !variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0)) {
|
733 |
7663cd0b
|
Andreas Kohlbecker
|
$form_params['tree'] = get_current_classification_uuid();
|
734 |
61b6ee11
|
Andreas Kohlbecker
|
}
|
735 |
38753115
|
Andreas Kohlbecker
|
// Store in session.
|
736 |
|
|
$_SESSION['cdm']['search'] = $form_params;
|
737 |
|
|
|
738 |
|
|
// ----------- further processing that must not be store in the session --------- //
|
739 |
|
|
|
740 |
67a5cafa
|
Andreas Kohlbecker
|
if($search_endpoint == CDM_WS_PORTAL_TAXON_SEARCH){
|
741 |
a15edbb0
|
Andreas Kohlbecker
|
// HACK to allow using dot characters
|
742 |
|
|
$form_params['query'] = str_replace('.', '*', $form_params['query']);
|
743 |
a0557101
|
Andreas Kohlbecker
|
// lucene based taxon search always as phrase search if the query string contains a whitespace --> enclose it in "
|
744 |
|
|
if(preg_match("/\s+/", $form_params['query'])){
|
745 |
|
|
if(!str_beginsWith($form_params['query'], '"')){
|
746 |
|
|
$form_params['query'] = '"' . $form_params['query'];
|
747 |
|
|
}
|
748 |
|
|
if(!str_endsWith($form_params['query'], '"')){
|
749 |
|
|
$form_params['query'] = $form_params['query'] . '"' ;
|
750 |
|
|
}
|
751 |
67a5cafa
|
Andreas Kohlbecker
|
}
|
752 |
|
|
}
|
753 |
|
|
|
754 |
efa372e9
|
Andreas Kohlbecker
|
// If the 'NONE' classification has been chosen (advanced search)
|
755 |
7b4c053d
|
Andreas Kohlbecker
|
// delete the tree information to avoid unknown uuid exceptions in the
|
756 |
|
|
// cdm service.
|
757 |
|
|
if (isset($form_params['tree'])
|
758 |
|
|
&& ($form_params['tree'] == 'NONE' || !is_uuid($form_params['tree']))
|
759 |
|
|
) {
|
760 |
|
|
// $form_params['ignore_classification'] = TRUE;
|
761 |
dbf4b8a8
|
Andreas Kohlbecker
|
unset($form_params['tree']);
|
762 |
|
|
}
|
763 |
7b4c053d
|
Andreas Kohlbecker
|
// else {
|
764 |
|
|
// $form_params['ignore_classification'] = NULL;
|
765 |
|
|
// }
|
766 |
dbf4b8a8
|
Andreas Kohlbecker
|
|
767 |
6657531f
|
Andreas Kohlbecker
|
|
768 |
|
|
return $form_params;
|
769 |
|
|
}
|
770 |
|
|
|
771 |
6eaec849
|
Katja Luther
|
/**
|
772 |
|
|
* Processes the query parameters of the blast search form.
|
773 |
|
|
*
|
774 |
|
|
* Reads the query parameters from $_REQUEST and modifies and adds additional
|
775 |
|
|
* query parameters if necessary.
|
776 |
|
|
*
|
777 |
|
|
* - Filters $_REQUEST by a list of valid request parameters
|
778 |
|
|
*
|
779 |
|
|
*
|
780 |
|
|
* @param $search_endpoint string
|
781 |
|
|
* The web service endpoint which will be used for executing the search.
|
782 |
|
|
*
|
783 |
|
|
* @return array
|
784 |
|
|
* the processed request parameters submitted by the search form and
|
785 |
|
|
* also stores them in $_SESSION['cdm']['search']
|
786 |
|
|
*/
|
787 |
|
|
function cdm_dataportal_blast_search_request($search_endpoint)
|
788 |
|
|
{
|
789 |
|
|
|
790 |
|
|
$form_params = array();
|
791 |
|
|
|
792 |
|
|
if (isset($_REQUEST['search']) && is_array($_REQUEST['search'])) {
|
793 |
|
|
array_deep_copy($_REQUEST['search'], $form_params['data']);
|
794 |
|
|
}
|
795 |
|
|
|
796 |
|
|
|
797 |
|
|
//$query = trim($_REQUEST['query']);
|
798 |
|
|
$form_params['data'] = formatParams($_REQUEST['search']);
|
799 |
|
|
|
800 |
|
|
/*if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
|
801 |
|
|
$form_params = array_merge($form_params, $_REQUEST['pager']);
|
802 |
|
|
}*/
|
803 |
|
|
|
804 |
|
|
$form_params['query']= trim($_REQUEST['query']);
|
805 |
|
|
|
806 |
|
|
|
807 |
|
|
// Store in session.
|
808 |
|
|
$_SESSION['cdm']['search'] = $form_params;
|
809 |
|
|
|
810 |
|
|
return $form_params;
|
811 |
|
|
}
|
812 |
|
|
|
813 |
|
|
|
814 |
|
|
|
815 |
61b6ee11
|
Andreas Kohlbecker
|
/**
|
816 |
44756fcd
|
Andreas Kohlbecker
|
* Provides the classification to which the last search has been limited to..
|
817 |
61b6ee11
|
Andreas Kohlbecker
|
*
|
818 |
24797d7f
|
Andreas Kohlbecker
|
* This function should only be used after the cdm_dataportal_search_taxon_execute()
|
819 |
efa372e9
|
Andreas Kohlbecker
|
* handler has been run, otherwise it will return the information from the last
|
820 |
7b4c053d
|
Andreas Kohlbecker
|
* search executed. The information is retrieved from
|
821 |
61b6ee11
|
Andreas Kohlbecker
|
* the $_SESSION variable: $_SESSION['cdm']['search']['tree']
|
822 |
|
|
*
|
823 |
7b4c053d
|
Andreas Kohlbecker
|
* @return object
|
824 |
|
|
* the CDM classification instance which has been used a filter for the
|
825 |
|
|
* last processed search
|
826 |
|
|
* or NULL, it it was on all classifications
|
827 |
61b6ee11
|
Andreas Kohlbecker
|
*/
|
828 |
|
|
function cdm_dataportal_searched_in_classification() {
|
829 |
|
|
|
830 |
|
|
$classification = &drupal_static(__FUNCTION__);
|
831 |
|
|
|
832 |
|
|
if (!isset($classification)) {
|
833 |
|
|
if (isset($_SESSION['cdm']['search']['tree'])) {
|
834 |
|
|
$classification = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY, ($_SESSION['cdm']['search']['tree']));
|
835 |
7b4c053d
|
Andreas Kohlbecker
|
}
|
836 |
|
|
else {
|
837 |
61b6ee11
|
Andreas Kohlbecker
|
$classification = FALSE;
|
838 |
|
|
}
|
839 |
|
|
}
|
840 |
|
|
|
841 |
7b4c053d
|
Andreas Kohlbecker
|
return $classification !== FALSE ? $classification : NULL;
|
842 |
61b6ee11
|
Andreas Kohlbecker
|
}
|
843 |
|
|
|
844 |
a6ae799b
|
Andreas Kohlbecker
|
/**
|
845 |
|
|
* Removed the drupal internal form parameters 'form_id', 'form_token', 'form_build_id' from the request array.
|
846 |
|
|
*
|
847 |
|
|
* @param $request array
|
848 |
|
|
* Pass $_REQUEST as paramter
|
849 |
|
|
* @return array
|
850 |
|
|
* The $request array without drupal internal form parameters
|
851 |
|
|
*/
|
852 |
|
|
function remove_drupal_form_params($request) {
|
853 |
|
|
|
854 |
|
|
static $exclude_keys = array('form_id', 'form_token', 'form_build_id');
|
855 |
|
|
$request_sanitized = array();
|
856 |
|
|
foreach ($request as $key => $value) {
|
857 |
|
|
if(!array_search($key, $exclude_keys)){
|
858 |
|
|
$request_sanitized[$key] = $value;
|
859 |
|
|
}
|
860 |
|
|
}
|
861 |
|
|
|
862 |
|
|
return $request_sanitized;
|
863 |
|
|
}
|
864 |
|
|
|
865 |
6657531f
|
Andreas Kohlbecker
|
/**
|
866 |
103a1463
|
Andreas Kohlbecker
|
* Sends a search request to the cdm server.
|
867 |
dbf4b8a8
|
Andreas Kohlbecker
|
*
|
868 |
|
|
* The parameters to build the query are taken obtained by calling
|
869 |
efa372e9
|
Andreas Kohlbecker
|
* cdm_dataportal_search_request() which reads the query parameters
|
870 |
dbf4b8a8
|
Andreas Kohlbecker
|
* from $_REQUEST and add additional query parameters if nessecary.
|
871 |
|
|
*
|
872 |
efa372e9
|
Andreas Kohlbecker
|
* @see cdm_dataportal_search_request()
|
873 |
6657531f
|
Andreas Kohlbecker
|
*/
|
874 |
24797d7f
|
Andreas Kohlbecker
|
function cdm_dataportal_search_taxon_execute() {
|
875 |
6657531f
|
Andreas Kohlbecker
|
|
876 |
|
|
// Store as last search in session.
|
877 |
|
|
$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
|
878 |
|
|
|
879 |
|
|
// Validate the search webservice parameter:
|
880 |
7b4c053d
|
Andreas Kohlbecker
|
if (!isset($_REQUEST['ws'])) {
|
881 |
|
|
drupal_set_message(
|
882 |
103a1463
|
Andreas Kohlbecker
|
t("Invalid search, webservice parameter 'ws' is missing"), 'warning'
|
883 |
7b4c053d
|
Andreas Kohlbecker
|
);
|
884 |
61b6ee11
|
Andreas Kohlbecker
|
return NULL;
|
885 |
|
|
}
|
886 |
7b4c053d
|
Andreas Kohlbecker
|
if (!cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
|
887 |
6657531f
|
Andreas Kohlbecker
|
// Endpoint is unknown.
|
888 |
7b4c053d
|
Andreas Kohlbecker
|
drupal_set_message(
|
889 |
78ec4159
|
Andreas Kohlbecker
|
t("Invalid search webservice parameter 'ws' given"), 'warning'
|
890 |
7b4c053d
|
Andreas Kohlbecker
|
);
|
891 |
6657531f
|
Andreas Kohlbecker
|
return NULL;
|
892 |
|
|
}
|
893 |
|
|
|
894 |
7b4c053d
|
Andreas Kohlbecker
|
// Read the query parameters from $_REQUEST and add additional query
|
895 |
|
|
// parameters if necessary.
|
896 |
b3d49e6e
|
Andreas Kohlbecker
|
$request_params = cdm_dataportal_search_request($_REQUEST['ws']);
|
897 |
dbf4b8a8
|
Andreas Kohlbecker
|
|
898 |
446cffc5
|
Andreas Kohlbecker
|
$taxon_pager = cdm_ws_get($_REQUEST['ws'], NULL, queryString($request_params));
|
899 |
|
|
|
900 |
|
|
return $taxon_pager;
|
901 |
|
|
}
|
902 |
|
|
|
903 |
6eaec849
|
Katja Luther
|
/**
|
904 |
|
|
* Sends a search request to the cdm server.
|
905 |
|
|
*
|
906 |
|
|
* The parameters to build the query are taken obtained by calling
|
907 |
|
|
* cdm_dataportal_search_request() which reads the query parameters
|
908 |
|
|
* from $_REQUEST and add additional query parameters if nessecary.
|
909 |
|
|
*
|
910 |
|
|
* @see cdm_dataportal_search_request()
|
911 |
|
|
*/
|
912 |
|
|
function cdm_dataportal_search_blast_execute() {
|
913 |
|
|
|
914 |
|
|
// Store as last search in session.
|
915 |
|
|
$_SESSION['cdm']['last_blast_search'] = $_SERVER['REQUEST_URI'];
|
916 |
|
|
|
917 |
|
|
// Validate the search webservice parameter:
|
918 |
|
|
if (!isset($_REQUEST['ws'])) {
|
919 |
|
|
drupal_set_message(
|
920 |
|
|
t("Invalid search, webservice parameter 'ws' is missing"), 'warning'
|
921 |
|
|
);
|
922 |
|
|
return NULL;
|
923 |
|
|
}
|
924 |
|
|
// if (!cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
|
925 |
|
|
// // Endpoint is unknown.
|
926 |
|
|
// drupal_set_message(
|
927 |
|
|
// t("Invalid search webservice parameter 'ws' given"), 'warning'
|
928 |
|
|
// );
|
929 |
|
|
// return NULL;
|
930 |
|
|
// }
|
931 |
|
|
|
932 |
|
|
// Read the query parameters from $_REQUEST and add additional query
|
933 |
|
|
// parameters if necessary.
|
934 |
|
|
$request_params = cdm_dataportal_blast_search_request($_REQUEST['ws']);
|
935 |
|
|
// $url = drupal_http_build_query($_REQUEST['ws'], $request_params);
|
936 |
|
|
|
937 |
|
|
$taxon_pager = drupal_http_request($_REQUEST['ws'].'?sequence='.$request_params['query'], $request_params);
|
938 |
|
|
|
939 |
|
|
return $taxon_pager;
|
940 |
|
|
}
|
941 |
|
|
|
942 |
|
|
|
943 |
a6ae799b
|
Andreas Kohlbecker
|
|
944 |
|
|
/**
|
945 |
efbff4b3
|
Andreas Kohlbecker
|
* Sends a request for a registrations filter search to the cdm server.
|
946 |
a6ae799b
|
Andreas Kohlbecker
|
*/
|
947 |
efbff4b3
|
Andreas Kohlbecker
|
function cdm_dataportal_search_registrations_filter_execute()
|
948 |
a6ae799b
|
Andreas Kohlbecker
|
{
|
949 |
|
|
|
950 |
|
|
static $query_param_map = array(
|
951 |
|
|
'identifier' => 'identifierFilterPattern',
|
952 |
|
|
'taxon_name'=> 'taxonNameFilterPattern',
|
953 |
|
|
'type_designation_status' => 'typeDesignationStatusUuids',
|
954 |
|
|
);
|
955 |
|
|
|
956 |
efbff4b3
|
Andreas Kohlbecker
|
$session_key = SESSION_KEY_SEARCH_REGISTRATION_FILTER;
|
957 |
|
|
$request_params = cdm_dataportal_search_request_params($session_key, $query_param_map);
|
958 |
a6ae799b
|
Andreas Kohlbecker
|
|
959 |
|
|
// cleanup
|
960 |
|
|
if(isset($request_params['typeDesignationStatusUuids'])){
|
961 |
|
|
if(!$request_params['typeDesignationStatusUuids']
|
962 |
|
|
|| $request_params['typeDesignationStatusUuids'] == "0"
|
963 |
|
|
|| (isset($request_params['typeDesignationStatusUuids'][0]) && !$request_params['typeDesignationStatusUuids'][0])){
|
964 |
|
|
unset($request_params['typeDesignationStatusUuids']);
|
965 |
|
|
}
|
966 |
bb177c82
|
Andreas Kohlbecker
|
}
|
967 |
|
|
if(isset($request_params['taxonNameFilterPattern'])){
|
968 |
|
|
// trim and remove empty taxon name query strings
|
969 |
|
|
$request_params['taxonNameFilterPattern'] = trim($request_params['taxonNameFilterPattern']);
|
970 |
|
|
if(!$request_params['taxonNameFilterPattern']){
|
971 |
|
|
unset($request_params['taxonNameFilterPattern']);
|
972 |
|
|
}
|
973 |
a6ae799b
|
Andreas Kohlbecker
|
}
|
974 |
|
|
|
975 |
|
|
$registration_pager = cdm_ws_get('registrationDTO/find', NULL, queryString($request_params));
|
976 |
|
|
|
977 |
|
|
return $registration_pager;
|
978 |
|
|
}
|
979 |
|
|
|
980 |
efbff4b3
|
Andreas Kohlbecker
|
/**
|
981 |
|
|
* Sends a request for a registrations taxongraph search to the cdm server.
|
982 |
|
|
*/
|
983 |
|
|
function cdm_dataportal_search_registrations_taxongraph_execute()
|
984 |
|
|
{
|
985 |
|
|
|
986 |
|
|
static $query_param_map = array(
|
987 |
|
|
'taxon_name'=> 'taxonNameFilter'
|
988 |
|
|
);
|
989 |
|
|
|
990 |
|
|
$session_key = SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER;
|
991 |
|
|
$request_params = cdm_dataportal_search_request_params($session_key, $query_param_map);
|
992 |
|
|
|
993 |
|
|
// cleanup
|
994 |
|
|
if(isset($request_params['taxonNameFilter'])){
|
995 |
|
|
// trim and remove empty taxon name query strings
|
996 |
|
|
$request_params['taxonNameFilter'] = trim($request_params['taxonNameFilter']);
|
997 |
|
|
if(!$request_params['taxonNameFilter']){
|
998 |
|
|
unset($request_params['taxonNameFilter']);
|
999 |
|
|
}
|
1000 |
|
|
}
|
1001 |
|
|
|
1002 |
|
|
$registration_pager = cdm_ws_get('registrationDTO/findInTaxonGraph', NULL, queryString($request_params));
|
1003 |
|
|
|
1004 |
|
|
return $registration_pager;
|
1005 |
|
|
}
|
1006 |
|
|
|
1007 |
|
|
/**
|
1008 |
|
|
* @param $session_key
|
1009 |
|
|
* @param $query_param_map
|
1010 |
|
|
* @return array
|
1011 |
|
|
*/
|
1012 |
|
|
function cdm_dataportal_search_request_params($session_key, $query_param_map)
|
1013 |
|
|
{
|
1014 |
|
|
// Read the query parameters from $_REQUEST and add additional query
|
1015 |
|
|
// parameters if necessary.
|
1016 |
|
|
$request_params = array();
|
1017 |
|
|
|
1018 |
|
|
$request = remove_drupal_form_params($_REQUEST);
|
1019 |
|
|
|
1020 |
|
|
if (count($request) > 0) {
|
1021 |
|
|
$_SESSION['cdm'][$session_key] = $request;
|
1022 |
|
|
foreach ($query_param_map as $filter_key => $query_param) {
|
1023 |
|
|
if (isset($request[$filter_key])) {
|
1024 |
|
|
$request_params[$query_param] = $request[$filter_key];
|
1025 |
|
|
}
|
1026 |
|
|
}
|
1027 |
|
|
if (isset($request['pager']['pageNumber'])) {
|
1028 |
|
|
$request_params['pageNumber'] = $request['pager']['pageNumber'];
|
1029 |
|
|
}
|
1030 |
|
|
}
|
1031 |
|
|
|
1032 |
|
|
if (count($request_params) == 0 && isset($_SESSION['cdm'][$session_key])) {
|
1033 |
|
|
foreach ($query_param_map as $filter_key => $query_param) {
|
1034 |
|
|
if (isset($_SESSION['cdm'][$session_key][$filter_key])) {
|
1035 |
|
|
$request_params[$query_param] = $_SESSION['cdm'][$session_key][$filter_key];
|
1036 |
|
|
}
|
1037 |
|
|
}
|
1038 |
|
|
if (isset($_SESSION['cdm'][$session_key]['pager']['pageNumber'])) {
|
1039 |
|
|
$request_params['pageNumber'] = $_SESSION['cdm'][$session_key]['pager']['pageNumber'];
|
1040 |
|
|
}
|
1041 |
|
|
}
|
1042 |
|
|
return $request_params;
|
1043 |
|
|
}
|
1044 |
|
|
|
1045 |
7b4c053d
|
Andreas Kohlbecker
|
/**
|
1046 |
|
|
* Transforms the termDTO tree into options array.
|
1047 |
|
|
*
|
1048 |
|
|
* TermDto:
|
1049 |
|
|
* - partOfUuid:
|
1050 |
|
|
* - representation_L10n:
|
1051 |
|
|
* - representation_L10n_abbreviatedLabel:
|
1052 |
|
|
* - uuid:
|
1053 |
|
|
* - vocabularyUuid:
|
1054 |
|
|
* - children: array of TermDto
|
1055 |
|
|
*
|
1056 |
|
|
* The options array is suitable for drupal form API elements that
|
1057 |
|
|
* allow multiple choices.
|
1058 |
|
|
* @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#options
|
1059 |
|
|
*
|
1060 |
|
|
* @param array $term_dto_tree
|
1061 |
|
|
* a hierarchic array of CDM TermDto instances, with additional
|
1062 |
|
|
* 'children' field:
|
1063 |
|
|
* @param array $options
|
1064 |
|
|
* Internally used for recursive calls
|
1065 |
|
|
* @param string $prefix
|
1066 |
|
|
* Internally used for recursive calls
|
1067 |
|
|
*
|
1068 |
|
|
* @return array
|
1069 |
|
|
* the terms in an array as options for a form element that allows
|
1070 |
|
|
* multiple choices.
|
1071 |
|
|
*/
|
1072 |
|
|
function term_tree_as_options($term_dto_tree, &$options = array(), $prefix = '') {
|
1073 |
|
|
|
1074 |
c079337e
|
Andreas Kohlbecker
|
uasort($term_dto_tree, 'compare_terms_by_order_index');
|
1075 |
7b4c053d
|
Andreas Kohlbecker
|
foreach ($term_dto_tree as $uuid => $dto) {
|
1076 |
|
|
$label = $prefix . '<span class="child-label">'
|
1077 |
|
|
. $dto->representation_L10n
|
1078 |
35619936
|
Andreas Kohlbecker
|
. '</span><span class="child-label-abbreviated"> (' . $dto->representation_L10n_abbreviatedLabel . ')</span>';
|
1079 |
7b4c053d
|
Andreas Kohlbecker
|
$options[$uuid] = $label;
|
1080 |
|
|
if (isset($dto->children) && is_array($dto->children)) {
|
1081 |
|
|
term_tree_as_options(
|
1082 |
|
|
$dto->children,
|
1083 |
|
|
$options, $prefix
|
1084 |
fdf52d6a
|
Andreas Kohlbecker
|
. '<span data-cdm-parent="' . $uuid . '" class="parent"></span>'
|
1085 |
|
|
);
|
1086 |
446cffc5
|
Andreas Kohlbecker
|
}
|
1087 |
7b4c053d
|
Andreas Kohlbecker
|
}
|
1088 |
6657531f
|
Andreas Kohlbecker
|
|
1089 |
7b4c053d
|
Andreas Kohlbecker
|
return $options;
|
1090 |
6657531f
|
Andreas Kohlbecker
|
}
|
1091 |
a6ae799b
|
Andreas Kohlbecker
|
|
1092 |
|
|
|
1093 |
efbff4b3
|
Andreas Kohlbecker
|
function cdm_dataportal_search_registration_filter_form($form, &$form_state) {
|
1094 |
a6ae799b
|
Andreas Kohlbecker
|
|
1095 |
d68a30b0
|
Andreas Kohlbecker
|
static $filter_presets_empty = array(
|
1096 |
|
|
'identifier'=> null,
|
1097 |
|
|
'taxon_name'=> null,
|
1098 |
|
|
'type_designation_status' => null
|
1099 |
|
|
);
|
1100 |
|
|
|
1101 |
6d9071b7
|
Andreas Kohlbecker
|
_add_font_awesome_font();
|
1102 |
bb177c82
|
Andreas Kohlbecker
|
|
1103 |
5195ddf2
|
Andreas Kohlbecker
|
if(isset($_REQUEST['q']) && ($_REQUEST['q'] == 'cdm_dataportal/registration-search/filter' || $_REQUEST['q'] == 'cdm_dataportal/registration-search')){
|
1104 |
efbff4b3
|
Andreas Kohlbecker
|
// read the $request_params only if it was send from this form
|
1105 |
|
|
$request_params = remove_drupal_form_params($_REQUEST);
|
1106 |
|
|
} else {
|
1107 |
|
|
$request_params = array();
|
1108 |
|
|
}
|
1109 |
a6ae799b
|
Andreas Kohlbecker
|
$filter_presets = (isset($_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER]) ? $_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER] : array());
|
1110 |
efbff4b3
|
Andreas Kohlbecker
|
$filter_presets = array_merge($filter_presets_empty, $filter_presets, $request_params);
|
1111 |
|
|
$form['#action'] = url('/cdm_dataportal/registration-search/filter');
|
1112 |
a6ae799b
|
Andreas Kohlbecker
|
$form['#method'] = 'get';
|
1113 |
|
|
$form['#attributes'] = array('class' => array('search-filter'));
|
1114 |
|
|
$form['identifier'] = array(
|
1115 |
|
|
'#type' => 'textfield',
|
1116 |
|
|
'#title' => t('Identifier'),
|
1117 |
|
|
'#default_value' => $filter_presets['identifier'],
|
1118 |
|
|
'#size' => 20,
|
1119 |
|
|
'#maxlength' => 128
|
1120 |
|
|
);
|
1121 |
|
|
$form['taxon_name'] = array(
|
1122 |
|
|
'#type' => 'textfield',
|
1123 |
|
|
'#title' => t('Scientific name'),
|
1124 |
|
|
'#default_value' => $filter_presets['taxon_name'],
|
1125 |
|
|
'#size' => 20,
|
1126 |
|
|
'#maxlength' => 128
|
1127 |
|
|
);
|
1128 |
|
|
$form['type_designation_status'] = array(
|
1129 |
|
|
'#type' => 'select',
|
1130 |
|
|
'#title' => t('Type designation status'),
|
1131 |
|
|
'#multiple' => true,
|
1132 |
|
|
'#options' => cdm_terms_by_type_as_option('TypeDesignationStatusBase', null, null, TRUE),
|
1133 |
|
|
'#default_value' => $filter_presets['type_designation_status']
|
1134 |
|
|
);
|
1135 |
|
|
|
1136 |
|
|
$form['submit'] = array(
|
1137 |
|
|
'#type' => 'submit',
|
1138 |
|
|
'#attributes' => array('class' => array('fa-icon'), 'title' => t('Search')),
|
1139 |
|
|
'#value' => decode_entities(''), // fontawesome search icon
|
1140 |
098b6358
|
Andreas Kohlbecker
|
// '#prefix' => "<div class=\"form-item\"><label> </label>",
|
1141 |
|
|
// '#suffix' => "</div>"
|
1142 |
a6ae799b
|
Andreas Kohlbecker
|
|
1143 |
|
|
);
|
1144 |
|
|
return $form;
|
1145 |
|
|
}
|
1146 |
|
|
|
1147 |
|
|
|
1148 |
efbff4b3
|
Andreas Kohlbecker
|
function cdm_dataportal_search_registration_taxongraph_form($form, &$form_state) {
|
1149 |
|
|
|
1150 |
|
|
static $filter_presets_empty = array(
|
1151 |
|
|
'taxon_name'=> null
|
1152 |
|
|
);
|
1153 |
|
|
|
1154 |
|
|
_add_font_awesome_font();
|
1155 |
|
|
|
1156 |
5195ddf2
|
Andreas Kohlbecker
|
if(isset($_REQUEST['q']) && $_REQUEST['q'] == 'cdm_dataportal/registration-search/taxongraph'){
|
1157 |
efbff4b3
|
Andreas Kohlbecker
|
// read the $request_params only if it was send from this form
|
1158 |
|
|
$request_params = remove_drupal_form_params($_REQUEST);
|
1159 |
|
|
} else {
|
1160 |
|
|
$request_params = array();
|
1161 |
|
|
}
|
1162 |
|
|
$filter_presets = (isset($_SESSION['cdm'][SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER]) ? $_SESSION['cdm'][SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER] : array());
|
1163 |
|
|
$filter_presets = array_merge($filter_presets_empty, $filter_presets, $request_params);
|
1164 |
|
|
|
1165 |
|
|
$form['#action'] = url('/cdm_dataportal/registration-search/taxongraph');
|
1166 |
|
|
$form['#method'] = 'get';
|
1167 |
|
|
$form['#attributes'] = array('class' => array('search-filter'));
|
1168 |
|
|
$form['taxon_name'] = array(
|
1169 |
|
|
'#type' => 'textfield',
|
1170 |
|
|
'#title' => t('Scientific name'),
|
1171 |
|
|
'#default_value' => $filter_presets['taxon_name'],
|
1172 |
|
|
'#size' => 20,
|
1173 |
|
|
'#maxlength' => 128
|
1174 |
|
|
);
|
1175 |
|
|
|
1176 |
|
|
$form['submit'] = array(
|
1177 |
|
|
'#type' => 'submit',
|
1178 |
|
|
'#attributes' => array('class' => array('fa-icon'), 'title' => t('Search')),
|
1179 |
|
|
'#value' => decode_entities(''), // fontawesome search icon
|
1180 |
|
|
// '#prefix' => "<div class=\"form-item\"><label> </label>",
|
1181 |
|
|
// '#suffix' => "</div>"
|
1182 |
|
|
|
1183 |
|
|
);
|
1184 |
|
|
return $form;
|
1185 |
|
|
}
|
1186 |
|
|
|
1187 |
a6ae799b
|
Andreas Kohlbecker
|
/**
|
1188 |
|
|
* Compose the result set of a registration search from a pager object
|
1189 |
|
|
*
|
1190 |
|
|
* @param $registration_pager
|
1191 |
|
|
* The pager containing registration objects
|
1192 |
|
|
*
|
1193 |
|
|
* @return
|
1194 |
|
|
* A drupal render array.
|
1195 |
|
|
*
|
1196 |
|
|
* @ingroup compose
|
1197 |
|
|
*
|
1198 |
|
|
* TODO compose function into search.inc ?
|
1199 |
|
|
*/
|
1200 |
24797d7f
|
Andreas Kohlbecker
|
function compose_registrations_search_results($registration_pager){
|
1201 |
a6ae799b
|
Andreas Kohlbecker
|
|
1202 |
|
|
$render_array = array();
|
1203 |
6789eff8
|
Andreas Kohlbecker
|
$render_array['pre'] = markup_to_render_array("<div class=\"cdm-item-list\">");
|
1204 |
0b494565
|
Andreas Kohlbecker
|
|
1205 |
|
|
if($registration_pager != null && count($registration_pager->records) > 0){
|
1206 |
a6ae799b
|
Andreas Kohlbecker
|
$items_render_array = array();
|
1207 |
26b8a1bc
|
Andreas Kohlbecker
|
foreach($registration_pager->records as $registration_dto) {
|
1208 |
|
|
|
1209 |
|
|
$items_render_array[] = array(
|
1210 |
|
|
'#prefix' => "<div class=\"item\"><div class=\"" . html_class_attribute_ref(new TypedEntityReference("Registration", $registration_dto->uuid)) . "\">",
|
1211 |
f461a488
|
Andreas Kohlbecker
|
'item_data' => compose_registration_dto_compact($registration_dto, 'item-style', 'div'),
|
1212 |
26b8a1bc
|
Andreas Kohlbecker
|
'#suffix' => "</div></div>"
|
1213 |
a6ae799b
|
Andreas Kohlbecker
|
);
|
1214 |
|
|
;
|
1215 |
|
|
}
|
1216 |
efbff4b3
|
Andreas Kohlbecker
|
|
1217 |
a6ae799b
|
Andreas Kohlbecker
|
$render_array['items'] = $items_render_array;
|
1218 |
|
|
$render_array['pager'] = markup_to_render_array(theme('cdm_pager', array(
|
1219 |
|
|
'pager' => $registration_pager,
|
1220 |
efbff4b3
|
Andreas Kohlbecker
|
'path' => $_REQUEST['q'], // stay on same page
|
1221 |
a6ae799b
|
Andreas Kohlbecker
|
'parameters' => $_REQUEST,
|
1222 |
|
|
)));
|
1223 |
|
|
|
1224 |
|
|
} else {
|
1225 |
0b494565
|
Andreas Kohlbecker
|
if($registration_pager != null && $registration_pager->count > 0 && count($registration_pager->records) == 0){
|
1226 |
|
|
$render_array['items'] = markup_to_render_array("<div id=\"no_results\">Result page out of range.</div>");
|
1227 |
|
|
} else {
|
1228 |
|
|
$render_array['items'] = markup_to_render_array("<div id=\"no_results\">No results found.</div>");
|
1229 |
|
|
}
|
1230 |
a6ae799b
|
Andreas Kohlbecker
|
}
|
1231 |
|
|
$render_array['post'] = markup_to_render_array("</div>");
|
1232 |
|
|
|
1233 |
|
|
return $render_array;
|
1234 |
|
|
|
1235 |
|
|
}
|