Project

General

Profile

Download (21.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Search related functions.
5
 */
6

    
7
/**
8
 * Returns a Drupal path to a search form for a CDM webservice.
9
 *
10
 * For a given CDM webservice end-point, the drupal page path to the
11
 * according search form is returned.
12
 * cdm webservice end points are defined in constant variables like:
13
 * <code>CDM_WS_PORTAL_TAXON_FIND</code> and
14
 * <code>CDM_WS_PORTAL_TAXON_FINDBY_DESCRIPTIONELEMENT_FULLTEXT</code>
15
 *
16
 * @param string $ws_endpoint
17
 *   The cdm webservice endpoint for which to find the search form path.
18
 *
19
 * @return string
20
 *   The Drupal path found.
21
 */
22
function cdm_dataportal_search_form_path_for_ws($ws_endpoint) {
23
  static $form_ws_map = array(
24
    CDM_WS_PORTAL_TAXON_FIND => "cdm_dataportal/search",
25
    CDM_WS_PORTAL_TAXON_SEARCH => "cdm_dataportal/search",
26
    CDM_WS_PORTAL_TAXON_FINDBY_DESCRIPTIONELEMENT_FULLTEXT => "cdm_dataportal/search/taxon_by_description",
27
  );
28
  return $form_ws_map[$ws_endpoint];
29
}
30

    
31
/**
32
 * Prepares a form array for a general purpose search form.
33
 *
34
 * The form is used for general purpose search functionality in the
35
 * dataportal. The form returned is populated with all nessecary fields
36
 * for internal processing and has the textfield element $form['query']
37
 * which holds the query term.
38
 * he sub tree array can be extended to contain additional search parameters.
39
 *
40
 * @param string $action_path
41
 *   The Drupal path to be put into the action url to which the form will
42
 *   be submitted.
43
 * @param string $search_webservice
44
 *   The cdm-remote webservice to be used, valid values are defined by
45
 *   the constants: FIXME.
46
 * @param string $query_field_default_value
47
 *   A default text for the query field
48
 * @param string $query_field_description
49
 *   The description text for the query field
50
 * @param string $process
51
 *   The value for #process, if NULL (default), 'cdm_dataportal_search_process'
52
 *   is used.
53
 *
54
 * @return array
55
 *   The prepared form array.
56
 */
57
function cdm_dataportal_search_form_prepare($action_path, $search_webservice, $query_field_default_value, $query_field_description, $process = NULL) {
58

    
59
  if ($process == NULL) {
60
    $process = 'cdm_dataportal_search_process';
61
  }
62

    
63
  $form['#method'] = 'get';
64
  //
65
  //  $form['#process'] = array(
66
  //  $process => array(),
67
  //  );
68
  //
69
  $form['#action'] = url($action_path, array(
70
    'absolute' => TRUE,
71
  ));
72

    
73
  $form['ws'] = array(
74
    '#type' => 'hidden',
75
    '#value' => $search_webservice,
76
    '#name' => 'ws',
77
  );
78

    
79
  $form['query'] = array(
80
    '#weight' => 0,
81
    '#type' => 'textfield',
82
    '#size' => 68,
83
    // This causes the description to display also when hovering over
84
    // the textfield.
85
    // This is wanted behaviour for the simple seach but could
86
    // be disabled for the advances search.
87
    '#attributes' => array(
88
      'title' => $query_field_description,
89
    ),
90
    '#description' => $query_field_description,
91
    '#value' => $query_field_default_value,
92
    // '#description' => $query_field_description,
93
  );
94
  if(variable_get('cdm_dataportal_taxon_auto_suggest')){
95
      $form['query']['#autocomplete_path'] = 'cdm_dataportal/taxonSearch/autocomplete';
96
  }
97

    
98
    $form['search'] = array(
99
    '#weight' => 3,
100
    '#tree' => TRUE,
101
    // '#type' => $advanced_form ? 'fieldset': 'hidden',
102
    '#title' => t('Options'),
103
  );
104

    
105
  // Clean URL get forms breaks if we don't give it a 'q'.
106
  if (!(bool) variable_get('clean_url', '0')) {
107
    $form['search']['q'] = array(
108
      '#type' => 'hidden',
109
      '#value' => $action_path,
110
      '#name' => 'q',
111
    );
112
  }
113

    
114
  $form['submit'] = array(
115
    '#weight' => 5,
116
    '#type' => 'submit',
117
    '#name' => '',
118
    '#value' => t('Search'),
119
  );
120

    
121
  return $form;
122
}
123

    
124
function cdm_dataportal_taxon_search_autocomplete($string) {
125
  $matches = array();
126

    
127
  $queryParams = array();
128
  $queryParams['query'] = $string."*";
129
  $queryParams['pageNumber'] = '0';
130
  $queryParams['pageSize'] = '100';
131
  $queryParams['doTaxa'] = true;
132
  $queryParams['doSynonyms'] = true;
133
  $queryParams['doMisappliedNames'] = true;
134
  $queryParams['doTaxaByCommonNames'] = true;
135

    
136
  $search_results = cdm_ws_get(CDM_WS_TAXON_SEARCH, NULL, queryString($queryParams));
137
  foreach($search_results->records as $record){
138
      $titleCache = $record->entity->titleCache;
139
      preg_match('/(.*) sec.*/', $titleCache, $trimmedTitle); //remove sec reference
140
      $trimmedTitle = trim($trimmedTitle[1]);
141
      $matches[$trimmedTitle] = $trimmedTitle;
142
  }
143
  drupal_json_output($matches);
144
}
145

    
146

    
147
  /**
148
 * Creates a search form for searching on taxa.
149
 *
150
 * If advanced $advanced_form id TRUE the form will offer additional choices
151
 *
152
 * @param array $form
153
 *   A drupal form array
154
 * @param array $form_state
155
 *   The drupal form state passed as reference
156
 * @param bool $advanced_form
157
 *   default is FALSE
158
 * @param bool $classification_select
159
 *   set TRUE to offer a classification selector in the form - default is FALSE
160
 *   if only available in the advanced mode
161
 *
162
 * @return array
163
 *   the form array
164
 */
165
function cdm_dataportal_search_taxon_form($form, &$form_state, $advanced_form = FALSE, $classification_select = TRUE) {
166

    
167
  $query_field_default_value = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
168

    
169
  if ($advanced_form || variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, FALSE)) {
170
    $search_service_endpoint = CDM_WS_PORTAL_TAXON_SEARCH;
171
  }
172
  else {
173
    $search_service_endpoint = CDM_WS_PORTAL_TAXON_FIND;
174
  }
175

    
176
  $form = cdm_dataportal_search_form_prepare(
177
    'cdm_dataportal/search/results/taxon',
178
    $search_service_endpoint,
179
    $query_field_default_value,
180
    t('Enter the name or part of a name you wish to search for.
181
      The asterisk  character * can be used as wildcard, but must not be used as first character.'),
182
      NULL
183
  );
184

    
185
  if (!$advanced_form) {
186
    $form['query']['#size'] = 20;
187
  }
188

    
189
  $form['search']['pageSize'] = array(
190
    '#weight' => -1,
191
    '#type' => 'hidden',
192
    '#value' => variable_get('cdm_dataportal_search_items_on_page', 25),
193
  );
194

    
195
  $form['search']['pageNumber'] = array(
196
    '#weight' => -1,
197
    '#type' => 'hidden',
198
    '#value' => 0,
199
  );
200

    
201
  $search_taxa_mode_settings = get_array_variable_merged(
202
    CDM_SEARCH_TAXA_MODE,
203
    CDM_SEARCH_TAXA_MODE_DEFAULT
204
  );
205
  $preset_do_taxa = $search_taxa_mode_settings['doTaxa'] !== 0;
206
  $preset_do_synonyms = $search_taxa_mode_settings['doSynonyms'] !== 0;
207
  $preset_do_taxa_by_common_names = $search_taxa_mode_settings['doTaxaByCommonNames'] !== 0;
208
  $preset_do_misapplied_names = $search_taxa_mode_settings['doMisappliedNames'] !== 0;
209

    
210
  if ($advanced_form) {
211

    
212
    // --- ADVANCED SEARCH FORM ---
213
    //
214

    
215
    // Get presets from settings.
216
    $preset_classification_uuid = get_current_classification_uuid();
217

    
218
    // Overwrite presets by user choice stored in session.
219
    if (isset($_SESSION['cdm']['search'])) {
220
      $preset_do_taxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
221
      $preset_do_synonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
222
      $preset_do_misapplied_names = (isset($_SESSION['cdm']['search']['doMisappliedNames']) ? 1 : 0);
223
      $preset_do_taxa_by_common_names = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
224
      if (isset($_SESSION['cdm']['search']['tree'])) {
225
        $preset_classification_uuid = $_SESSION['cdm']['search']['tree'];
226
      }
227
    }
228

    
229
    if ($classification_select === TRUE) {
230
      $form['search']['tree'] = array(
231
        '#title' => t('Classification'),
232
        '#weight' => 1,
233
        '#type' => 'select',
234
        '#default_value' => get_current_classification_uuid(),
235
        '#options' => cdm_get_taxontrees_as_options(TRUE),
236
        '#description' => t('A filter to limit the search to a specific classification. Choosing <em>--- ALL ---</em> will disable this filter.'),
237
      );
238
    }
239

    
240
    // General search parameters.
241
    $form['search']['doTaxa'] = array(
242
      '#weight' => 2,
243
      '#type' => 'checkbox',
244
      '#title' => t('Search for') . ' ' . t('accepted taxa'),
245
      '#value' => $preset_do_taxa,
246
    );
247
    $form['search']['doSynonyms'] = array(
248
      '#weight' => 3,
249
      '#type' => 'checkbox',
250
      '#title' => t('Search for') . ' ' . t('synonyms'),
251
      '#value' => $preset_do_synonyms,
252
    );
253
    $form['search']['doMisappliedNames'] = array(
254
      '#weight' => 4,
255
      '#type' => 'checkbox',
256
      '#title' => t('Search for') . ' ' . t('misapplied names'),
257
      '#value' => $preset_do_misapplied_names,
258
    );
259
    $form['search']['doTaxaByCommonNames'] = array(
260
      '#weight' => 5,
261
      '#type' => 'checkbox',
262
      '#title' => t('Search for') . ' ' . t('common names'),
263
      '#value' => $preset_do_taxa_by_common_names,
264
    );
265

    
266
    $area_term_dtos = cdm_ws_fetch_all(
267
      CDM_WS_DESCRIPTION_NAMEDAREAS_IN_USE,
268
      array('includeAllParents' => 'true')
269
    );
270

    
271
    // create map: term_uuid => term
272
    $term_map = array();
273
    foreach ($area_term_dtos as $term_dto) {
274
      $term_map[$term_dto->uuid] = $term_dto;
275
    }
276

    
277
    $term_tree = array();
278
    // mixed_vocabularies will contain the uuid vocabularies which
279
    // also contain terms of foreign vocabularies due to the term
280
    // hierarchy
281
    $mixed_vocabularies = array();
282

    
283
    // Build hierarchy of the terms regardless of the vocabulary.
284
    foreach ($term_map as $term_dto) {
285
      if (!empty($term_dto->partOfUuid)) {
286
        // Children.
287
        $parent =& $term_map[$term_dto->partOfUuid];
288
        if ($parent) {
289
          if (!isset($parent->children)) {
290
            $parent->children = array();
291
          }
292
          $parent->children[$term_dto->uuid] = $term_dto;
293
          if ($parent->vocabularyUuid != $term_dto->vocabularyUuid) {
294
            $mixed_vocabularies[$parent->vocabularyUuid] = $parent->vocabularyUuid;
295
          }
296
        }
297
      }
298
      else {
299
        // group root nodes by vocabulary
300
        if (!isset($term_tree[$term_dto->vocabularyUuid])) {
301
          $term_tree[$term_dto->vocabularyUuid] = array();
302
        }
303
        $term_tree[$term_dto->vocabularyUuid][$term_dto->uuid] = $term_dto;
304
      }
305
    }
306

    
307
    $show_area_filter = ! variable_get(CDM_SEARCH_AREA_FILTER_PRESET, '');
308

    
309
    if($show_area_filter){
310
      drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/search_area_filter.js');
311

    
312
      drupal_add_js('jQuery(document).ready(function() {
313
        jQuery(\'#edit-search-areas\').search_area_filter(\'#edit-search-areas-areas-filter\');
314
      });
315
      ', array('type' => 'inline'));
316

    
317
      $form['search']['areas'] = array(
318
        '#type' => 'fieldset',
319
        '#title' => t('Filter by distribution areas'),
320
        '#description' => t('The search will return taxa having distribution
321
        information for at least one of the selected areas.') . ' '
322
          .(count($term_tree) > 1 ? t('The areas are grouped
323
        by the vocabularies to which the highest level areas belong.') : ''),
324
      );
325
      $form['search']['areas']['areas_filter'] = array(
326
        '#type' => 'textfield',
327
        '#description' => t('Type to filter the areas listed below.'),
328
      );
329
      $vocab_cnt = 0;
330
      $areas_defaults = array();
331
      if (isset($_SESSION['cdm']['search']['area'])) {
332
        $areas_defaults = explode(',', $_SESSION['cdm']['search']['area']);
333
      }
334
      foreach ($term_tree as $vocab_uuid => $term_dto_tree) {
335
        $vocabulary = cdm_ws_get(CDM_WS_TERMVOCABULARY, array($vocab_uuid));
336
        $areas_options = term_tree_as_options($term_dto_tree);
337
        $form['search']['areas']['area'][$vocab_cnt++] = array(
338
          '#prefix' => '<strong>' . $vocabulary->representation_L10n
339
            . (isset($mixed_vocabularies[$vocab_uuid]) ? ' <span title="Contains terms of at least one other area vocabulary.">(' . t('mixed') . ')</span>': '')
340
            . '</strong>',
341
          '#type' => 'checkboxes',
342
          '#default_value' => $areas_defaults,
343
          '#options' => $areas_options,
344
        );
345
      }
346
    }
347

    
348
  }
349
  else {
350
    // --- SIMPLE SEARCH FORM ---
351
    //
352

    
353
    // Overwrite presets by user choice stored in session.
354
    if (isset($_SESSION['cdm']['search'])) {
355
      $preset_do_misapplied_names = (isset($_SESSION['cdm']['search']['doMisappliedNames']) ? 1 : 0);
356
    }
357

    
358
    $form['search']['doTaxa'] = array(
359
      '#weight' => -2,
360
      '#type' => 'hidden',
361
      '#value' => $preset_do_taxa,
362
    );
363
    $form['search']['doSynonyms'] = array(
364
      '#weight' => -3,
365
      '#type' => 'hidden',
366
      '#value' => $preset_do_synonyms,
367
    );
368
    $form['search']['doMisappliedNames'] = array(
369
      '#weight' => -4,
370
      '#type' => 'checkbox',
371
      '#title' => t('Misapplied names'),
372
      '#value' => $preset_do_misapplied_names,
373
    );
374
    $form['search']['doTaxaByCommonNames'] = array(
375
      '#weight' => -5,
376
      '#type' => 'hidden',
377
      '#value' => $preset_do_taxa_by_common_names,
378
    );
379
  }
380

    
381
  return $form;
382
}
383

    
384
/**
385
 * Wrapper function for cdm_dataportal_search_taxon_form().
386
 *
387
 * This function makes ot possible possible to just pass the
388
 * correct $form_id 'cdm_dataportal_search_taxon_form_advanced' to
389
 * drupal_get_form like:
390
 * drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
391
 *
392
 * @param array $form
393
 *   A drupal form array
394
 * @param array $form_state
395
 *   The drupal form state passed as reference
396
 *
397
 * @return array
398
 *   The form array
399
 */
400
function cdm_dataportal_search_taxon_form_advanced($form, &$form_state) {
401
  return cdm_dataportal_search_taxon_form($form, $form_state, TRUE);
402
}
403

    
404
/**
405
 * Form for searching taxa by the findByDescriptionElementFullText rest service.
406
 */
407
function cdm_dataportal_search_taxon_by_description_form() {
408
  $query_field_default_value = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
409

    
410
  $form = cdm_dataportal_search_form_prepare(
411
    'cdm_dataportal/search/results/taxon',
412
    CDM_WS_PORTAL_TAXON_FINDBY_DESCRIPTIONELEMENT_FULLTEXT,
413
    $query_field_default_value,
414
    t("Enter the text you wish to search for. The asterisk character * can be
415
        used as wildcard, but must not be used as first character. Terms can be combined with 'AND'. To search for a
416
        full phrase enclose the terms in parentheses. For more syntactical
417
        options please refer to the !link.",
418
      array(
419
        '!link' => l(
420
          t('Apache Lucene - Query Parser Syntax'),
421
          'http://lucene.apache.org/core/old_versioned_docs/versions/2_9_1/queryparsersyntax.html', array(
422
            'attributes' => array(
423
              'absolute' => TRUE,
424
              'html' => TRUE),
425
          )
426
        ),
427
      )
428
    ),
429
    NULL
430
  );
431

    
432
  $form['search']['tree'] = array(
433
    '#weight' => -1,
434
    '#type' => 'hidden',
435
    '#value' => get_current_classification_uuid(),
436
  );
437

    
438
  $form['search']['hl'] = array(
439
    '#weight' => -1,
440
    '#type' => 'hidden',
441
    '#value' => 1,
442
  );
443

    
444
  // Only available to admins:
445
  if (!isset($_SESSION['cdm']['search']['clazz'])) {
446
    $_SESSION['cdm']['search']['clazz'] = '';
447
  }
448
  if (module_exists("user") && user_access('administer')) {
449
    $form['search']['clazz'] = array(
450
      '#type' => 'select',
451
      '#title' => t('Limit to description item type'),
452
      '#default_value' => $_SESSION['cdm']['search']['clazz'],
453
      '#options' => cdm_descriptionElementTypes_as_option(TRUE),
454
    );
455
  }
456

    
457
  $profile_feature_tree = get_profile_feature_tree();
458
  $feature_options = _featureTree_nodes_as_feature_options($profile_feature_tree->root);
459
  if (isset($_SESSION['cdm']['search']['features'])) {
460
    $form['search']['features'] = array(
461
      '#type' => 'checkboxes',
462
      '#title' => t('Limit to selected features'),
463
      '#default_value' => $_SESSION['cdm']['search']['features'],
464
      '#options' => $feature_options,
465
    );
466
  }
467
  else {
468
    $form['search']['features'] = array(
469
      '#type' => 'checkboxes',
470
      '#title' => t('Limit to selected features'),
471
      '#options' => $feature_options,
472
    );
473
  }
474
  return $form;
475
}
476

    
477
/**
478
 * Processes the query parameters of the search form.
479
 *
480
 * Reads the query parameters from $_REQUEST and modifies and adds additional
481
 * query parameters if nessecary.
482
 *
483
 *  - Filters $_REQUEST by a list of valid request parameters
484
 *  - modifies geographic_range parameters
485
 *  - adds taxon tree uuid if it is missing and if it should not be
486
 *    ignored (parameter value = 'IGNORE')
487
 *  - and more
488
 *
489
 *
490
 * @return array
491
 *   the processed request parameters submitted by the search form and
492
 *   also stores them in $_SESSION['cdm']['search']
493
 */
494
function cdm_dataportal_search_form_request()
495
{
496

    
497
  $form_params = array();
498

    
499
  if (isset($_REQUEST['search']) && is_array($_REQUEST['search'])) {
500
    array_deep_copy($_REQUEST['search'], $form_params);
501
  }
502

    
503
  if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
504
    $form_params = array_merge($form_params, $_REQUEST['pager']);
505
  }
506

    
507
  $form_params['query'] = trim($_REQUEST['query']);
508

    
509
  // --- handle geographic range
510
  // Split of geographic range.
511
  unset($form_params['areas']);
512

    
513
  $area_filter_preset = null;
514
  if (variable_get(CDM_SEARCH_AREA_FILTER_PRESET, '')) {
515
    $area_filter_preset = explode(',', variable_get(CDM_SEARCH_AREA_FILTER_PRESET, ''));
516
  }
517

    
518
  $area_uuids = array();
519
  if($area_filter_preset){
520
    $area_uuids = $area_filter_preset;
521
  }
522
  elseif (isset($_REQUEST['search']['areas']['area']) && is_array($_REQUEST['search']['areas']['area'])) {
523
    foreach ($_REQUEST['search']['areas']['area'] as $areas) {
524
      $area_uuids = array_merge($area_uuids, $areas);
525
    }
526
  }
527
  if(count($area_uuids) > 0){
528
    $form_params['area'] = implode(',', $area_uuids);
529
  }
530

    
531
  // Simple search will not submit a 'tree' query parameter,
532
  // so we add it here from what is stored in the session unless
533
  // SIMPLE_SEARCH_IGNORE_CLASSIFICATION is checked in the settings.
534
  if (!isset($form_params['tree']) && !variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0)) {
535
    $form_params['tree'] = get_current_classification_uuid();
536
  }
537
  // If the 'NONE' classification has been chosen (adanced search)
538
  // delete the tree information to avoid unknown uuid exceptions in the
539
  // cdm service.
540
  if (isset($form_params['tree'])
541
    && ($form_params['tree'] == 'NONE' || !is_uuid($form_params['tree']))
542
  ) {
543
    // $form_params['ignore_classification'] =  TRUE;
544
    unset($form_params['tree']);
545
  }
546
  // else {
547
  //   $form_params['ignore_classification'] =  NULL;
548
  // }
549

    
550
  // Store in session.
551
  $_SESSION['cdm']['search'] = $form_params;
552

    
553
  return $form_params;
554
}
555

    
556
/**
557
 * Provides the classification to which the last search has been limited to..
558
 *
559
 * This function should only be used after the cdm_dataportal_search_execute()
560
 * handler has been run, otherwise it will return the infomation from the last
561
 * search executed. The information is retrieved from
562
 * the $_SESSION variable:  $_SESSION['cdm']['search']['tree']
563
 *
564
 * @return object
565
 *   the CDM classification instance which has been used a filter for the
566
 *   last processed search
567
 *   or NULL, it it was on all classifications
568
 */
569
function cdm_dataportal_searched_in_classification() {
570

    
571
  $classification = &drupal_static(__FUNCTION__);
572

    
573
  if (!isset($classification)) {
574
    if (isset($_SESSION['cdm']['search']['tree'])) {
575
      $classification = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY, ($_SESSION['cdm']['search']['tree']));
576
    }
577
    else {
578
      $classification = FALSE;
579
    }
580
  }
581

    
582
  return $classification !== FALSE ? $classification : NULL;
583
}
584

    
585
/**
586
 * Removes Drupal internal form elements from query.
587
 */
588
function cdm_dataportal_search_process($form, &$form_state) {
589
  unset($form['form_id']);
590
  unset($form['form_token']);
591
  return $form;
592
}
593

    
594
/**
595
 * Sends a search request at the cdm web server.
596
 *
597
 * The parameters to build the query are taken obtained by calling
598
 * cdm_dataportal_search_form_request() which reads the query parameters
599
 * from $_REQUEST and add additional query parameters if nessecary.
600
 *
601
 * @see cdm_dataportal_search_form_request()
602
 */
603
function cdm_dataportal_search_execute() {
604

    
605
  // Store as last search in session.
606
  $_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
607

    
608
  // Validate the search webservice parameter:
609
  if (!isset($_REQUEST['ws'])) {
610
    drupal_set_message(
611
      t("Invalid search webservice parameter 'ws' given"), 'warning'
612
    );
613
    return NULL;
614
  }
615
  if (!cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
616
    // Endpoint is unknown.
617
    drupal_set_message(
618
      t("Invalid search webservice parameter 'ws' given"), 'warning'
619
    );
620
    return NULL;
621
  }
622

    
623
  // Read the query parameters from $_REQUEST and add additional query
624
  // parameters if necessary.
625
  $request_params = cdm_dataportal_search_form_request();
626

    
627
  $taxon_pager = cdm_ws_get($_REQUEST['ws'], NULL, queryString($request_params));
628

    
629
  return $taxon_pager;
630
}
631

    
632
/**
633
 * Transforms the termDTO tree into options array.
634
 *
635
 *   TermDto:
636
 *      - partOfUuid:
637
 *      - representation_L10n:
638
 *      - representation_L10n_abbreviatedLabel:
639
 *      - uuid:
640
 *      - vocabularyUuid:
641
 *      - children: array of TermDto
642
 *
643
 * The options array is suitable for drupal form API elements that
644
 * allow multiple choices.
645
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#options
646
 *
647
 * @param array $term_dto_tree
648
 *   a hierarchic array of CDM TermDto instances, with additional
649
 * 'children' field:
650
 * @param array $options
651
 *   Internally used for recursive calls
652
 * @param string $prefix
653
 *   Internally used for recursive calls
654
 *
655
 * @return array
656
 *   the terms in an array as options for a form element that allows
657
 *   multiple choices.
658
 */
659
function term_tree_as_options($term_dto_tree, &$options = array(), $prefix = '') {
660

    
661
  foreach ($term_dto_tree as $uuid => $dto) {
662
    $label = $prefix . '<span class="child-label">'
663
      .  $dto->representation_L10n
664
      . '</span><span class="child-label-abbreviated"> (' . $dto->representation_L10n_abbreviatedLabel . ')</span>';
665
    $options[$uuid] = $label;
666
    if (isset($dto->children) && is_array($dto->children)) {
667
      uasort($dto->children, 'compare_terms_by_representationL10n');
668
      term_tree_as_options(
669
        $dto->children,
670
        $options, $prefix
671
          . '<span data-cdm-parent="' . $uuid . '" class="parent"></span>');
672
    }
673
  }
674

    
675
  return $options;
676
}
(11-11/16)