Project

General

Profile

Download (13.5 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'] = '<span class="misapplied">'.theme('cdm_related_taxon',$taxonRelation->fromTaxon, UUID_MISAPPLIED_NAME_FOR, false).'</span>';
91
			}
92

    
93
			// collect all authors for this fullname
94
			if(isset($authorteam)){
95
				$misapplied[$name]['authorteam'][$authorteam] = '';
96
				$joinedAuthorTeams[$authorteam] = 'sensu '.theme('cdm_reference', $taxonRelation->fromTaxon->sec);
97
			}
98

    
99
		}
100
	}
101

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

    
109
	// generate output
110
	$out = '<ul class="misapplied">';
111

    
112
	foreach($misapplied as $misapplied_name){
113

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

    
125
	}
126
	//$out .= '</ul>';
127

    
128
	$tr_footnotes = theme('cdm_footnotes', $footnoteListKey, 'li');
129
	$tr_footnotes_exploded = explode('sensu', $tr_footnotes);
130
	$tr_footnotes_aux = '';
131
	foreach ($tr_footnotes_exploded as $element){
132
		$tr_footnotes_aux .= $element;
133
	}
134
	$out .= $tr_footnotes_aux;
135
	$out .= '</ul>';
136
	RenderHints::popFromRenderStack();
137
	return $out;
138
}
139

    
140
function theme_cdm_acceptedFor(){
141
	RenderHints::pushToRenderStack('acceptedFor');
142

    
143
	$out = '';
144
	if(isset($_REQUEST['acceptedFor'])){
145

    
146
		$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $_REQUEST['acceptedFor']);
147

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

    
163
function theme_cdm_list_of_taxa($records, $showMedia = false){
164

    
165
	RenderHints::pushToRenderStack('list_of_taxa');
166

    
167
	$showMedia_taxa = variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1);
168
	$showMedia_synonyms = variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0);
169

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

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

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

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

    
231

    
232
function theme_cdm_related_taxon($taxon, $reltype_uuid = false){
233

    
234
	static $relsign_homo = '≡';
235
	static $relsign_hetero = '=';
236
	static $relsign_invalid = '&ndash;';
237

    
238
	$relsign = '';
239
	$name_prefix = '';
240
	$name_postfix = '';
241

    
242
	switch ($reltype_uuid){
243
		case UUID_HETEROTYPIC_SYNONYM_OF:
244
		case UUID_SYNONYM_OF:
245
			$relsign = $relsign_hetero;
246
			break;
247
		case UUID_HOMOTYPIC_SYNONYM_OF:
248
			$relsign = $relsign_homo;
249
			break;
250
		case UUID_MISAPPLIED_NAME_FOR:
251
		case UUID_INVALID_DESIGNATION_FOR:
252
			$relsign = $relsign_invalid;
253
			$name_prefix = '"';
254
			$name_postfix = '"';
255
			break;
256
		default :
257
			$relsign = $relsign_invalid;
258
	}
259

    
260
	$status = $taxon->name->status[0]->type->representation_L10n;
261
	//if ($status == 'Invalid' || $status == 'Nudum'){
262
	if (sizeof($status) > 0){
263
		if ($status == 'Invalid' || $status == 'Nudum'){
264
			$relsign = $relsign_invalid;
265
		}
266
		$status = ', ' . $taxon->name->status[0]->type->representation_L10n_abbreviated;
267
		//var_dump('&mdash' . $taxon->name->status[0]->type->representation_L10n_abbreviated);
268
	}
269

    
270
	RenderHints::pushToRenderStack('related_taxon');
271

    
272
	//$taxonUri = url(path_to_taxon($taxon->uuid));
273
	if($taxon->name->nomenclaturalReference){
274
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
275
	}
276
	//printing the taxonName and the handling the special case of annotations
277
	$nameHtml = theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri, false);
278
	$special_annotations_array = array();
279
	$special_annotations_array[] = $taxon->name;
280
	$special_annotations_array[] = $taxon;
281
	$nameHtml .= theme('cdm_annotations_as_footnotekeys', $special_annotations_array);
282

    
283
	//later homonym or trated as later homonym AND bloking names
284
	$from_name_rels = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS, $taxon->uuid);
285
	$to_name_rels = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
286
	//first the FROM RELS
287
	if ($from_name_rels){
288
		foreach($from_name_rels as $element){
289
			switch ($element->type->representation_L10n){
290
				case 'later homonym for':
291
					if(isset($rels_out)){
292
						$rels_out .= ' nec ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
293
						    'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid);
294
					}else{
295
						$rels_out = ' non ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
296
                        'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid)
297
						. ' ' . $element->toName->datePublished->start;
298
					}
299
					break;
300
				case 'treated as 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);
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);
307
					}
308
					break;
309
			}
310
		}
311
		//second the TO RELS
312
		if ($to_name_rels){
313
			foreach($to_name_rels as $element){
314
				switch ($element->type->representation_L10n){
315
					case 'blocking name for':
316
						if(isset($rels_out) ){
317
							$rels_out .= ' nec ' . l($element->fromName->titleCache . ' ' .  substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
318
                'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid);
319
						}else{
320
							$rels_out = ' non ' . l($element->fromName->titleCache . ' ' .  substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
321
                        'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid)
322
							. ' ' . $element->fromName->datePublished->start;
323
						}
324
						break;
325
				}
326
			}
327
		}
328
    //rels output
329
		if(isset($rels_out)){
330
			$rels_out = '['. $rels_out .']';
331
		}
332
	}
333
  //geneal output
334
	$out = '<span class="relation_sign">'.$relsign.'</span>'.$name_prefix . $nameHtml . $name_postfix . $rels_out . $status;
335
	$out = uuid_anchor($taxon->uuid, $out);
336

    
337
	RenderHints::popFromRenderStack();
338

    
339
	return $out;
340
}
341

    
342
/**
343
 */
344
function theme_cdm_taxon_list_thumbnails($taxon){
345

    
346
	$gallery_name = $taxon->uuid;
347

    
348
	$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 1);
349
	$prefMimeTypeRegex = 'image:.*';
350
	$prefMediaQuality = '*';
351

    
352
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
353

    
354
	if($showCaption){
355
		//$captionElements = array('title', '#uri'=>t('open Image'));
356
		$captionElements = array('title', 'rights');
357
	}
358

    
359
	$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
360
	$selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
361
	if ($selectShowMedia == 0){
362
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
363
	}else{
364
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
365
	}
366
	//$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_MEDIA, array(variable_get('cdm_taxonomictree_uuid', false), $taxon ->rank, $taxon->uuid ));
367
	$out .= theme('cdm_media_gallerie', $mediaList, $gallery_name ,
368
	$gallery_settings['cdm_dataportal_media_maxextend'],
369
	$gallery_settings['cdm_dataportal_media_cols'],
370
	$gallery_settings['cdm_dataportal_media_maxRows'],
371
	$captionElements, 'LIGHTBOX', null, $galleryLinkUri);
372

    
373
	return $out;
374
}
375

    
376

    
(8-8/8)