1
|
<?php
|
2
|
// $Id$
|
3
|
|
4
|
/*
|
5
|
* @file
|
6
|
* cdm_dataportal
|
7
|
*
|
8
|
* Copyright (C) 2007 EDIT
|
9
|
* European Distributed Institute of Taxonomy
|
10
|
* http://www.e-taxonomy.eu
|
11
|
*
|
12
|
*/
|
13
|
|
14
|
require_once('cdm_dataportal.theme.php');
|
15
|
|
16
|
define(CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE, 25);
|
17
|
|
18
|
/* ====================== hook implementations ====================== */
|
19
|
|
20
|
/**
|
21
|
* Implementation of hook_help()
|
22
|
*
|
23
|
* Display help and module information
|
24
|
* @param section which section of the site we're displaying help
|
25
|
* @return help text for section
|
26
|
*/
|
27
|
function cdm_dataportal_help($section='') {
|
28
|
|
29
|
$out = '';
|
30
|
switch ($section) {
|
31
|
case "admin/modules#description":
|
32
|
$out = t("The dataportal publishes CDM data hosted in a CommunityStore on the web.");
|
33
|
break;
|
34
|
}
|
35
|
return $out;
|
36
|
}
|
37
|
|
38
|
|
39
|
/**
|
40
|
* Implementation of hook_perm()
|
41
|
*
|
42
|
* Valid permissions for this module
|
43
|
* @return array An array of valid permissions for the portfolio module
|
44
|
*/
|
45
|
function cdm_dataportal_perm() {
|
46
|
return array(
|
47
|
'administer cdm_dataportal',
|
48
|
'cdm_dataportal view notes',
|
49
|
//TODO which else permission are required? -> check the WP6 requirements document
|
50
|
);
|
51
|
}
|
52
|
|
53
|
|
54
|
/**
|
55
|
* Implementation of hook_menu()
|
56
|
*/
|
57
|
function cdm_dataportal_menu($may_cache) {
|
58
|
$items = array();
|
59
|
|
60
|
if ($may_cache) {
|
61
|
|
62
|
$items[] = array(
|
63
|
'path' => 'admin/settings/cdm_dataportal',
|
64
|
'title' => t('CDM Dataportal'),
|
65
|
'description' => t('Setting for the CDM Dataportal'),
|
66
|
'access' => user_access('administer cdm_dataportal'),
|
67
|
'callback' => 'drupal_get_form',
|
68
|
'callback arguments' => 'cdm_dataportal_settings',
|
69
|
);
|
70
|
|
71
|
/*$items[] = array(
|
72
|
'path' => 'admin/settings/cdm_dataportal/ws',
|
73
|
'title' => t('Web Service'),
|
74
|
'description' => t('Setting for the CDM Dataportal'),
|
75
|
'access' => user_access('administer cdm_dataportal'),
|
76
|
'callback' => 'drupal_get_form',
|
77
|
'callback arguments' => 'cdm_dataportal_settings',
|
78
|
'weight' => 1,
|
79
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
80
|
);*/
|
81
|
|
82
|
$items[] = array(
|
83
|
'path' => 'cdm_dataportal/names',
|
84
|
'callback' => 'cdm_dataportal_view_names',
|
85
|
'access' => true,
|
86
|
'type' => MENU_CALLBACK,
|
87
|
);
|
88
|
// optional callback arguments: page
|
89
|
|
90
|
$items[] = array(
|
91
|
'path' => 'cdm_dataportal/taxon',
|
92
|
'callback' => 'cdm_dataportal_view_taxon',
|
93
|
'access' => true,
|
94
|
'type' => MENU_CALLBACK,
|
95
|
// expected callback arguments: name_uuid
|
96
|
);
|
97
|
|
98
|
$items[] = array(
|
99
|
'path' => 'cdm_dataportal/reference',
|
100
|
'callback' => 'cdm_dataportal_view_reference',
|
101
|
'access' => true,
|
102
|
'type' => MENU_CALLBACK,
|
103
|
// expected callback arguments: name_uuid
|
104
|
);
|
105
|
|
106
|
$items[] = array(
|
107
|
'path' => 'cdm_dataportal/reference/list',
|
108
|
'callback' => 'cdm_dataportal_view_reference_list',
|
109
|
'access' => true,
|
110
|
'type' => MENU_CALLBACK,
|
111
|
// expected callback arguments: name_uuid
|
112
|
);
|
113
|
|
114
|
$items[] = array(
|
115
|
'path' => 'cdm_dataportal/search',
|
116
|
'callback' => 'cdm_dataportal_view_search_advanced',
|
117
|
'access' => true,
|
118
|
'type' => MENU_CALLBACK,
|
119
|
);
|
120
|
|
121
|
$items[] = array(
|
122
|
'path' => 'cdm_dataportal/search/taxon',
|
123
|
'callback' => 'cdm_dataportal_view_search_taxon',
|
124
|
'access' => true,
|
125
|
'type' => MENU_CALLBACK,
|
126
|
);
|
127
|
|
128
|
$items[] = array(
|
129
|
'path' => 'cdm/xml2json',
|
130
|
'callback' => 'cdm_view_xml2json',
|
131
|
'access' => true,
|
132
|
'type' => MENU_CALLBACK,
|
133
|
);
|
134
|
|
135
|
|
136
|
} else {
|
137
|
// may not cache
|
138
|
// --- local tasks for Taxon
|
139
|
if(variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
|
140
|
|
141
|
$items[] = array(
|
142
|
'path' => 'cdm_dataportal/taxon/'.arg(2),
|
143
|
'title' => theme('cdm_taxonpage_tab', 'General'),
|
144
|
'callback' => 'cdm_dataportal_view_taxon',
|
145
|
'access' => true,
|
146
|
'type' => MENU_CALLBACK,
|
147
|
'weight' => 1,
|
148
|
'callback arguments' => array(arg(2), "description")
|
149
|
// expected callback arguments: name_uuid
|
150
|
);
|
151
|
|
152
|
$items[] = array(
|
153
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/description',
|
154
|
'title' => theme('cdm_taxonpage_tab', 'General'),
|
155
|
'callback' => 'cdm_dataportal_view_taxon',
|
156
|
'access' => true,
|
157
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
158
|
'weight' => 2,
|
159
|
'callback arguments' => array(arg(2), "description")
|
160
|
// expected callback arguments: name_uuid
|
161
|
);
|
162
|
|
163
|
$items[] = array(
|
164
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/synonymy',
|
165
|
'title' => theme('cdm_taxonpage_tab', 'Synonymy'),
|
166
|
'callback' => 'cdm_dataportal_view_taxon',
|
167
|
'access' => true,
|
168
|
'type' => MENU_LOCAL_TASK,
|
169
|
'weight' => 3,
|
170
|
'callback arguments' => array(arg(2), "synonymy")
|
171
|
// expected callback arguments: name_uuid
|
172
|
);
|
173
|
|
174
|
$items[] = array(
|
175
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/images',
|
176
|
'title' => theme('cdm_taxonpage_tab', 'Images'),
|
177
|
'callback' => 'cdm_dataportal_view_taxon',
|
178
|
'access' => true,
|
179
|
'type' => MENU_LOCAL_TASK,
|
180
|
'weight' => 4,
|
181
|
'callback arguments' => array(arg(2), "images")
|
182
|
// expected callback arguments: name_uuid
|
183
|
);
|
184
|
}
|
185
|
}
|
186
|
|
187
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
|
188
|
//drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
|
189
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
|
190
|
|
191
|
return $items;
|
192
|
|
193
|
}
|
194
|
|
195
|
/**
|
196
|
* Implementation of hook_block()
|
197
|
*
|
198
|
* Provides the following blocks:
|
199
|
* 0: list of links useful during development
|
200
|
*
|
201
|
* @param String $op
|
202
|
* @param int $delta
|
203
|
*/
|
204
|
function cdm_dataportal_block($op='list', $delta=0) {
|
205
|
// listing of blocks, such as on the admin/block page
|
206
|
if ($op == "list") {
|
207
|
$block[0]["info"] = t("CDM DataPortal DevLinks");
|
208
|
$block[1]["info"] = t("CDM DataPortal Credits");
|
209
|
$block[2]["info"] = t("CDM Search Taxa");
|
210
|
$block[3]["info"] = t("CDM Filters");
|
211
|
return $block;
|
212
|
}
|
213
|
else if ($op == 'view') {
|
214
|
switch($delta){
|
215
|
case 1:
|
216
|
$block['subject'] = t('Credits');
|
217
|
$block['content'] = theme('cdm_credits');
|
218
|
return $block;
|
219
|
case 2:
|
220
|
$block['subject'] = t('Search Taxa');
|
221
|
$block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
|
222
|
$block['content'] .= '<div>'.l('Advanced Search', '/cdm_dataportal/search').'</div>';
|
223
|
return $block;
|
224
|
}
|
225
|
}
|
226
|
}
|
227
|
|
228
|
|
229
|
/**
|
230
|
* Implementation of hook_validate()
|
231
|
*
|
232
|
* @param $element
|
233
|
*/
|
234
|
function cdm_dataportal_settings_validate($form_id, $form_values){
|
235
|
|
236
|
if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
|
237
|
form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
|
238
|
}
|
239
|
|
240
|
$cdm_webservice_url_changed = variable_get('cdm_webservice_url', '') != $form_values['cdm_webservice_url'];
|
241
|
|
242
|
$cdm_secUuid_default_changed = variable_get('cdm_secUuid_default', '') != $form_values['cdm_secUuid_default'];
|
243
|
|
244
|
if ($cdm_webservice_url_changed || $cdm_secUuid_default_changed) {
|
245
|
|
246
|
_cdm_dataportal_set_currentSecUuid($form_values['cdm_secUuid_default']);
|
247
|
// reset all cdm related data stored in the session
|
248
|
// cdm_dataportal_session_clear($form_values['cdm_webservice_url']); // cdm_webservice_url is not further stored here
|
249
|
// clear the cdm webservice cache
|
250
|
cache_clear_all(NULL, 'cache_cdm_ws');
|
251
|
// better clear secref_cache since i can not be sure if the cache has not be used during this response
|
252
|
cdm_api_secref_cache_clear();
|
253
|
}
|
254
|
if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
|
255
|
cache_clear_all(NULL, 'cache_cdm_ws');
|
256
|
// better clear secref_cache since i can not be sure if the cache has not be used during this response
|
257
|
cdm_api_secref_cache_clear();
|
258
|
}
|
259
|
|
260
|
}
|
261
|
|
262
|
/*
|
263
|
function cdm_dataportal_session_clear($cdm_ws_uri_update = false){
|
264
|
$_SESSION['cdm'] = null;
|
265
|
if(is_string($cdm_ws_uri_update)){
|
266
|
$_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
|
267
|
}
|
268
|
}
|
269
|
|
270
|
function cdm_dataportal_session_validate(){
|
271
|
|
272
|
if(!isset($_SESSION['cdm']['ws_uri'])){
|
273
|
$_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', false));
|
274
|
} else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', false)){
|
275
|
cdm_dataportal_session_clear(variable_get('cdm_webservice_url', false));
|
276
|
}
|
277
|
}
|
278
|
*/
|
279
|
|
280
|
function cdm_dataportal_search_taxon_form($advancedForm = false){
|
281
|
|
282
|
$preset_query = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
|
283
|
$preset_doTaxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
|
284
|
$preset_doSynonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
|
285
|
$preset_doTaxaByCommonNames = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
|
286
|
$tdwg_level_select = (isset($_SESSION['cdm']['search']['tdwg_level_select']) ? $_SESSION['cdm']['search']['tdwg_level_select'] : 2);
|
287
|
$selected_areas = (isset($_SESSION['cdm']['search']['area']) ? $_SESSION['cdm']['search']['area'] : false);
|
288
|
|
289
|
$url = 'cdm_dataportal/search/taxon';
|
290
|
$form['#method'] = 'get';
|
291
|
$form['#process'] = array('cdm_dataportal_search_process' => array());
|
292
|
$form['#action'] = url($url, NULL, NULL, true);
|
293
|
|
294
|
$form['query'] = array(
|
295
|
'#delta' => 0,
|
296
|
'#type' => 'textfield',
|
297
|
'#size' => 20,
|
298
|
'#attributes' => array('title' => t('Enter the name or part of a name you wish to search for. The asterisk character * can always be used as wildcard')),
|
299
|
'#value' => $preset_query,
|
300
|
);
|
301
|
|
302
|
$form['search'] = array(
|
303
|
'#delta' => 1,
|
304
|
'#tree' => true,
|
305
|
//'#type' => $advancedForm ? 'fieldset': 'hidden',
|
306
|
'#title' => t('Options')
|
307
|
);
|
308
|
|
309
|
$form['search']['tree'] = array(
|
310
|
'#delta' => -1,
|
311
|
'#type' => 'hidden',
|
312
|
'#value' => variable_get('cdm_taxonomictree_uuid', false)
|
313
|
);
|
314
|
|
315
|
|
316
|
// clean URL get forms breaks if we don't give it a 'q'.
|
317
|
if (!(bool)variable_get('clean_url', '0')) {
|
318
|
$form['search']['q'] = array(
|
319
|
'#delta' => -1,
|
320
|
'#type' => 'hidden',
|
321
|
'#value' => $url,
|
322
|
'#name' => 'q',
|
323
|
);
|
324
|
}
|
325
|
|
326
|
$form['search']['pageSize'] = array(
|
327
|
'#delta' => -1,
|
328
|
'#type' => 'hidden',
|
329
|
'#value' => variable_get('cdm_dataportal_search_items_on_page', 25)
|
330
|
);
|
331
|
|
332
|
if($advancedForm){
|
333
|
// general search parameters
|
334
|
$form['search']['doTaxa'] = array(
|
335
|
'#delta' => 2,
|
336
|
'#type' => 'checkbox',
|
337
|
'#title' => t('Search for accepted taxa'),
|
338
|
'#value' => $preset_doTaxa
|
339
|
);
|
340
|
$form['search']['doSynonyms'] = array(
|
341
|
'#delta' => 3,
|
342
|
'#type' => 'checkbox',
|
343
|
'#title' => t('Search for synonyms'),
|
344
|
'#value' => $preset_doSynonyms
|
345
|
);
|
346
|
$form['search']['doTaxaByCommonNames'] = array(
|
347
|
'#delta' => 4,
|
348
|
'#type' => 'checkbox',
|
349
|
'#title' => t('Search for common names'),
|
350
|
'#value' => $preset_doTaxaByCommonNames
|
351
|
);
|
352
|
|
353
|
// Geographic Range
|
354
|
$form['search']['geographic_range'] = array(
|
355
|
'#type' => 'fieldset',
|
356
|
'#delta' => 5,
|
357
|
'#tree' => true,
|
358
|
'#title' => t('Geographic range'),
|
359
|
);
|
360
|
|
361
|
$form['search']['geographic_range']['tdwg_level_select'] = array(
|
362
|
'#type' => 'radios',
|
363
|
'#title' => t('Select a TDWG distribution level and code:'),
|
364
|
'#default_value' => $tdwg_level_select,
|
365
|
'#options' => array(
|
366
|
t('TDWG level-1, i.e. a continent'),
|
367
|
t('TDWG level-2'),
|
368
|
t('TDWG level-3, i.e. a country'),
|
369
|
t('TDWG level-4')
|
370
|
)
|
371
|
);
|
372
|
$tdwg[1] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '1');
|
373
|
$tdwg[2] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '2');
|
374
|
$tdwg[3] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '3');
|
375
|
$tdwg[4] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '4');
|
376
|
|
377
|
$tdwg_js = '';
|
378
|
foreach($tdwg as $key=>$tdwg_level){
|
379
|
$tdwgOptions = array();
|
380
|
$tdwgOptionsSelected = array();
|
381
|
foreach($tdwg_level as $area){
|
382
|
$representation = $area->representations[0];
|
383
|
$tdwgOptions[$representation->abbreviatedLabel] = $area->representation_L10n;
|
384
|
if(is_array($selected_areas) && in_array($representation->abbreviatedLabel, $selected_areas)){
|
385
|
$tdwgOptionsSelected[] = $representation->abbreviatedLabel; //$area->uuid;
|
386
|
}
|
387
|
}
|
388
|
asort($tdwgOptions);
|
389
|
$form['search']['geographic_range']['tdwg_level_'.$key] = array(
|
390
|
'#type' => 'select',
|
391
|
'#title' => t('TDWG level').' '.$key,
|
392
|
'#default_value' => $tdwgOptionsSelected,
|
393
|
'#multiple' => TRUE,
|
394
|
'#options' => $tdwgOptions
|
395
|
);
|
396
|
$tdwg_js .= "$('#edit-search-geographic-range-tdwg-level-$key').parent()".($tdwg_level_select + 1 == $key ? '.show()' : '.hide()'). ";\n";
|
397
|
}
|
398
|
|
399
|
drupal_add_js(
|
400
|
"$(document).ready(function(){
|
401
|
|
402
|
$(\"input[@name='search[geographic_range][tdwg_level_select]']\").change(
|
403
|
function(event){
|
404
|
var selectId = $(\"input[@name='search[geographic_range][tdwg_level_select]']:checked\").val();
|
405
|
var i;
|
406
|
for(i = 0; i < 4; i++){
|
407
|
if(selectId == i){
|
408
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1) ).parent().fadeIn('slow');
|
409
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
|
410
|
} else {
|
411
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1)).parent().fadeOut('slow');
|
412
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
|
413
|
}
|
414
|
}
|
415
|
}
|
416
|
);
|
417
|
|
418
|
$tdwg_js
|
419
|
});",
|
420
|
'inline');
|
421
|
|
422
|
} else {
|
423
|
$form['search']['doTaxa'] = array(
|
424
|
'#delta' => -2,
|
425
|
'#type' => 'hidden',
|
426
|
'#value' => 1
|
427
|
);
|
428
|
$form['search']['doSynonyms'] = array(
|
429
|
'#delta' => -3,
|
430
|
'#type' => 'hidden',
|
431
|
'#value' => 1
|
432
|
);
|
433
|
$form['search']['doTaxaByCommonNames'] = array(
|
434
|
'#delta' => -4,
|
435
|
'#type' => 'hidden',
|
436
|
'#value' => 1
|
437
|
);
|
438
|
}
|
439
|
|
440
|
$form['submit'] = array(
|
441
|
'#delta' => 9,
|
442
|
'#type' => 'submit',
|
443
|
'#name' => '',
|
444
|
'#value' => t('Search')
|
445
|
);
|
446
|
|
447
|
return $form;
|
448
|
}
|
449
|
|
450
|
function cdm_dataportal_search_taxon_form_advanced(){
|
451
|
return cdm_dataportal_search_taxon_form(true);
|
452
|
}
|
453
|
|
454
|
/**
|
455
|
* Implementation #process method call, see form_builder()
|
456
|
* <p>
|
457
|
* Removes Drupal internal form elements from query
|
458
|
* @param $form
|
459
|
* @return unknown_type
|
460
|
*/
|
461
|
function cdm_dataportal_search_process($form) {
|
462
|
unset($form['form_id']);
|
463
|
unset($form['form_token']);
|
464
|
return $form;
|
465
|
}
|
466
|
|
467
|
/**
|
468
|
* Filters $_REQUEST by a list of valid request parameters and also sets defaults if required.
|
469
|
* returns the processed request parameters submitted by the search form.
|
470
|
*/
|
471
|
function cdm_dataportal_search_form_request(){
|
472
|
|
473
|
|
474
|
$form_params = array();
|
475
|
array_deep_copy($_REQUEST['search'], $form_params);
|
476
|
$form_params['query'] = trim($_REQUEST['query']);
|
477
|
|
478
|
// split of geographic range
|
479
|
if(isset($_REQUEST['search']['geographic_range'])){
|
480
|
$geographicRange = $_REQUEST['search']['geographic_range'];
|
481
|
// remove
|
482
|
unset($form_params['geographic_range']);
|
483
|
}
|
484
|
|
485
|
// add geographic range
|
486
|
if($geographicRange){
|
487
|
$form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
|
488
|
for($i = 1; $i < 5; $i++){
|
489
|
if(isset($geographicRange['tdwg_level_'.$i])){
|
490
|
$form_params['area'] = $geographicRange['tdwg_level_'.$i];
|
491
|
}
|
492
|
}
|
493
|
}
|
494
|
|
495
|
// store in session
|
496
|
$_SESSION['cdm']['search'] = $form_params;
|
497
|
|
498
|
return $form_params;
|
499
|
}
|
500
|
|
501
|
|
502
|
/* UNREACHABLE since action of form directly links to view
|
503
|
function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
|
504
|
|
505
|
$_SESSION['cdm']['search'] = $form_values;
|
506
|
//return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
|
507
|
return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
|
508
|
//$paramstr = compose_url_prameterstr($form_values);
|
509
|
//return url('/cdm_dataportal/search/taxon/', $paramstr);
|
510
|
}
|
511
|
*/
|
512
|
/* ====================== menu callback functions ====================== */
|
513
|
|
514
|
/**
|
515
|
* Generate main administration form.
|
516
|
*
|
517
|
* @return
|
518
|
* An array containing form items to place on the module settings page.
|
519
|
*/
|
520
|
function cdm_dataportal_settings(){
|
521
|
|
522
|
$form = cdm_api_settings_form();
|
523
|
|
524
|
//TODO: settings are still incomplete, compare with trunk/dataportal/inc/config_default.php.inc
|
525
|
$form['cdm_dataportal'] = array(
|
526
|
'#type' => 'fieldset',
|
527
|
'#title' => t('CDM DataPortal'),
|
528
|
'#collapsible' => FALSE,
|
529
|
'#collapsed' => TRUE,
|
530
|
);
|
531
|
|
532
|
// $form['cdm_dataportal']['secuuid_widget'] = array(
|
533
|
// '#type' => 'select_secuuid', // => will be themed by theme_select_secuuid(...)
|
534
|
// '#title' => t('Default Concept References'),
|
535
|
// '#description' => t('The default \'sensu\' reference to start the CDM DataPortal with. Per user choices are possible and may override this value.'),
|
536
|
// '#varname' => 'cdm_secUuid_default',
|
537
|
// '#multiple' => false
|
538
|
// );
|
539
|
|
540
|
$taxonTrees = cdm_ws_get(CDM_WS_TAXONOMY);
|
541
|
foreach($taxonTrees as $tree){
|
542
|
$taxonomicTreeOptions[$tree->uuid] = $tree->titleCache;
|
543
|
}
|
544
|
$form['cdm_dataportal']['cdm_taxonomictree_uuid'] = array(
|
545
|
'#type' => 'select',
|
546
|
'#title' => t('Available taxonomic views'),
|
547
|
'#default_value' => variable_get('cdm_taxonomictree_uuid', false),
|
548
|
'#options' => $taxonomicTreeOptions,
|
549
|
'#description' => t('Select a taxonomic view for this webservice.')
|
550
|
);
|
551
|
|
552
|
|
553
|
//------------------ FEATURE TREE --------------------//
|
554
|
|
555
|
$form['cdm_dataportal']['feature_tree'] = array(
|
556
|
'#type' => 'fieldset',
|
557
|
'#title' => t('Feature Tree'),
|
558
|
'#collapsible' => TRUE,
|
559
|
'#collapsed' => TRUE,
|
560
|
);
|
561
|
|
562
|
$form['cdm_dataportal']['feature_tree']['cdm_dataportal_featuretree_uuid'] = array(
|
563
|
'#type' => 'select',
|
564
|
'#title' => t('Available FeatureTrees'),
|
565
|
'#default_value' => variable_get('cdm_dataportal_featuretree_uuid', false),
|
566
|
'#options' => _get_feature_trees(),
|
567
|
'#description' => t('Select a FeatureTree for this webservice.'
|
568
|
//.' If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
|
569
|
)
|
570
|
);
|
571
|
|
572
|
//------------------ LAYOUT --------------------//
|
573
|
|
574
|
$form['cdm_dataportal']['layout'] = array(
|
575
|
'#type' => 'fieldset',
|
576
|
'#title' => t('Layout'),
|
577
|
'#collapsible' => TRUE,
|
578
|
'#collapsed' => TRUE,
|
579
|
);
|
580
|
|
581
|
$form['cdm_dataportal']['layout']['cdm_taxonname_type'] = array(
|
582
|
'#type' => 'select',
|
583
|
'#title' => t('Taxon name type'),
|
584
|
'#default_value' => variable_get('cdm_taxonname_type', 'BotanicalName'),
|
585
|
'#options' => array( 'BotanicalName'=>t('BotanicalName'), 'ZoologicalName'=>t('ZoologicalName')),
|
586
|
'#description' => t('')
|
587
|
);
|
588
|
|
589
|
$form['cdm_dataportal']['layout']['cdm_dataportal_nomref_in_title'] = array(
|
590
|
'#type' => 'checkbox',
|
591
|
'#title' => t('Hide full nomenclatural reference in title'),
|
592
|
'#default_value' => variable_get('cdm_dataportal_nomref_in_title', 1),
|
593
|
'#description' => t('Uncheck this, if you want the title of a taxon page consisting of name and author plus publication year only.
|
594
|
If not checked, the first homotypic taxon is a repetition of the accepted taxon with
|
595
|
the full nomenclatural reference.')
|
596
|
);
|
597
|
|
598
|
$form['cdm_dataportal']['layout']['cdm_dataportal_display_name_relations'] = array(
|
599
|
'#type' => 'checkbox',
|
600
|
'#title' => t('Show name relations of accepted taxa on taxon page'),
|
601
|
'#default_value' => variable_get('cdm_dataportal_display_name_relations', 1),
|
602
|
'#description' => t('')
|
603
|
);
|
604
|
|
605
|
$form['cdm_dataportal']['layout']['cdm_dataportal_name_relations_skiptype_basionym'] = array(
|
606
|
'#type' => 'checkbox',
|
607
|
'#title' => t('Exclude the basionym relationship type from the taxon page'),
|
608
|
'#default_value' => variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1),
|
609
|
'#description' => t('')
|
610
|
);
|
611
|
|
612
|
$form['cdm_dataportal']['layout']['cdm_dataportal_taxonpage_tabs'] = array(
|
613
|
'#type' => 'checkbox',
|
614
|
'#title' => t('Tabbed taxon page'),
|
615
|
'#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
|
616
|
'#description' => t('Split the taxon page into individual tabs for description, images, synonymy')
|
617
|
);
|
618
|
|
619
|
$form['cdm_dataportal']['layout']['cdm_dataportal_search_items_on_page'] = array(
|
620
|
'#type' => 'textfield',
|
621
|
'#title' => t('Search Page Size'),
|
622
|
'#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
|
623
|
'#description' => t('Number of Names to display per page in search results.')
|
624
|
);
|
625
|
|
626
|
$form['cdm_dataportal']['layout']['cdm_dataportal_descriptions_separated'] = array(
|
627
|
'#type' => 'checkbox',
|
628
|
'#title' => t('Separate Desriptions'),
|
629
|
'#default_value' => variable_get('cdm_dataportal_descriptions_separated', 0),
|
630
|
'#description' => t('By default corresponding elements of different descriptions are joined together'
|
631
|
.' into a common section per feature (i.e. type of description).'
|
632
|
.' Check this box to allow displaying all descriptions separately.')
|
633
|
);
|
634
|
|
635
|
$options = cdm_rankVocabulary_as_option();
|
636
|
array_unshift($options, '-- DISABLED --');
|
637
|
$form['cdm_dataportal']['layout']['image_hide_rank'] = array(
|
638
|
'#type' => 'select',
|
639
|
'#title' => t('Hide Images for Taxa above'),
|
640
|
'#default_value' => variable_get('image_hide_rank', '0'),
|
641
|
'#options' => $options,
|
642
|
'#description' => t(''),
|
643
|
);
|
644
|
|
645
|
// --- find taxa ---- //
|
646
|
$form['cdm_dataportal']['layout']['findtaxa'] = array(
|
647
|
'#type' => 'fieldset',
|
648
|
'#title' => t('Search Taxa'),
|
649
|
'#collapsible' => TRUE,
|
650
|
'#collapsed' => TRUE,
|
651
|
);
|
652
|
|
653
|
$form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_taxon_media_on'] = array(
|
654
|
'#type' => 'checkbox',
|
655
|
'#title' => t('Show media for accepted taxa'),
|
656
|
'#default_value' => variable_get('cdm_dataportal_findtaxa_taxon_media_on', 1),
|
657
|
'#description' => t('')
|
658
|
);
|
659
|
|
660
|
$form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_synonyms_media_on'] = array(
|
661
|
'#type' => 'checkbox',
|
662
|
'#title' => t('Show media for syonyms'),
|
663
|
'#default_value' => variable_get('cdm_dataportal_findtaxa_synonyms_media_on', 0),
|
664
|
'#description' => t('')
|
665
|
);
|
666
|
|
667
|
$form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_media_maxextend'] = array(
|
668
|
'#type' => 'textfield',
|
669
|
'#title' => t('Maximum extend of Images'),
|
670
|
'#default_value' => variable_get('cdm_dataportal_findtaxa_media_maxextend', 120),
|
671
|
'#description' => t('')
|
672
|
);
|
673
|
|
674
|
$form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_media_cols'] = array(
|
675
|
'#type' => 'textfield',
|
676
|
'#title' => t('Number of columns'),
|
677
|
'#default_value' => variable_get('cdm_dataportal_findtaxa_media_cols', 3),
|
678
|
'#description' => t('')
|
679
|
);
|
680
|
|
681
|
$form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_media_maxRows'] = array(
|
682
|
'#type' => 'textfield',
|
683
|
'#title' => t('Maximum number of rows'),
|
684
|
'#default_value' => variable_get('cdm_dataportal_findtaxa_media_maxRows', 1),
|
685
|
'#description' => t('')
|
686
|
);
|
687
|
|
688
|
|
689
|
|
690
|
//---------------- GEOSERVICE ----------------//
|
691
|
|
692
|
$form['cdm_dataportal']['geoservice'] = array(
|
693
|
'#type' => 'fieldset',
|
694
|
'#title' => t('Geoservice'),
|
695
|
'#collapsible' => TRUE,
|
696
|
'#collapsed' => TRUE,
|
697
|
);
|
698
|
|
699
|
$form['cdm_dataportal']['geoservice']['cdm_dataportal_map_openlayers'] = array(
|
700
|
'#type' => 'checkbox',
|
701
|
'#title' => t('OpenLayers Viewer'),
|
702
|
'#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
|
703
|
'#description' => t('Display the maps in an interactive viewer which allows zooming and panning.')
|
704
|
);
|
705
|
|
706
|
$form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_access_point'] = array(
|
707
|
'#type' => 'textfield',
|
708
|
'#title' => t('Geoservice Access Point'),
|
709
|
'#default_value' => variable_get('cdm_dataportal_geoservice_access_point', ''),
|
710
|
'#description' => t('Base URL of the geoservice to be used by this portal')
|
711
|
);
|
712
|
|
713
|
$form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_display_width'] = array(
|
714
|
'#type' => 'textfield',
|
715
|
'#title' => t('Geoservice Display Width'),
|
716
|
'#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
|
717
|
'#description' => t('Width of the image generated by geoservice')
|
718
|
);
|
719
|
|
720
|
$form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_bounding_box'] = array(
|
721
|
'#type' => 'textfield',
|
722
|
'#title' => t('Geoservice Bounding Box'),
|
723
|
'#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
|
724
|
'#description' => t('Define the surrounding area using latitude and longitude. Leave as is for the whole world.')
|
725
|
);
|
726
|
|
727
|
//cdm_dataportal_geoservice_labels_on
|
728
|
$form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_labels_on'] = array(
|
729
|
'#type' => 'checkbox',
|
730
|
'#title' => t('Display Country Labels'),
|
731
|
'#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
|
732
|
'#description' => t('Check this if you like country names to be displayed in the maps. ')
|
733
|
);
|
734
|
|
735
|
//cdm_dataportal_geoservice_legend_on
|
736
|
$form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_legend_on'] = array(
|
737
|
'#type' => 'checkbox',
|
738
|
'#title' => t('Display a map legend'),
|
739
|
'#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
|
740
|
'#description' => t('Check this if you like a legend to be displayed with the maps. ')
|
741
|
);
|
742
|
|
743
|
return system_settings_form($form);
|
744
|
}
|
745
|
|
746
|
/**
|
747
|
* Implementation of hook_elements().
|
748
|
*/
|
749
|
function cdm_dataportal_elements() {
|
750
|
$type['select_secuuid'] = array(
|
751
|
'#input' => TRUE,
|
752
|
'#process' => array('cdm_dataportal_select_secuuid_expand' => array()),
|
753
|
//'#validate' => array('cdm_dataportal_select_secuuid_validate' => array()),
|
754
|
//'#default_value' => array(),
|
755
|
);
|
756
|
return $type;
|
757
|
}
|
758
|
|
759
|
/*
|
760
|
*
|
761
|
*/
|
762
|
function cdm_dataportal_select_secuuid_expand($element){
|
763
|
|
764
|
$element['#tree'] = FALSE;
|
765
|
|
766
|
// any value submitted?
|
767
|
if(isset($element['#post'][$element['#varname']])){
|
768
|
$selected_values = $element['#post'][$element['#varname']];
|
769
|
} else {
|
770
|
// use those store in drupal
|
771
|
$selected_values = variable_get( $element['#varname'], array());
|
772
|
}
|
773
|
if(!is_array($selected_values)){
|
774
|
$selected_values = array($selected_values);
|
775
|
}
|
776
|
$options = array();
|
777
|
foreach($selected_values as $secUuid){
|
778
|
$options[$secUuid] = cdm_taxontree_secRefTitle_for($secUuid);
|
779
|
}
|
780
|
|
781
|
$element[$element['#varname']] = array(
|
782
|
'#type' => 'select',
|
783
|
'#options' => $options,
|
784
|
'#default_value' => array_values($options),
|
785
|
'#size' => $element['#multiple'] ? 12 : 2,
|
786
|
'#multiple' => $element['#multiple'],
|
787
|
);
|
788
|
return $element;
|
789
|
}
|
790
|
|
791
|
|
792
|
|
793
|
/**
|
794
|
* Displays a list of the known taxonomic names. Long lists are split up into multiple pages
|
795
|
*
|
796
|
* TODO: parameters are still preliminar
|
797
|
* @param String $page page number to diplay defaults to page 1
|
798
|
* @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
|
799
|
*/
|
800
|
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
|
801
|
|
802
|
$request_params = array(
|
803
|
'q' => $beginsWith,
|
804
|
//'sec' = '',
|
805
|
//'higherTaxa' => getFiters(),
|
806
|
// 'matchAnywhere' => false, // default is false
|
807
|
'page' => $page,
|
808
|
'onlyAccepted' => $onlyAccepted,
|
809
|
'pagesize' => 20 /*$_SESSION['cdm']['namelist_pagesize'] */);
|
810
|
|
811
|
$taxonPager = cdm_ws_find(CDM_WS_FIND_TAXA, $request_params);
|
812
|
/*
|
813
|
* FIXME the filter for accepted names will be a form element, thus this widget
|
814
|
* should be generated via form api preferably as block
|
815
|
*/
|
816
|
//$out = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
|
817
|
//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
|
818
|
$out .= theme('cdm_listof_taxa', $taxonPager);
|
819
|
return $out;
|
820
|
}
|
821
|
|
822
|
function cdm_dataportal_view_reference($uuid, $arg2 = null){
|
823
|
$reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
|
824
|
return theme('cdm_reference_page', $reference);
|
825
|
}
|
826
|
|
827
|
function cdm_dataportal_view_reference_list($pageNumber){
|
828
|
$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
|
829
|
return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
|
830
|
}
|
831
|
|
832
|
/**
|
833
|
* The taxon page gives detailed information on a taxon, it shows:
|
834
|
* - Taxon name
|
835
|
* - Full list of synonyms homotypic synonyms on top, followed by the
|
836
|
* heterotypic and finally followed by misapplied names.
|
837
|
* The list is ordered historically.
|
838
|
* - All facts associated with the very taxon concept and taxon name.
|
839
|
*
|
840
|
* @param String $uuid the UUID of the taxon
|
841
|
*/
|
842
|
function cdm_dataportal_view_taxon($uuid, $chapter = null){
|
843
|
|
844
|
// display the page for the taxon defined by $uuid
|
845
|
$taxon = cdm_ws_get(CDM_WS_TAXON, $uuid);
|
846
|
if(!$taxon){
|
847
|
drupal_set_title(t('Taxon does not exist'));
|
848
|
return false;
|
849
|
}
|
850
|
_cdm_dataportal_set_currentSecUuid($taxon->sec->uuid);
|
851
|
|
852
|
drupal_set_title(theme('cdm_taxon_page_title', $taxon));
|
853
|
$out = theme('cdm_taxon_page_general', $taxon, $chapter);
|
854
|
|
855
|
return $out;
|
856
|
/*}*/
|
857
|
}
|
858
|
|
859
|
function cdm_dataportal_view_search_advanced(){
|
860
|
|
861
|
drupal_set_title(t('Advanced Search'));
|
862
|
|
863
|
$searchForm = cdm_dataportal_search_taxon_form(true);
|
864
|
|
865
|
return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
|
866
|
|
867
|
}
|
868
|
|
869
|
/**
|
870
|
*
|
871
|
* future extensions to meet palmweb mockup requirements:
|
872
|
* - habitat
|
873
|
* - uses
|
874
|
* - conservation status
|
875
|
* - locality / tdwg region
|
876
|
*/
|
877
|
function cdm_dataportal_view_search_taxon(){
|
878
|
|
879
|
$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
|
880
|
|
881
|
$request_params = cdm_dataportal_search_form_request();
|
882
|
$taxonPager = cdm_ws_get(CDM_WS_FIND_TAXA, null, queryString($request_params));
|
883
|
|
884
|
$search_params = $_REQUEST;
|
885
|
unset($search_params['q']);
|
886
|
return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
|
887
|
}
|
888
|
|
889
|
function cdm_view_xml2json(){
|
890
|
$file = arg(2);
|
891
|
$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
|
892
|
return xml2json::transformXmlStringToJson($datastr);
|
893
|
}
|
894
|
|
895
|
/* ====================== other functions ====================== */
|
896
|
|
897
|
/**
|
898
|
* Enter description here...
|
899
|
*
|
900
|
* @param String $uuid the UUID of the taxon
|
901
|
* @return the URL
|
902
|
*/
|
903
|
function path_to_taxon($uuid){
|
904
|
if(!$uuid) return false;
|
905
|
return 'cdm_dataportal/taxon/'.$uuid;
|
906
|
}
|
907
|
|
908
|
function path_to_reference($uuid){
|
909
|
if(!$uuid) return false;
|
910
|
return 'cdm_dataportal/reference/'.$uuid;
|
911
|
}
|
912
|
|
913
|
/**
|
914
|
* Compares thisRank with thatRank.
|
915
|
* Returns a negative integer, zero, or a positive integer
|
916
|
* as the of thisRank is higher than, equal to, or lower than thatRank.
|
917
|
* e.g:
|
918
|
* <ul>
|
919
|
* <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
|
920
|
* <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
|
921
|
* <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
|
922
|
* </ul>
|
923
|
* <p>
|
924
|
* This compare logic of the underlying webservice is the
|
925
|
* <b>inverse logic</b> of the the one implemented in
|
926
|
* java.lang.Comparable#compareTo(java.lang.Object)
|
927
|
* @param $thisRankUuid
|
928
|
* @param $thatRankUuid
|
929
|
* @return a negative integer, zero, or a positive integer
|
930
|
* as the thisRank is lower than, equal to, or higher than thatRank
|
931
|
*/
|
932
|
function rank_compare($thisRankUuid, $thatRankUuid){
|
933
|
$result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
|
934
|
return $result->Integer;
|
935
|
}
|
936
|
|
937
|
function uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null){
|
938
|
$acceptedPath = path_to_taxon($acceptedUuid);
|
939
|
return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid);
|
940
|
}
|
941
|
|
942
|
/**
|
943
|
* Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
|
944
|
* If the taggename if empty the fullname will be returned.
|
945
|
*
|
946
|
* @param unknown_type $Name or TreeNode
|
947
|
* @return string
|
948
|
*/
|
949
|
function cdm_dataportal_shortname_of($name){
|
950
|
|
951
|
$nameStr = '';
|
952
|
// get all tagged text tokens of the scientific name
|
953
|
foreach($name->taggedTitle as $tagtxt){
|
954
|
if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
|
955
|
$nameStr .= ($nameStr ? ' ' : '').$tagtxt->text;
|
956
|
}
|
957
|
}
|
958
|
$nameStr = trim($nameStr);
|
959
|
if($nameStr){
|
960
|
// do not return short names for these
|
961
|
if($nameStr == 'Incertae sedis' || $nameStr == 'Nomina excludenda'){
|
962
|
return $nameStr;
|
963
|
}
|
964
|
if($pos = stripos($nameStr, ' ')){
|
965
|
return substr($nameStr, 0, 1).'. '.substr($nameStr, $pos);
|
966
|
} else {
|
967
|
return $nameStr;
|
968
|
}
|
969
|
} else {
|
970
|
return $name->titleCache;
|
971
|
}
|
972
|
}
|
973
|
|
974
|
/**
|
975
|
* TODO Add Comments. I don't get what
|
976
|
*
|
977
|
* @param UUID $secUuid
|
978
|
*/
|
979
|
function _cdm_dataportal_set_currentSecUuid($secUuid){
|
980
|
|
981
|
// do not save in session but in database
|
982
|
|
983
|
if(is_array($secUuid)){
|
984
|
$secUuid = $secUuid[0];
|
985
|
}
|
986
|
if(!$secUuid){
|
987
|
variable_set('cdm_currentSecRef', null);
|
988
|
} else {
|
989
|
$secRef = cdm_ws_get(CDM_WS_REFERENCE, $secUuid);
|
990
|
if(isset($secRef)){
|
991
|
variable_set('cdm_currentSecRef', (array)($secRef));
|
992
|
}
|
993
|
}
|
994
|
|
995
|
}
|
996
|
|
997
|
/**
|
998
|
* TODO
|
999
|
* This will not work with multiple instances of the dataportal running
|
1000
|
* under the same host as there is only one session for all instances.
|
1001
|
* In case you switch instances with the same client, you will definitely
|
1002
|
* run into trouble.
|
1003
|
* Also this is not handling multiple secs.
|
1004
|
*
|
1005
|
*
|
1006
|
* returns the current secRef array.
|
1007
|
* If the according session variable is not jet set the default
|
1008
|
* as configured in the setting is used otherwise null.
|
1009
|
*
|
1010
|
* currentSecRef['uuid']
|
1011
|
* currentSecRef[....
|
1012
|
*
|
1013
|
* @return array
|
1014
|
*/
|
1015
|
function _cdm_dataportal_currentSecRef_array(){
|
1016
|
|
1017
|
// do not look in session but in database
|
1018
|
if( variable_get('cdm_currentSecRef', null) == null){
|
1019
|
$secUuid = variable_get('cdm_secUuid_default', null);
|
1020
|
_cdm_dataportal_set_currentSecUuid($secUuid);
|
1021
|
}
|
1022
|
return variable_get('cdm_currentSecRef', null);
|
1023
|
|
1024
|
}
|
1025
|
|
1026
|
/**
|
1027
|
* Check if a taxon is accepted by the current taxonomic tree
|
1028
|
*
|
1029
|
* @param Taxon $taxon
|
1030
|
* @return true if $taxon is accepted, false otherwise
|
1031
|
*/
|
1032
|
|
1033
|
function _cdm_dataportal_acceptedByCurrentView($taxon){
|
1034
|
|
1035
|
//$current_secref = _cdm_dataportal_currentSecRef_array();
|
1036
|
$defaultTreeUuid = variable_get('cdm_taxonomictree_uuid', false);
|
1037
|
if($taxon->class == "Taxon" && isset($taxon->taxonNodes)){
|
1038
|
foreach($taxon->taxonNodes as $node){
|
1039
|
if($node->taxonomicTree == $defaultTreeUuid) {
|
1040
|
return true;
|
1041
|
}
|
1042
|
}
|
1043
|
}
|
1044
|
return false;
|
1045
|
}
|
1046
|
|
1047
|
/**
|
1048
|
* Truncates a $string to the specified $length.
|
1049
|
* If the supplied string is equal to or shorter than the $legth the original is returend.
|
1050
|
* if an $appendix is defined the resulting string will have the specified $length including the $appendix.
|
1051
|
*
|
1052
|
* @param String $string the string to truncate
|
1053
|
* @param Number $length the maximun length
|
1054
|
* @param String $appendix an optional appendix.
|
1055
|
*
|
1056
|
* @return the string
|
1057
|
*/
|
1058
|
function str_trunk(&$string, $length, $appendix=''){
|
1059
|
if(strlen($string) >= $length ){
|
1060
|
return substr($string, 0, $length - strlen($appendix)).$appendix;
|
1061
|
} else {
|
1062
|
return $string;
|
1063
|
}
|
1064
|
}
|
1065
|
|
1066
|
/**
|
1067
|
* @param string $str
|
1068
|
* @param string $sub
|
1069
|
* @return boolean
|
1070
|
*/
|
1071
|
function str_beginsWith( $str, $sub ) {
|
1072
|
return ( substr( $str, 0, strlen( $sub ) ) === $sub );
|
1073
|
}
|
1074
|
|
1075
|
/**
|
1076
|
*
|
1077
|
* @param string $str
|
1078
|
* @param string $sub
|
1079
|
* @return boolean
|
1080
|
*/
|
1081
|
function str_endsWith( $str, $sub ) {
|
1082
|
return ( substr( $str, strlen( $str ) - strlen( $sub ) ) === $sub );
|
1083
|
}
|
1084
|
|
1085
|
/**
|
1086
|
* Replaces all occurences in $array of the key defined in $replace_map with the according values in the
|
1087
|
* $replace_map.
|
1088
|
*
|
1089
|
* @param $array
|
1090
|
* @param $replace_map
|
1091
|
* @return unknown_type
|
1092
|
*/
|
1093
|
function array_replace_key($array, $replace_map){
|
1094
|
foreach($replace_map as $key=>$newkey){
|
1095
|
if(isset($array[$key])){
|
1096
|
$array[$newkey] = $array[$key];
|
1097
|
unset($array[$key]);
|
1098
|
}
|
1099
|
}
|
1100
|
return $array;
|
1101
|
}
|
1102
|
|
1103
|
/**
|
1104
|
* Replaces all occurrences of space characters with
|
1105
|
* an underscore and transforms the given
|
1106
|
* string to lowercase.
|
1107
|
*
|
1108
|
* @param String $string
|
1109
|
* @return the transformed string
|
1110
|
*/
|
1111
|
function generalizeString($string){
|
1112
|
return str_replace(' ', '_', strtolower($string));
|
1113
|
}
|
1114
|
|
1115
|
/**@Deprecated
|
1116
|
*
|
1117
|
*/
|
1118
|
function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){
|
1119
|
$pstr = '';
|
1120
|
foreach($parameters as $key=>$value){
|
1121
|
if(is_array($value)){
|
1122
|
|
1123
|
} else {
|
1124
|
$pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);
|
1125
|
}
|
1126
|
}
|
1127
|
return $pstr;
|
1128
|
}
|
1129
|
|
1130
|
function _get_feature_trees(){
|
1131
|
$feature_trees = array();
|
1132
|
|
1133
|
// set tree that contains all features
|
1134
|
$feature_trees['0'] = 'No FeatureTree';
|
1135
|
|
1136
|
// get features from database
|
1137
|
$persisted_trees = cdm_ws_get(CDM_WS_FEATURETREES);
|
1138
|
if(is_array($persisted_trees)){
|
1139
|
foreach($persisted_trees as $featureTree){
|
1140
|
|
1141
|
$featureLabels = array();
|
1142
|
foreach ($featureTree->root->children as $featureNode){
|
1143
|
$featureLabels[] = $featureNode->feature->representation_L10n;
|
1144
|
}
|
1145
|
|
1146
|
$feature_trees[$featureTree->uuid] = implode(", ", $featureLabels);
|
1147
|
|
1148
|
}
|
1149
|
}
|
1150
|
return $feature_trees;
|
1151
|
}
|
1152
|
|
1153
|
|
1154
|
function get_nameRenderTemplate($renderPath, $nameLink = NULL, $refenceLink = NULL){
|
1155
|
//TODO implement admin user interface to replace swicth statement
|
1156
|
// preliminar solution: using themes
|
1157
|
|
1158
|
$template = theme('get_nameRenderTemplate', $renderPath);
|
1159
|
|
1160
|
if(!is_array($template)){
|
1161
|
switch($renderPath){
|
1162
|
case 'list_of_taxa':
|
1163
|
case 'acceptedFor':
|
1164
|
case 'taxon_page_synonymy':
|
1165
|
case 'typedesignations':
|
1166
|
case 'taxon_page_title':
|
1167
|
case 'na': $template = array(
|
1168
|
'namePart' => array('#uri'=>true),
|
1169
|
//'authorshipPart' => true,
|
1170
|
);
|
1171
|
break;
|
1172
|
case 'nar': $template = array(
|
1173
|
'namePart' => array('#uri'=>true),
|
1174
|
//'authorshipPart' => true,
|
1175
|
'referencePart' => array('#uri'=>true),
|
1176
|
'microreferencePart' => true,
|
1177
|
);
|
1178
|
break;
|
1179
|
default: $template = array(
|
1180
|
'namePart' => array('#uri'=>true),
|
1181
|
'authorshipPart' => true,
|
1182
|
'referencePart' => array('#uri'=>true),
|
1183
|
'microreferencePart' => true,
|
1184
|
'statusPart' => true,
|
1185
|
'descriptionPart' => true
|
1186
|
);
|
1187
|
}
|
1188
|
}
|
1189
|
|
1190
|
if($nameLink && isset($template['nameAuthorPart']['#uri'])){
|
1191
|
$template['nameAuthorPart']['#uri'] = $nameLink;
|
1192
|
} else{
|
1193
|
unset($template['nameAuthorPart']['#uri']);
|
1194
|
}
|
1195
|
|
1196
|
if($nameLink && isset($template['namePart']['#uri'])){
|
1197
|
$template['namePart']['#uri'] = $nameLink;
|
1198
|
} else{
|
1199
|
unset($template['namePart']['#uri']);
|
1200
|
}
|
1201
|
|
1202
|
if($refenceLink && isset($template['referencePart']['#uri'])){
|
1203
|
$template['referencePart']['#uri'] = $refenceLink;
|
1204
|
}else{
|
1205
|
unset($template['referencePart']['#uri']);
|
1206
|
}
|
1207
|
|
1208
|
return $template;
|
1209
|
}
|
1210
|
|
1211
|
function get_partDefinition($taxonNameType){
|
1212
|
//TODO implement admin user interface to allow specify the partdefinitions for any type
|
1213
|
// preliminar solution: using themes
|
1214
|
|
1215
|
$partdef = theme('get_partDefinition', $taxonNameType);
|
1216
|
|
1217
|
if(!is_array($partdef)){
|
1218
|
switch($taxonNameType){
|
1219
|
case 'ZoologicalName': $partdef = array(
|
1220
|
'namePart' => array(
|
1221
|
'name' => true,
|
1222
|
),
|
1223
|
'referencePart' => array(
|
1224
|
'authorTeam' => true
|
1225
|
),
|
1226
|
'microreferencePart' => array(
|
1227
|
'microreference' => true,
|
1228
|
),
|
1229
|
'statusPart' => array(
|
1230
|
'status' => true,
|
1231
|
),
|
1232
|
'descriptionPart' => array(
|
1233
|
'description' => true,
|
1234
|
),
|
1235
|
);
|
1236
|
break;
|
1237
|
case 'BotanicalName': $partdef = array(
|
1238
|
'namePart' => array(
|
1239
|
'name' => true
|
1240
|
),
|
1241
|
'authorTeamPart' => array(
|
1242
|
'authorTeam' => true,
|
1243
|
),
|
1244
|
'referencePart' => array(
|
1245
|
'reference' => true
|
1246
|
),
|
1247
|
'microreferencePart' => array(
|
1248
|
'microreference' => true,
|
1249
|
),
|
1250
|
'statusPart' => array(
|
1251
|
'status' => true,
|
1252
|
),
|
1253
|
'descriptionPart' => array(
|
1254
|
'description' => true,
|
1255
|
),
|
1256
|
);
|
1257
|
break;
|
1258
|
default: $partdef = array(
|
1259
|
'namePart' => array(
|
1260
|
'name' => true,
|
1261
|
),
|
1262
|
'authorTeamPart' => array(
|
1263
|
'authorTeam' => true,
|
1264
|
),
|
1265
|
'referencePart' => array(
|
1266
|
'reference' => true
|
1267
|
),
|
1268
|
'microreferencePart' => array(
|
1269
|
'microreference' => true,
|
1270
|
),
|
1271
|
'statusPart' => array(
|
1272
|
'status' => true,
|
1273
|
),
|
1274
|
'descriptionPart' => array(
|
1275
|
'description' => true,
|
1276
|
),
|
1277
|
);
|
1278
|
}
|
1279
|
}
|
1280
|
return $partdef;
|
1281
|
}
|