1
|
<?php
|
2
|
// $Id$
|
3
|
|
4
|
/**
|
5
|
* Copyright (C) 2007 EDIT
|
6
|
* European Distributed Institute of Taxonomy
|
7
|
* http://www.e-taxonomy.eu
|
8
|
*
|
9
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
10
|
* See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
|
11
|
*/
|
12
|
|
13
|
function theme_cdm_search_results($pager, $path, $parameters){
|
14
|
|
15
|
|
16
|
$showThumbnails = $_SESSION['pageoptions']['searchtaxa']['showThumbnails'];
|
17
|
if( !is_numeric($showThumbnails)){
|
18
|
$showThumbnails = 1;
|
19
|
}
|
20
|
$setSessionUri = url('cdm_api/setvalue/session', "var=[pageoption][searchtaxa][showThumbnails]&val=");
|
21
|
drupal_add_js('$(document).ready(function() {
|
22
|
|
23
|
// init
|
24
|
if('.$showThumbnails.' == 1){
|
25
|
$(\'.media_gallery\').show(20);
|
26
|
} else {
|
27
|
$(\'.media_gallery\').hide(20);
|
28
|
}
|
29
|
// add change hander
|
30
|
$(\'#showThumbnails\').change(
|
31
|
function(event){
|
32
|
var state = 0;
|
33
|
if($(this).is(\':checked\')){
|
34
|
$(\'.media_gallery\').show(20);
|
35
|
state = 1;
|
36
|
} else {
|
37
|
$(\'.media_gallery\').hide(20);
|
38
|
}
|
39
|
// store state in session variable
|
40
|
var uri = \''.$setSessionUri.'\' + state;
|
41
|
jQuery.get(uri);
|
42
|
});
|
43
|
});', "inline");
|
44
|
|
45
|
drupal_set_title(t('Search results'));
|
46
|
|
47
|
$out = ''; //l('Advanced Search', '/cdm_dataportal/search');
|
48
|
|
49
|
$out = '<div class="page_options"><form name="pageoptions"><input id="showThumbnails" type="checkbox" name="showThumbnails" '.($showThumbnails == 1? 'checked="checked"': '').'> '.t('Show Thumbnails').'</form></div>';
|
50
|
if(count($pager->records) > 0){
|
51
|
$out .= theme('cdm_list_of_taxa', $pager->records);
|
52
|
$out .= theme('cdm_pager', $pager, $path, $parameters);
|
53
|
} else {
|
54
|
$out = '<h4 class="error">Sorry, no matching entries found.</h4>';
|
55
|
}
|
56
|
return $out;
|
57
|
}
|
58
|
|
59
|
|
60
|
/**
|
61
|
* renders misapplied names and invalid designations.
|
62
|
* Both relation types are currently treated the same!
|
63
|
*
|
64
|
* @param unknown_type $taxonRelationships
|
65
|
* @return unknown
|
66
|
*/
|
67
|
function theme_cdm_taxonRelationships($taxonRelationships){
|
68
|
|
69
|
if(!$taxonRelationships){
|
70
|
return;
|
71
|
}
|
72
|
|
73
|
RenderHints::pushToRenderStack('taxonRelationships');
|
74
|
$footnoteListKey = 'taxonRelationships';
|
75
|
RenderHints::setFootnoteListKey($footnoteListKey);
|
76
|
|
77
|
$misapplied = array();
|
78
|
$joinedAuthorTeams = array();
|
79
|
|
80
|
// aggregate misapplied names having the same fullname:
|
81
|
foreach($taxonRelationships as $taxonRelation){
|
82
|
if(true || $taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR ){
|
83
|
|
84
|
$name = $taxonRelation->fromTaxon->name->titleCache;
|
85
|
|
86
|
$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $taxonRelation->fromTaxon->sec->uuid);
|
87
|
$authorteam = $author_team->titleCache;
|
88
|
|
89
|
if(!isset($misapplied[$name])){
|
90
|
$misapplied[$name]['out'] =
|
91
|
'<span class="misapplied">'
|
92
|
.theme('cdm_related_taxon',$taxonRelation->fromTaxon, UUID_MISAPPLIED_NAME_FOR, false).
|
93
|
'</span>';
|
94
|
}
|
95
|
|
96
|
// collect all authors for this fullname
|
97
|
if(isset($authorteam)){
|
98
|
$misapplied[$name]['authorteam'][$authorteam] = '';
|
99
|
$joinedAuthorTeams[$authorteam] = 'sensu '.theme('cdm_reference', $taxonRelation->fromTaxon->sec);
|
100
|
}
|
101
|
|
102
|
}
|
103
|
}
|
104
|
|
105
|
// sort the joinedAuthorTeams and create footnotes and footnotekeys
|
106
|
ksort($joinedAuthorTeams);
|
107
|
foreach($joinedAuthorTeams as $authorteam=>$sensuCitation){
|
108
|
$footnoteKey = FootnoteManager::addNewFootnote($footnoteListKey, $sensuCitation);
|
109
|
$joinedAuthorTeams[$authorteam] = '<span class="sensu">sensu '.$authorteam. theme('cdm_footnote_key', $footnoteKey).'</span>';
|
110
|
}
|
111
|
|
112
|
// generate output
|
113
|
$out = '<ul class="misapplied">';
|
114
|
|
115
|
foreach($misapplied as $misapplied_name){
|
116
|
|
117
|
$out .= '<li class="synonym">'.$misapplied_name['out'] . " ";
|
118
|
if(isset($misapplied_name['authorteam'])){
|
119
|
// fill authors with the renderedFootnoteKey and sorting 'em
|
120
|
foreach($misapplied_name['authorteam'] as $authorteam=>&$renderedFootnoteKey) {
|
121
|
$renderedFootnoteKey = $joinedAuthorTeams[$authorteam];
|
122
|
}
|
123
|
ksort($misapplied_name['authorteam']);
|
124
|
$out .= join('; ', $misapplied_name['authorteam']);
|
125
|
}
|
126
|
$out .= '</li>';
|
127
|
|
128
|
}
|
129
|
$out .= '</ul>';
|
130
|
|
131
|
$tr_footnotes = theme('cdm_footnotes', $footnoteListKey, 'li');
|
132
|
$tr_footnotes_exploded = explode('sensu', $tr_footnotes);
|
133
|
$tr_footnotes_aux = '';
|
134
|
foreach ($tr_footnotes_exploded as $element){
|
135
|
$tr_footnotes_aux .= $element;
|
136
|
}
|
137
|
$out .= '<ul>' . $tr_footnotes_aux . '</ul>';
|
138
|
//$out .= '</ul>';
|
139
|
RenderHints::popFromRenderStack();
|
140
|
return $out;
|
141
|
}
|
142
|
|
143
|
function theme_cdm_acceptedFor(){
|
144
|
RenderHints::pushToRenderStack('acceptedFor');
|
145
|
|
146
|
$out = '';
|
147
|
if(isset($_REQUEST['acceptedFor'])){
|
148
|
|
149
|
$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $_REQUEST['acceptedFor']);
|
150
|
|
151
|
if($synonym){
|
152
|
$out .= '<span class="acceptedFor">';
|
153
|
$out .= t('is accepted for ');
|
154
|
if(isset($synonym->name->nomenclaturalReference)){
|
155
|
$referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid));
|
156
|
}
|
157
|
$out .= theme('cdm_taxonName', $synonym->name, null, $referenceUri);
|
158
|
$out .= theme('cdm_annotations_as_footnotekeys', $synonym);
|
159
|
$out .= '</span>';
|
160
|
}
|
161
|
}
|
162
|
RenderHints::popFromRenderStack();
|
163
|
return $out;
|
164
|
}
|
165
|
|
166
|
function theme_cdm_list_of_taxa($records, $showMedia = false){
|
167
|
|
168
|
RenderHints::pushToRenderStack('list_of_taxa');
|
169
|
|
170
|
$form_name = 'search_gallery';
|
171
|
//$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
|
172
|
//$gallery_settings = variable_get($form_name, $default_values);
|
173
|
|
174
|
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
|
175
|
|
176
|
$showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails'];
|
177
|
$showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails'];
|
178
|
//$showMedia_taxa = variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1);
|
179
|
//$showMedia_synonyms = variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0);
|
180
|
|
181
|
$classification_uuid = get_taxonomictree_uuid_selected();
|
182
|
|
183
|
// .. well, for sure not as performant as before, but better than nothing.
|
184
|
$synonym_uuids = array();
|
185
|
foreach($records as $taxon){
|
186
|
if($taxon->class != "Taxon"){
|
187
|
if(!array_key_exists($taxon->uuid, $synonym_uuids)){
|
188
|
$synonym_uuids[$taxon->uuid] = $taxon->uuid;
|
189
|
}
|
190
|
}
|
191
|
}
|
192
|
// batch service not jet implemented:
|
193
|
// $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED, join(',', $synonym_uuids));
|
194
|
// thus ...
|
195
|
$table_of_accepted = array();
|
196
|
|
197
|
foreach($synonym_uuids as $synUuid){
|
198
|
$table_of_accepted[$synUuid] = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($synUuid, $classification_uuid));
|
199
|
}
|
200
|
|
201
|
$out = '<ul class="cdm_names" style="background-image: none;">';
|
202
|
|
203
|
foreach($records as $taxon){
|
204
|
// its a Taxon
|
205
|
if($taxon->class == "Taxon"){
|
206
|
$taxonUri = url(path_to_taxon($taxon->uuid));
|
207
|
if(isset($taxon->name->nomenclaturalReference)){
|
208
|
$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
|
209
|
}
|
210
|
$out .= '<li class="Taxon">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
|
211
|
$out .= theme('cdm_annotations_as_footnotekeys', $taxon);
|
212
|
|
213
|
if($showMedia_taxa){
|
214
|
$out .= theme('cdm_taxon_list_thumbnails', $taxon);
|
215
|
}
|
216
|
$out .= '</li>';
|
217
|
} else {
|
218
|
// its a synonym
|
219
|
$uuid = $taxon->uuid;
|
220
|
$acceptedTaxa = $table_of_accepted[$uuid];
|
221
|
if(count($acceptedTaxa) == 1){
|
222
|
$acceptedTaxon = $acceptedTaxa[0];
|
223
|
$taxonUri = theme('cdm_uri_to_synonym', $taxon->uuid, $acceptedTaxon->uuid, 'synonymy');
|
224
|
if(isset($acceptedTaxon->name->nomenclaturalReference)){
|
225
|
$referenceUri = url(path_to_reference($acceptedTaxon->name->nomenclaturalReference->uuid));
|
226
|
}
|
227
|
$out .= '<li class="Synonym">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
|
228
|
$out .= theme('cdm_annotations_as_footnotekeys', $taxon);
|
229
|
if($showMedia_synonyms){
|
230
|
$out .= theme('cdm_taxon_list_thumbnails', $acceptedTaxon);
|
231
|
}
|
232
|
$out .= '</li>';
|
233
|
} else {
|
234
|
//TODO avoid using Ajax in the cdm_dynabox .... why?
|
235
|
//TODO add media
|
236
|
$out .= cdm_dynabox(
|
237
|
theme('cdm_taxonName', $taxon->name, null, null, false),
|
238
|
cdm_compose_url(CDM_WS_PORTAL_TAXON_ACCEPTED, array($taxon->uuid, $classification_uuid)),
|
239
|
'cdm_list_of_taxa',
|
240
|
'Click for accepted taxon');
|
241
|
}
|
242
|
}
|
243
|
}
|
244
|
|
245
|
$out .= '</ul>';
|
246
|
RenderHints::popFromRenderStack();
|
247
|
return $out;
|
248
|
}
|
249
|
|
250
|
|
251
|
function theme_cdm_related_taxon($taxon, $reltype_uuid = false){
|
252
|
|
253
|
static $relsign_homo = '≡';
|
254
|
static $relsign_hetero = '=';
|
255
|
static $relsign_invalid = '–';
|
256
|
|
257
|
$relsign = '';
|
258
|
$name_prefix = '';
|
259
|
$name_postfix = '';
|
260
|
|
261
|
$skiptags = array();
|
262
|
|
263
|
switch ($reltype_uuid){
|
264
|
case UUID_HETEROTYPIC_SYNONYM_OF:
|
265
|
case UUID_SYNONYM_OF:
|
266
|
$relsign = $relsign_hetero;
|
267
|
break;
|
268
|
case UUID_HOMOTYPIC_SYNONYM_OF:
|
269
|
$relsign = $relsign_homo;
|
270
|
break;
|
271
|
case UUID_MISAPPLIED_NAME_FOR:
|
272
|
case UUID_INVALID_DESIGNATION_FOR:
|
273
|
$skiptags[] = 'authors';
|
274
|
$relsign = $relsign_invalid;
|
275
|
$name_prefix = '"';
|
276
|
$name_postfix = '"';
|
277
|
break;
|
278
|
default :
|
279
|
$relsign = $relsign_invalid;
|
280
|
}
|
281
|
/*
|
282
|
* names with status invalid or nudum are to be displayed with the $relsign_invalid,
|
283
|
* these names appear at the end of all names in their homotypic group
|
284
|
* (ordered correctly by the java cdm_lib)
|
285
|
*/
|
286
|
if ( is_array($taxon->name->status)) {
|
287
|
foreach($taxon->name->status as $status){
|
288
|
if ($status->type->uuid == UUID_NOMENCLATURALSTATUS_TYPE_INVALID || $status->type->uuid == UUID_NOMENCLATURALSTATUS_TYPE_NUDUM){
|
289
|
$relsign = $relsign_invalid;
|
290
|
}
|
291
|
}
|
292
|
}
|
293
|
|
294
|
// now rendering starts ..
|
295
|
|
296
|
RenderHints::pushToRenderStack('related_taxon');
|
297
|
|
298
|
//$taxonUri = url(path_to_taxon($taxon->uuid));
|
299
|
if($taxon->name->nomenclaturalReference){
|
300
|
$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
|
301
|
}
|
302
|
//printing the taxonName and the handling the special case of annotations
|
303
|
$nameHtml = theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri, true, false, $skiptags);
|
304
|
$special_annotations_array = array();
|
305
|
$special_annotations_array[] = $taxon->name;
|
306
|
$special_annotations_array[] = $taxon;
|
307
|
$nameHtml .= theme('cdm_annotations_as_footnotekeys', $special_annotations_array);
|
308
|
|
309
|
//later homonym or trated as later homonym AND bloking names
|
310
|
$from_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS, $taxon->uuid);
|
311
|
$to_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
|
312
|
//first the FROM RELS
|
313
|
if ($from_name_relations){
|
314
|
foreach($from_name_relations as $element){
|
315
|
switch ($element->type->representation_L10n){
|
316
|
case 'later homonym for':
|
317
|
if(isset($name_relations_html)){
|
318
|
$name_relations_html .= ' nec ' . l($element->toName->titleCache . ' ' . substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
|
319
|
'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid);
|
320
|
}else{
|
321
|
$name_relations_html = ' non ' . l($element->toName->titleCache . ' ' . substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
|
322
|
'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid)
|
323
|
. ' ' . $element->toName->datePublished->start;
|
324
|
}
|
325
|
break;
|
326
|
case 'treated as later homonym for':
|
327
|
if(isset($name_relations_html)){
|
328
|
$name_relations_html = ' nec ' . l($element->toName->titleCache . ' ' . substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
|
329
|
'cdm_dataportal/name/' . $element->toName->uuid);
|
330
|
}else{
|
331
|
$name_relations_html = ' non ' . l($element->toName->titleCache . ' ' . substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
|
332
|
'cdm_dataportal/name/' . $element->toName->uuid);
|
333
|
}
|
334
|
break;
|
335
|
}
|
336
|
}
|
337
|
//second the TO RELS
|
338
|
if ($to_name_relations){
|
339
|
foreach($to_name_relations as $element){
|
340
|
switch ($element->type->representation_L10n){
|
341
|
case 'blocking name for':
|
342
|
if(isset($name_relations_html) ){
|
343
|
$name_relations_html .= ' nec ' . l($element->fromName->titleCache . ' ' . substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
|
344
|
'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid);
|
345
|
}else{
|
346
|
$name_relations_html = ' non ' . l($element->fromName->titleCache . ' ' . substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
|
347
|
'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid)
|
348
|
. ' ' . $element->fromName->datePublished->start;
|
349
|
}
|
350
|
break;
|
351
|
}
|
352
|
}
|
353
|
}
|
354
|
//rels output
|
355
|
if(isset($name_relations_html)){
|
356
|
$name_relations_html = '['. $name_relations_html .']';
|
357
|
}
|
358
|
}
|
359
|
//geneal output
|
360
|
$out = '<span class="relation_sign">'.$relsign.'</span>'.$name_prefix . $nameHtml . $name_postfix . $name_relations_html;
|
361
|
$out = uuid_anchor($taxon->uuid, $out);
|
362
|
|
363
|
RenderHints::popFromRenderStack();
|
364
|
|
365
|
return $out;
|
366
|
}
|
367
|
|
368
|
/**
|
369
|
*/
|
370
|
function theme_cdm_taxon_list_thumbnails($taxon){
|
371
|
|
372
|
$gallery_name = $taxon->uuid;
|
373
|
|
374
|
$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 1);
|
375
|
|
376
|
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
|
377
|
$showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
|
378
|
if($showCaption){
|
379
|
//$captionElements = array('title', '#uri'=>t('open Image'));
|
380
|
$captionElements = array('title', 'rights');
|
381
|
}
|
382
|
$mediaQueryParameters = array("type"=>"ImageFile");
|
383
|
$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
|
384
|
$selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
|
385
|
if ($selectShowMedia == 0){
|
386
|
$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
|
387
|
}else{
|
388
|
$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
|
389
|
}
|
390
|
//$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_MEDIA, array(variable_get('cdm_taxonomictree_uuid', false), $taxon ->rank, $taxon->uuid ));
|
391
|
$out .= theme('cdm_media_gallerie', $mediaList, $gallery_name ,
|
392
|
$gallery_settings['cdm_dataportal_media_maxextend'],
|
393
|
$gallery_settings['cdm_dataportal_media_cols'],
|
394
|
$gallery_settings['cdm_dataportal_media_maxRows'],
|
395
|
$captionElements, 'LIGHTBOX', null, $galleryLinkUri);
|
396
|
|
397
|
return $out;
|
398
|
}
|
399
|
|
400
|
|