Project

General

Profile

Download (13.7 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 .= 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
	$showMedia_taxa = variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1);
171
	$showMedia_synonyms = variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0);
172

    
173
	// .. well, for sure not as performant as before, but better than nothing.
174
	$synonym_uuids = array();
175
	foreach($records as $taxon){
176
		if($taxon->class != "Taxon"){
177
			if(!array_key_exists($taxon->uuid, $synonym_uuids)){
178
				$synonym_uuids[$taxon->uuid] = $taxon->uuid;
179
			}
180
		}
181
	}
182
	// batch service not jet implemented:
183
	// $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED, join(',', $synonym_uuids));
184
	// thus ...
185
	$table_of_accepted = array();
186
	foreach($synonym_uuids as $synUuid){
187
		$table_of_accepted[$synUuid] = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, $synUuid);
188
	}
189

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

    
192
	foreach($records as $taxon){
193
		// its a Taxon
194
		if($taxon->class == "Taxon"){
195
			$taxonUri = url(path_to_taxon($taxon->uuid));
196
			if(isset($taxon->name->nomenclaturalReference)){
197
				$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
198
			}
199
			$out .= '<li class="Taxon">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
200
			$out .= theme('cdm_annotations_as_footnotekeys', $taxon);
201

    
202
			if($showMedia_taxa){
203
				$out .= theme('cdm_taxon_list_thumbnails', $taxon);
204
			}
205
			$out .= '</li>';
206
		} else {
207
			// its a synonym
208
			$uuid = $taxon->uuid;
209
			$acceptedTaxa = $table_of_accepted[$uuid];
210
			if(count($acceptedTaxa) == 1){
211
				$acceptedTaxon = $acceptedTaxa[0];
212
				$taxonUri = theme('cdm_uri_to_synonym', $taxon->uuid, $acceptedTaxon->uuid, 'synonymy');
213
				if(isset($acceptedTaxon->name->nomenclaturalReference)){
214
					$referenceUri = url(path_to_reference($acceptedTaxon->name->nomenclaturalReference->uuid));
215
				}
216
				$out .= '<li class="Synonym">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
217
				$out .= theme('cdm_annotations_as_footnotekeys', $taxon);
218
				if($showMedia_synonyms){
219
					$out .= theme('cdm_taxon_list_thumbnails', $acceptedTaxon);
220
				}
221
				$out .= '</li>';
222
			} else {
223
				//TODO avoid using Ajax in the cdm_dynabox .... why?
224
				//TODO add media
225
				$out .= cdm_dynabox(
226
				  theme('cdm_taxonName', $taxon->name, null, null, false),
227
				  cdm_compose_url(CDM_WS_PORTAL_TAXON_ACCEPTED, array($taxon->uuid)),
228
				  'cdm_list_of_taxa',
229
				  'Click for accepted taxon');
230
			}
231
		}
232
	}
233
	$out .= '</ul>';
234
	RenderHints::popFromRenderStack();
235
	return $out;
236
}
237

    
238

    
239
function theme_cdm_related_taxon($taxon, $reltype_uuid = false){
240

    
241
	static $relsign_homo = '≡';
242
	static $relsign_hetero = '=';
243
	static $relsign_invalid = '&ndash;';
244

    
245
  $relsign = '';
246
	$name_prefix = '';
247
	$name_postfix = '';
248

    
249
	$skiptags = array();
250

    
251
	switch ($reltype_uuid){
252
		case UUID_HETEROTYPIC_SYNONYM_OF:
253
		case UUID_SYNONYM_OF:
254
			$relsign = $relsign_hetero;
255
			break;
256
		case UUID_HOMOTYPIC_SYNONYM_OF:
257
			$relsign = $relsign_homo;
258
			break;
259
		case UUID_MISAPPLIED_NAME_FOR:
260
		case UUID_INVALID_DESIGNATION_FOR:
261
			$skiptags[] = 'authors';
262
			$relsign = $relsign_invalid;
263
			$name_prefix = '"';
264
			$name_postfix = '"';
265
			break;
266
		default :
267
			$relsign = $relsign_invalid;
268
	}
269

    
270
	$status = $taxon->name->status[0]->type->representation_L10n;
271
	//if ($status == 'Invalid' || $status == 'Nudum'){
272
	if (sizeof($status) > 0){
273
		if ($status == 'Invalid' || $status == 'Nudum'){
274
			$relsign = $relsign_invalid;
275
		}
276
		$status = ', ' . $taxon->name->status[0]->type->representation_L10n_abbreviated;
277
		//var_dump('&mdash' . $taxon->name->status[0]->type->representation_L10n_abbreviated);
278
	}
279

    
280
	RenderHints::pushToRenderStack('related_taxon');
281

    
282
	//$taxonUri = url(path_to_taxon($taxon->uuid));
283
	if($taxon->name->nomenclaturalReference){
284
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
285
	}
286
	//printing the taxonName and the handling the special case of annotations
287
	$nameHtml = theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri, true, false, $skiptags);
288
	$special_annotations_array = array();
289
	$special_annotations_array[] = $taxon->name;
290
	$special_annotations_array[] = $taxon;
291
	$nameHtml .= theme('cdm_annotations_as_footnotekeys', $special_annotations_array);
292

    
293
	//later homonym or trated as later homonym AND bloking names
294
	$from_name_rels = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS, $taxon->uuid);
295
	$to_name_rels = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
296
	//first the FROM RELS
297
	if ($from_name_rels){
298
		foreach($from_name_rels as $element){
299
			switch ($element->type->representation_L10n){
300
				case 'later homonym for':
301
					if(isset($rels_out)){
302
						$rels_out .= ' nec ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
303
						    'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid);
304
					}else{
305
						$rels_out = ' non ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
306
                        'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid)
307
						. ' ' . $element->toName->datePublished->start;
308
					}
309
					break;
310
				case 'treated as later homonym for':
311
					if(isset($rels_out)){
312
						$rels_out = ' nec ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
313
                              'cdm_dataportal/name/' . $element->toName->uuid);
314
					}else{
315
						$rels_out = ' non ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
316
					                   'cdm_dataportal/name/' . $element->toName->uuid);
317
					}
318
					break;
319
			}
320
		}
321
		//second the TO RELS
322
		if ($to_name_rels){
323
			foreach($to_name_rels as $element){
324
				switch ($element->type->representation_L10n){
325
					case 'blocking name for':
326
						if(isset($rels_out) ){
327
							$rels_out .= ' nec ' . l($element->fromName->titleCache . ' ' .  substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
328
                'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid);
329
						}else{
330
							$rels_out = ' non ' . l($element->fromName->titleCache . ' ' .  substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
331
                        'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid)
332
							. ' ' . $element->fromName->datePublished->start;
333
						}
334
						break;
335
				}
336
			}
337
		}
338
    //rels output
339
		if(isset($rels_out)){
340
			$rels_out = '['. $rels_out .']';
341
		}
342
	}
343
  //geneal output
344
	$out = '<span class="relation_sign">'.$relsign.'</span>'.$name_prefix . $nameHtml . $name_postfix . $rels_out . $status;
345
	$out = uuid_anchor($taxon->uuid, $out);
346

    
347
	RenderHints::popFromRenderStack();
348

    
349
	return $out;
350
}
351

    
352
/**
353
 */
354
function theme_cdm_taxon_list_thumbnails($taxon){
355

    
356
	$gallery_name = $taxon->uuid;
357

    
358
	$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 1);
359
	$prefMimeTypeRegex = 'image:.*';
360
	$prefMediaQuality = '*';
361

    
362
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
363

    
364
	if($showCaption){
365
		//$captionElements = array('title', '#uri'=>t('open Image'));
366
		$captionElements = array('title', 'rights');
367
	}
368

    
369
	$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
370
	$selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
371
	if ($selectShowMedia == 0){
372
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
373
	}else{
374
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
375
	}
376
	//$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_MEDIA, array(variable_get('cdm_taxonomictree_uuid', false), $taxon ->rank, $taxon->uuid ));
377
	$out .= theme('cdm_media_gallerie', $mediaList, $gallery_name ,
378
	$gallery_settings['cdm_dataportal_media_maxextend'],
379
	$gallery_settings['cdm_dataportal_media_cols'],
380
	$gallery_settings['cdm_dataportal_media_maxRows'],
381
	$captionElements, 'LIGHTBOX', null, $galleryLinkUri);
382

    
383
	return $out;
384
}
385

    
386

    
(8-8/8)