Project

General

Profile

Download (10.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').'/pageoptions|searchtaxa|showThumbnails/';
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
			$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $taxonRelation->fromTaxon->sec->uuid);
86
			$authorteam = $author_team->titleCache;
87

    
88
			if(!isset($misapplied[$name])){
89
				$misapplied[$name]['out'] = '<span class="misapplied">'.theme('cdm_related_taxon',$taxonRelation->fromTaxon, UUID_MISAPPLIED_NAME_FOR, false).'</span>';
90
			}
91

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

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

    
108
	// generate output
109
	$out = '<ul class="misapplied">';
110
	
111
	foreach($misapplied as $misapplied_name){
112
		
113
		$out .= '<li class="synonym">'.$misapplied_name['out'] . " ";
114
		// fill authors the renderedFootnoteKey and sorting 'em
115
		foreach($misapplied_name['authorteam'] as $authorteam=>&$renderedFootnoteKey) {
116
		  $renderedFootnoteKey = $joinedAuthorTeams[$authorteam];
117
	    }
118
		if(isset($misapplied_name['authorteam'])){
119
			ksort($misapplied_name['authorteam']);
120
			$out .= join('; ', $misapplied_name['authorteam']);
121
		}
122
		$out .= '</li>';
123
		
124
	}
125
	$out .= '</ul>';
126
	
127
    RenderHints::popFromRenderStack();
128
	return $out;
129
}
130

    
131
function theme_cdm_acceptedFor(){
132
	RenderHints::pushToRenderStack('acceptedFor');
133
		
134
	$out = '';
135
	if(isset($_REQUEST['acceptedFor'])){
136
			
137
		$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $_REQUEST['acceptedFor']);
138
			
139
		if($synonym){
140
			$out .= '<span class="acceptedFor">';
141
			$out .= t('is accepted for ');
142
			if(isset($synonym->name->nomenclaturalReference)){
143
				$referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid));
144
			}
145
			$out .= theme('cdm_taxonName', $synonym->name, null, $referenceUri);
146
			$out .= '</span>';
147
		}
148
	}
149
    RenderHints::popFromRenderStack();
150
	return $out;
151
}
152

    
153
function theme_cdm_list_of_taxa($records, $showMedia = false){
154

    
155
	RenderHints::pushToRenderStack('list_of_taxa');
156

    
157
	$showMedia_taxa = variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1);
158
	$showMedia_synonyms = variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0);
159

    
160
	// .. well, for sure not as performant as before, but better than nothing.
161
	$synonym_uuids = array();
162
	foreach($records as $taxon){
163
		if($taxon->class != "Taxon"){
164
			if(!array_key_exists($taxon->uuid, $synonym_uuids)){
165
				$synonym_uuids[$taxon->uuid] = $taxon->uuid;
166
			}
167
		}
168
	}
169
	// batch service not jet implemented:
170
	// $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED, join(',', $synonym_uuids));
171
	// thus ...
172
	$table_of_accepted = array();
173
	foreach($synonym_uuids as $synUuid){
174
		$table_of_accepted[$synUuid] = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, $synUuid);
175
	}
176

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

    
179
	foreach($records as $taxon){
180
		// its a Taxon
181
		if($taxon->class == "Taxon"){
182
			$taxonUri = url(path_to_taxon($taxon->uuid));
183
			if(isset($taxon->name->nomenclaturalReference)){
184
				$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
185
			}
186
			$out .= '<li class="Taxon">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
187
			if($showMedia_taxa){
188
				$out .= theme('cdm_taxon_list_thumbnails', $taxon);
189
			}
190
			$out .= '</li>';
191
		} else {
192
			// its a synonym
193
			$uuid = $taxon->uuid;
194
			$acceptedTaxa = $table_of_accepted[$uuid];
195
			if(count($acceptedTaxa) == 1){
196
				$acceptedTaxon = $acceptedTaxa[0];
197
				$taxonUri = uri_to_synonym($taxon->uuid, $acceptedTaxon->uuid, 'synonymy');
198
				if(isset($acceptedTaxon->name->nomenclaturalReference)){
199
					$referenceUri = url(path_to_reference($acceptedTaxon->name->nomenclaturalReference->uuid));
200
				}
201
				$out .= '<li class="Synonym">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
202
				if($showMedia_synonyms){
203
					$out .= theme('cdm_taxon_list_thumbnails', $acceptedTaxon);
204
				}
205
				$out .= '</li>';
206
			} else {
207
				//TODO avoid using Ajax in the cdm_dynabox
208
				//TODO add media
209
				$out .= theme('cdm_dynabox', theme('cdm_taxonName', $taxon->name, null, null), cdm_compose_url(CDM_WS_PORTAL_TAXON_ACCEPTED, array($taxon->uuid)), 'cdm_list_of_taxa');
210
			}
211
		}
212
	}
213
	$out .= '</ul>';
214
	RenderHints::popFromRenderStack();
215
	return $out;
216
}
217

    
218

    
219
function theme_cdm_related_taxon($taxon, $reltype_uuid = false){
220

    
221
	$relsign = '';
222
	$name_prefix = '';
223
	$name_postfix = '';
224
	switch ($reltype_uuid){
225
		case UUID_HETEROTYPIC_SYNONYM_OF:
226
		case UUID_SYNONYM_OF:
227
			$relsign = '=';
228
			break;
229
		case UUID_HOMOTYPIC_SYNONYM_OF:
230
			$relsign = '≡';
231
			break;
232
		case UUID_MISAPPLIED_NAME_FOR:
233
		case UUID_INVALID_DESIGNATION_FOR:
234
			$relsign = '&ndash;'; // &ndash; &mdash; &minus;
235
			$name_prefix = '"';
236
			$name_postfix = '"';
237
			break;
238
		default :
239
			$relsign = '&ndash;';
240
	}
241

    
242
	 RenderHints::pushToRenderStack('related_taxon');
243

    
244
	//$taxonUri = url(path_to_taxon($taxon->uuid));
245
	if($taxon->name->nomenclaturalReference){
246
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
247
	}
248
	$nameHtml = theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
249
	
250
	//later homonym or trated as later homonym
251
	$taxon_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMERELATIONS, $taxon->uuid);
252
	foreach($taxon_name_relations as $element){	
253
    switch ($element->type->representation_L10n){
254
      case 'later homonym for':
255
        $later_homonym = ' [non ' . l($element->fromName->titleCache . ']', 
256
                                     'cdm_dataportal/name/' . $element->fromName->uuid);
257
        break;
258
    case 'treated as later homonym for':
259
        $later_homonym = ' [non ' . l($element->fromName->titleCache . ']', 
260
                                     'cdm_dataportal/name/' . $element->fromName->uuid);
261
        break;
262
    }	
263
	}
264

    
265

    
266
	$out = '<span class="relation_sign">'.$relsign.'</span>'.$name_prefix . $nameHtml . $name_postfix . $later_homonym;
267
	
268
  //var_dump($taxon_name_relations[0]->type->representation_L10n);  
269
	
270
	$out = uuid_anchor($taxon->uuid, $out);
271
	
272
	RenderHints::popFromRenderStack();
273
	
274
	return $out; 
275
}
276

    
277

    
278
/**
279
 */
280
function theme_cdm_taxon_list_thumbnails($taxon){
281

    
282
	$gallery_name = $taxon->uuid;
283

    
284
	$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 1);
285
	$prefMimeTypeRegex = 'image:.*';
286
	$prefMediaQuality = '*';
287

    
288
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
289
	
290
	if($showCaption){
291
		//$captionElements = array('title', '#uri'=>t('open Image'));
292
		$captionElements = array('title', 'rights');
293
	}
294

    
295
	$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
296
	$selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
297
	if ($selectShowMedia == 0){
298
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
299
	}else{
300
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
301
	}
302
	//$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_MEDIA, array(variable_get('cdm_taxonomictree_uuid', false), $taxon ->rank, $taxon->uuid ));
303
	$out .= theme('cdm_media_gallerie', $mediaList, $gallery_name ,
304
					$gallery_settings['cdm_dataportal_media_maxextend'], 
305
	             	$gallery_settings['cdm_dataportal_media_cols'], 
306
	             	$gallery_settings['cdm_dataportal_media_maxRows'], 
307
	             	$captionElements, 'LIGHTBOX', null, $galleryLinkUri);
308

    
309
	return $out;
310
}
311

    
312

    
(8-8/8)