Project

General

Profile

Download (14.9 KB) Statistics
| Branch: | Tag: | Revision:
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 .= '<div id="search_results">';
52
		$out .= theme('cdm_list_of_taxa', $pager->records);
53
		$out .= '</div>';
54
		$out .= theme('cdm_pager', $pager, $path, $parameters);
55
	} else {
56
		$out = '<h4 class="error">Sorry, no matching entries found.</h4>';
57
	}
58
	return $out;
59
}
60

    
61

    
62
/**
63
 * renders misapplied names and invalid designations.
64
 * Both relation types are currently treated the same!
65
 *
66
 * @param unknown_type $taxonRelationships
67
 * @return unknown
68
 */
69
function theme_cdm_taxonRelationships($taxonRelationships){
70

    
71
	if(!$taxonRelationships){
72
		return;
73
	}
74

    
75
	RenderHints::pushToRenderStack('taxonRelationships');
76
	$footnoteListKey = 'taxonRelationships';
77
	RenderHints::setFootnoteListKey($footnoteListKey);
78

    
79
	$misapplied = array();
80
	$joinedAuthorTeams = array();
81

    
82
	$taxon_relationship_types = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
83

    
84
	// aggregate misapplied names having the same fullname:
85
	foreach($taxonRelationships as $taxonRelation){
86

    
87
	    if( in_array($taxonRelation->type->uuid, $taxon_relationship_types)) {
88

    
89
    		if( $taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR ){
90

    
91
    			$name = $taxonRelation->fromTaxon->name->titleCache;
92

    
93
    			$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $taxonRelation->fromTaxon->sec->uuid);
94
    			$authorteam = $author_team->titleCache;
95

    
96
    			if(!isset($misapplied[$name])){
97
    				$misapplied[$name]['out'] =
98
    				  '<span class="misapplied">'
99
    				  .theme('cdm_related_taxon',$taxonRelation->fromTaxon, UUID_MISAPPLIED_NAME_FOR).
100
    				  '</span>';
101
    			}
102

    
103
    			// collect all authors for this fullname
104
    			if(isset($authorteam)){
105
    				$misapplied[$name]['authorteam'][$authorteam] = '';
106
    				$joinedAuthorTeams[$authorteam] = 'sensu '.theme('cdm_reference', $taxonRelation->fromTaxon->sec);
107
    			}
108

    
109
    		}
110
	    } else {
111
	       $taxonRelationshipsLines[] = theme('cdm_related_taxon',$taxonRelation->fromTaxon, $taxonRelation->type->uuid, $taxonRelation->type->representation_L10n_abbreviatedLabel);
112
	    }
113
	}
114

    
115
	// sort the joinedAuthorTeams and create footnotes and footnotekeys
116
	ksort($joinedAuthorTeams);
117
	foreach($joinedAuthorTeams as $authorteam=>$sensuCitation){
118
		$footnoteKey = FootnoteManager::addNewFootnote($footnoteListKey, $sensuCitation);
119
		$joinedAuthorTeams[$authorteam] = '<span class="sensu">sensu '.$authorteam. theme('cdm_footnote_key', $footnoteKey).'</span>';
120
	}
121

    
122
	// generate output
123
	$out = '<ul class="misapplied">';
124

    
125
	foreach($misapplied as $misapplied_name){
126

    
127
		$out .= '<li class="synonym">'.$misapplied_name['out'] . " ";
128
		if(isset($misapplied_name['authorteam'])){
129
			// fill authors with the renderedFootnoteKey and sorting 'em
130
			foreach($misapplied_name['authorteam'] as $authorteam=>&$renderedFootnoteKey) {
131
				$renderedFootnoteKey = $joinedAuthorTeams[$authorteam];
132
			}
133
				ksort($misapplied_name['authorteam']);
134
				$out .= join('; ', $misapplied_name['authorteam']);
135
		}
136
		$out .= '</li>';
137

    
138
	}
139
	$out .= '</ul>';
140

    
141
	$tr_footnotes = theme('cdm_footnotes', $footnoteListKey, 'li');
142
	$tr_footnotes_exploded = explode('sensu', $tr_footnotes);
143
	$tr_footnotes_aux = '';
144
	foreach ($tr_footnotes_exploded as $element){
145
		$tr_footnotes_aux .= $element;
146
	}
147
	$out .= '<ul>' . $tr_footnotes_aux . '</ul>';
148
	//$out .= '</ul>';
149
	RenderHints::popFromRenderStack();
150
	return $out;
151
}
152

    
153
function theme_cdm_acceptedFor(){
154
	RenderHints::pushToRenderStack('acceptedFor');
155

    
156
	$out = '';
157
	if(isset($_REQUEST['acceptedFor'])){
158

    
159
		$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $_REQUEST['acceptedFor']);
160

    
161
		if($synonym){
162
			$out .= '<span class="acceptedFor">';
163
			$out .= t('is accepted for ');
164
			if(isset($synonym->name->nomenclaturalReference)){
165
				$referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid));
166
			}
167
			$out .= theme('cdm_taxonName', $synonym->name, null, $referenceUri);
168
			$out .= theme('cdm_annotations_as_footnotekeys', $synonym);
169
			$out .= '</span>';
170
		}
171
	}
172
	RenderHints::popFromRenderStack();
173
	return $out;
174
}
175

    
176
function theme_cdm_list_of_taxa($records, $showMedia = false){
177

    
178
	RenderHints::pushToRenderStack('list_of_taxa');
179

    
180
	$form_name = 'search_gallery';
181
	//$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
182
    //$gallery_settings = variable_get($form_name, $default_values);
183

    
184
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
185

    
186
	$showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails'];
187
	$showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails'];
188
	//$showMedia_taxa = variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1);
189
	//$showMedia_synonyms = variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0);
190

    
191
	$classification_uuid = get_taxonomictree_uuid_selected();
192

    
193
	// .. well, for sure not as performant as before, but better than nothing.
194
	$synonym_uuids = array();
195
	foreach($records as $taxon){
196
		if($taxon->class != "Taxon"){
197
			if(!array_key_exists($taxon->uuid, $synonym_uuids)){
198
				$synonym_uuids[$taxon->uuid] = $taxon->uuid;
199
			}
200
		}
201
	}
202
	// batch service not jet implemented:
203
	// $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED, join(',', $synonym_uuids));
204
	// thus ...
205
	$table_of_accepted = array();
206

    
207
	foreach($synonym_uuids as $synUuid){
208
		$table_of_accepted[$synUuid] = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($synUuid, $classification_uuid));
209
	}
210

    
211
	$out = '<ul class="cdm_names" style="background-image: none;">';
212

    
213
	foreach($records as $taxon){
214
		// its a Taxon
215
		if($taxon->class == "Taxon"){
216
			$taxonUri = url(path_to_taxon($taxon->uuid));
217
			if(isset($taxon->name->nomenclaturalReference)){
218
				$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
219
			}
220
			$out .= '<li class="Taxon">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
221
			$out .= theme('cdm_annotations_as_footnotekeys', $taxon);
222

    
223
			if($showMedia_taxa){
224
				$out .= theme('cdm_taxon_list_thumbnails', $taxon);
225
			}
226
			$out .= '</li>';
227
		} else {
228
			// its a synonym
229
			$uuid = $taxon->uuid;
230
			$acceptedTaxa = $table_of_accepted[$uuid];
231
			if(count($acceptedTaxa) == 1){
232
				$acceptedTaxon = $acceptedTaxa[0];
233
				$taxonUri = theme('cdm_uri_to_synonym', $taxon->uuid, $acceptedTaxon->uuid, 'synonymy');
234
				if(isset($acceptedTaxon->name->nomenclaturalReference)){
235
					$referenceUri = url(path_to_reference($acceptedTaxon->name->nomenclaturalReference->uuid));
236
				}
237
				$out .= '<li class="Synonym">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
238
				$out .= theme('cdm_annotations_as_footnotekeys', $taxon);
239
				if($showMedia_synonyms){
240
					$out .= theme('cdm_taxon_list_thumbnails', $acceptedTaxon);
241
				}
242
				$out .= '</li>';
243
			} else {
244
				//TODO avoid using Ajax in the cdm_dynabox .... why?
245
				//TODO add media
246
				$out .= cdm_dynabox(
247
				  theme('cdm_taxonName', $taxon->name, null, null, false),
248
				  cdm_compose_url(CDM_WS_PORTAL_TAXON_ACCEPTED, array($taxon->uuid, $classification_uuid)),
249
				  'cdm_list_of_taxa',
250
				  'Click for accepted taxon');
251
			}
252
		}
253
	}
254

    
255
	$out .= '</ul>';
256
	RenderHints::popFromRenderStack();
257
	return $out;
258
}
259

    
260

    
261
function theme_cdm_related_taxon($taxon, $reltype_uuid = false, $relsign = null){
262

    
263
	static $relsign_homo = '≡';
264
	static $relsign_hetero = '=';
265
	static $relsign_invalid = '&ndash;';
266

    
267
  $relsign = '';
268
	$name_prefix = '';
269
	$name_postfix = '';
270

    
271
	$skiptags = array();
272

    
273
	if(!$relsign) {
274

    
275
       	switch ($reltype_uuid){
276
    		case UUID_HETEROTYPIC_SYNONYM_OF:
277
    		case UUID_SYNONYM_OF:
278
    			$relsign = $relsign_hetero;
279
    			break;
280
    		case UUID_HOMOTYPIC_SYNONYM_OF:
281
    			$relsign = $relsign_homo;
282
    			break;
283
    		case UUID_MISAPPLIED_NAME_FOR:
284
    		case UUID_INVALID_DESIGNATION_FOR:
285
    			$skiptags[] = 'authors';
286
    			$relsign = $relsign_invalid;
287
    			$name_prefix = '"';
288
    			$name_postfix = '"';
289
    			break;
290
    		default :
291
    			$relsign = $relsign_invalid;
292
	    }
293
	}
294
	/*
295
	 * names with status invalid or nudum are to be displayed with the $relsign_invalid,
296
	 * these names appear at the end of all names in their homotypic group
297
	 * (ordered correctly by the java cdm_lib)
298
	 */
299
	if ( is_array($taxon->name->status)) {
300
		foreach($taxon->name->status as $status){
301
			if ($status->type->uuid == UUID_NOMENCLATURALSTATUS_TYPE_INVALID || $status->type->uuid == UUID_NOMENCLATURALSTATUS_TYPE_NUDUM){
302
				$relsign = $relsign_invalid;
303
			}
304
		}
305
	}
306

    
307
	// now rendering starts ..
308

    
309
	RenderHints::pushToRenderStack('related_taxon');
310

    
311
	//$taxonUri = url(path_to_taxon($taxon->uuid));
312
	if($taxon->name->nomenclaturalReference){
313
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
314
	}
315
	//printing the taxonName and the handling the special case of annotations
316
	$nameHtml = theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri, true, false, $skiptags);
317
	$special_annotations_array = array();
318
	$special_annotations_array[] = $taxon->name;
319
	$special_annotations_array[] = $taxon;
320
	$nameHtml .= theme('cdm_annotations_as_footnotekeys', $special_annotations_array);
321

    
322
	//later homonym or trated as later homonym AND bloking names
323
	$from_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS, $taxon->uuid);
324
	$to_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
325
	//first the FROM RELS
326
	if ($from_name_relations){
327
		foreach($from_name_relations as $element){
328
			switch ($element->type->representation_L10n){
329
				case 'later homonym for':
330
					if(isset($name_relations_html)){
331
						$name_relations_html .= ' nec ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
332
						    'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid);
333
					}else{
334
						$name_relations_html = ' non ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
335
                        'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid)
336
						. ' ' . $element->toName->datePublished->start;
337
					}
338
					break;
339
				case 'treated as later homonym for':
340
					if(isset($name_relations_html)){
341
						$name_relations_html = ' nec ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
342
                              'cdm_dataportal/name/' . $element->toName->uuid);
343
					}else{
344
						$name_relations_html = ' non ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
345
					                   'cdm_dataportal/name/' . $element->toName->uuid);
346
					}
347
					break;
348
			}
349
		}
350
		//second the TO RELS
351
		if ($to_name_relations){
352
			foreach($to_name_relations as $element){
353
				switch ($element->type->representation_L10n){
354
					case 'blocking name for':
355
						if(isset($name_relations_html) ){
356
							$name_relations_html .= ' nec ' . l($element->fromName->titleCache . ' ' .  substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
357
                'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid);
358
						}else{
359
							$name_relations_html = ' non ' . l($element->fromName->titleCache . ' ' .  substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
360
                        'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid)
361
							. ' ' . $element->fromName->datePublished->start;
362
						}
363
						break;
364
				}
365
			}
366
		}
367
    //rels output
368
		if(isset($name_relations_html)){
369
			$name_relations_html = '['. $name_relations_html .']';
370
		}
371
	}
372
  //geneal output
373
	$out = '<span class="relation_sign">'.$relsign.'</span>'.$name_prefix . $nameHtml . $name_postfix . $name_relations_html;
374
	$out = uuid_anchor($taxon->uuid, $out);
375

    
376
	RenderHints::popFromRenderStack();
377

    
378
	return $out;
379
}
380

    
381
/**
382
 */
383
function theme_cdm_taxon_list_thumbnails($taxon){
384

    
385

    
386
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
387
	$showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
388

    
389
	if($showCaption){
390
		$captionElements = array('title', 'rights');
391
	}
392

    
393
	$gallery_name = $taxon->uuid;
394

    
395
 	$mediaQueryParameters = array("type"=>"ImageFile");
396
	$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
397

    
398
	// cdm_dataportal_show_media = ???? TODO
399
	$selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
400
	if ($selectShowMedia == 0){
401
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
402
	}else{
403
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
404
	}
405

    
406
	$out .= theme('cdm_media_gallerie', $mediaList, $gallery_name ,
407
    	$gallery_settings['cdm_dataportal_media_maxextend'],
408
    	$gallery_settings['cdm_dataportal_media_cols'],
409
    	$gallery_settings['cdm_dataportal_media_maxRows'],
410
    	$captionElements, 'LIGHTBOX', null, $galleryLinkUri);
411

    
412
	return $out;
413
}
414

    
415

    
(8-8/8)