Project

General

Profile

Download (14.4 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
	// aggregate misapplied names having the same fullname:
83
	foreach($taxonRelationships as $taxonRelation){
84
		if(true || $taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR ){
85

    
86
			$name = $taxonRelation->fromTaxon->name->titleCache;
87

    
88
			$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $taxonRelation->fromTaxon->sec->uuid);
89
			$authorteam = $author_team->titleCache;
90

    
91
			if(!isset($misapplied[$name])){
92
				$misapplied[$name]['out'] =
93
				  '<span class="misapplied">'
94
				  .theme('cdm_related_taxon',$taxonRelation->fromTaxon, UUID_MISAPPLIED_NAME_FOR, false).
95
				  '</span>';
96
			}
97

    
98
			// collect all authors for this fullname
99
			if(isset($authorteam)){
100
				$misapplied[$name]['authorteam'][$authorteam] = '';
101
				$joinedAuthorTeams[$authorteam] = 'sensu '.theme('cdm_reference', $taxonRelation->fromTaxon->sec);
102
			}
103

    
104
		}
105
	}
106

    
107
	// sort the joinedAuthorTeams and create footnotes and footnotekeys
108
	ksort($joinedAuthorTeams);
109
	foreach($joinedAuthorTeams as $authorteam=>$sensuCitation){
110
		$footnoteKey = FootnoteManager::addNewFootnote($footnoteListKey, $sensuCitation);
111
		$joinedAuthorTeams[$authorteam] = '<span class="sensu">sensu '.$authorteam. theme('cdm_footnote_key', $footnoteKey).'</span>';
112
	}
113

    
114
	// generate output
115
	$out = '<ul class="misapplied">';
116

    
117
	foreach($misapplied as $misapplied_name){
118

    
119
		$out .= '<li class="synonym">'.$misapplied_name['out'] . " ";
120
		if(isset($misapplied_name['authorteam'])){
121
			// fill authors with the renderedFootnoteKey and sorting 'em
122
			foreach($misapplied_name['authorteam'] as $authorteam=>&$renderedFootnoteKey) {
123
				$renderedFootnoteKey = $joinedAuthorTeams[$authorteam];
124
			}
125
				ksort($misapplied_name['authorteam']);
126
				$out .= join('; ', $misapplied_name['authorteam']);
127
		}
128
		$out .= '</li>';
129

    
130
	}
131
	$out .= '</ul>';
132

    
133
	$tr_footnotes = theme('cdm_footnotes', $footnoteListKey, 'li');
134
	$tr_footnotes_exploded = explode('sensu', $tr_footnotes);
135
	$tr_footnotes_aux = '';
136
	foreach ($tr_footnotes_exploded as $element){
137
		$tr_footnotes_aux .= $element;
138
	}
139
	$out .= '<ul>' . $tr_footnotes_aux . '</ul>';
140
	//$out .= '</ul>';
141
	RenderHints::popFromRenderStack();
142
	return $out;
143
}
144

    
145
function theme_cdm_acceptedFor(){
146
	RenderHints::pushToRenderStack('acceptedFor');
147

    
148
	$out = '';
149
	if(isset($_REQUEST['acceptedFor'])){
150

    
151
		$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $_REQUEST['acceptedFor']);
152

    
153
		if($synonym){
154
			$out .= '<span class="acceptedFor">';
155
			$out .= t('is accepted for ');
156
			if(isset($synonym->name->nomenclaturalReference)){
157
				$referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid));
158
			}
159
			$out .= theme('cdm_taxonName', $synonym->name, null, $referenceUri);
160
			$out .= theme('cdm_annotations_as_footnotekeys', $synonym);
161
			$out .= '</span>';
162
		}
163
	}
164
	RenderHints::popFromRenderStack();
165
	return $out;
166
}
167

    
168
function theme_cdm_list_of_taxa($records, $showMedia = false){
169

    
170
	RenderHints::pushToRenderStack('list_of_taxa');
171

    
172
	$form_name = 'search_gallery';
173
	//$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
174
    //$gallery_settings = variable_get($form_name, $default_values);
175

    
176
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
177

    
178
	$showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails'];
179
	$showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails'];
180
	//$showMedia_taxa = variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1);
181
	//$showMedia_synonyms = variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0);
182

    
183
	$classification_uuid = get_taxonomictree_uuid_selected();
184

    
185
	// .. well, for sure not as performant as before, but better than nothing.
186
	$synonym_uuids = array();
187
	foreach($records as $taxon){
188
		if($taxon->class != "Taxon"){
189
			if(!array_key_exists($taxon->uuid, $synonym_uuids)){
190
				$synonym_uuids[$taxon->uuid] = $taxon->uuid;
191
			}
192
		}
193
	}
194
	// batch service not jet implemented:
195
	// $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED, join(',', $synonym_uuids));
196
	// thus ...
197
	$table_of_accepted = array();
198

    
199
	foreach($synonym_uuids as $synUuid){
200
		$table_of_accepted[$synUuid] = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($synUuid, $classification_uuid));
201
	}
202

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

    
205
	foreach($records as $taxon){
206
		// its a Taxon
207
		if($taxon->class == "Taxon"){
208
			$taxonUri = url(path_to_taxon($taxon->uuid));
209
			if(isset($taxon->name->nomenclaturalReference)){
210
				$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
211
			}
212
			$out .= '<li class="Taxon">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
213
			$out .= theme('cdm_annotations_as_footnotekeys', $taxon);
214

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

    
247
	$out .= '</ul>';
248
	RenderHints::popFromRenderStack();
249
	return $out;
250
}
251

    
252

    
253
function theme_cdm_related_taxon($taxon, $reltype_uuid = false){
254

    
255
	static $relsign_homo = '≡';
256
	static $relsign_hetero = '=';
257
	static $relsign_invalid = '&ndash;';
258

    
259
  $relsign = '';
260
	$name_prefix = '';
261
	$name_postfix = '';
262

    
263
	$skiptags = array();
264

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

    
296
	// now rendering starts ..
297

    
298
	RenderHints::pushToRenderStack('related_taxon');
299

    
300
	//$taxonUri = url(path_to_taxon($taxon->uuid));
301
	if($taxon->name->nomenclaturalReference){
302
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
303
	}
304
	//printing the taxonName and the handling the special case of annotations
305
	$nameHtml = theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri, true, false, $skiptags);
306
	$special_annotations_array = array();
307
	$special_annotations_array[] = $taxon->name;
308
	$special_annotations_array[] = $taxon;
309
	$nameHtml .= theme('cdm_annotations_as_footnotekeys', $special_annotations_array);
310

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

    
365
	RenderHints::popFromRenderStack();
366

    
367
	return $out;
368
}
369

    
370
/**
371
 */
372
function theme_cdm_taxon_list_thumbnails($taxon){
373

    
374

    
375
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
376
	$showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
377

    
378
	if($showCaption){
379
		$captionElements = array('title', 'rights');
380
	}
381

    
382
	$gallery_name = $taxon->uuid;
383

    
384
 	$mediaQueryParameters = array("type"=>"ImageFile");
385
	$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
386

    
387
	// cdm_dataportal_show_media = ???? TODO
388
	$selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
389
	if ($selectShowMedia == 0){
390
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
391
	}else{
392
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
393
	}
394

    
395
	$out .= theme('cdm_media_gallerie', $mediaList, $gallery_name ,
396
    	$gallery_settings['cdm_dataportal_media_maxextend'],
397
    	$gallery_settings['cdm_dataportal_media_cols'],
398
    	$gallery_settings['cdm_dataportal_media_maxRows'],
399
    	$captionElements, 'LIGHTBOX', null, $galleryLinkUri);
400

    
401
	return $out;
402
}
403

    
404

    
(8-8/8)