Project

General

Profile

Download (25.6 KB) Statistics
| Branch: | Tag: | Revision:
1 806baeb2 Andreas Kohlbecker
<?php
2
// $Id$
3
4
/**
5 75b05e16 f.revilla
 * 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 806baeb2 Andreas Kohlbecker
13 75b05e16 f.revilla
/**
14
 * This function prints the lectotype citation with the correct layout
15
 * Lectotypes are renderized in the synonymy tab of a taxon if they exist
16
 * @param $typeDesignation_citation The lectotype citation to print
17
 * @return html valid string
18
 */
19 44b1626d f.revilla
function type_designation_citation_layout($typeDesignation, $footnote_separator = ','){
20 75b05e16 f.revilla
	$res = '';
21 12196fd5 f.revilla
	$citation = $typeDesignation->citation;
22
	$pages = $typeDesignation->citationMicroReference;
23 8aabc503 f.revilla
24
	if ($typeDesignation->typeStatus->uuid == UUID_ORIGINAL_DESIGNATION ||
25
	$typeDesignation->typeStatus->uuid == UUID_MONOTYPE){
26
		$res = ' ('. $typeDesignation->typeStatus->representation_L10n . ')';
27
		return $res;
28
	}
29 44b1626d f.revilla
30
	if ($citation){
31 8aabc503 f.revilla
		//$type = $typeDesignation_citation->type;
32
	$year = substr($citation->datePublished->start, 0, 4);
33
	$author = $citation->authorTeam->titleCache;
34
	$res .= ' (designated by ';
35
	$res .= $author;
36
	$res .= ($year ? ' '.$year : '');
37
	$res .= ($pages ? ': '. $pages : '');
38
	//$res .= ')';
39
40
	$fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-typeDesignations', $typeDesignation->citation->titleCache);
41
	$res .= theme('cdm_footnote_key', $fkey_typeDesignation, $footnote_separator, true, true) . ')';
42 2efb8f43 Andreas Kohlbecker
43 8aabc503 f.revilla
}
44
return $res;
45 75b05e16 f.revilla
}
46 806baeb2 Andreas Kohlbecker
47 b32739d9 f.revilla
function contains_type_designation ($element, $collection){
48
    $result = false;
49
    foreach ($collection as $a){
50
    	if($a->uuid == $element->uuid){
51
    		$result = true;
52
    	}
53
    }
54
    return $result;
55
}
56
57
function cdm_add_type_designations ($source, $extra) {
58 a515d38e f.revilla
	if (is_array($source)){
59 75aa3e52 f.revilla
	   $result = $source;
60
        if ($extra){
61 ac168ae1 Andreas Kohlbecker
            foreach ($extra as $element) {
62 75aa3e52 f.revilla
                if (!contains_type_designation($element, $source)){
63
                $result[] = $element;
64
            }
65 a515d38e f.revilla
        }
66 75aa3e52 f.revilla
    }
67 a515d38e f.revilla
	}else {
68 75aa3e52 f.revilla
		$result = $extra;
69 a515d38e f.revilla
	}
70 ac168ae1 Andreas Kohlbecker
71 b32739d9 f.revilla
    return $result;
72
}
73
74 806baeb2 Andreas Kohlbecker
function theme_cdm_typedesignations($typeDesignations = array()){
75 6d589240 f.revilla
	/*
76
	 if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
77
	 $microreference = null;
78
	 if(isset($renderTemplate['referencePart']['microreference'])){
79
	 $microreference = $taxonName->nomenclaturalMicroReference;
80
	 }
81
	 $citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($typeDesignation->uuid), "microReference=".urlencode($microreference));
82
	 $citation = $citation->String;
83
	 */
84
85 ac168ae1 Andreas Kohlbecker
	RenderHints::pushToRenderStack('typedesignations');
86 806baeb2 Andreas Kohlbecker
	$out = '<ul class="typeDesignations">';
87 6d589240 f.revilla
	$typeDesignation_footnotes = false;
88 300375f2 f.revilla
	$is_lectotype = false;
89 806baeb2 Andreas Kohlbecker
	$specimenTypeDesignations = array();
90 1f5b7a24 f.revilla
	$separator = ',';
91 806baeb2 Andreas Kohlbecker
	foreach($typeDesignations as $typeDesignation){
92
		if($typeDesignation->class == 'SpecimenTypeDesignation'){
93 75b05e16 f.revilla
			// SpecimenTypeDesignations should be ordered. collect theme here only
94 806baeb2 Andreas Kohlbecker
			$specimenTypeDesignations[] = $typeDesignation;
95 300375f2 f.revilla
		}else{ //it is a lectotype?
96
			if(strcmp($typeDesignation->typeStatus->titleCache, 'lectotype') == 0){
97 8aabc503 f.revilla
				$is_lectotype = true;
98
			}
99 806baeb2 Andreas Kohlbecker
			// it's a NameTypeDesignation
100 d74aa4df Andreas Kohlbecker
			if($typeDesignation->notDesignated){
101 300375f2 f.revilla
				$out .= '<li class="nameTypeDesignation"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>: ' . t('not designated'). '</li>';
102
				//$out .= '<li class="nameTypeDesignation"><span class="status">Lectotype</span>: '.t('not designated'). '</li>';
103 806baeb2 Andreas Kohlbecker
			}else if($typeDesignation->typeName){
104 75b05e16 f.revilla
				$link_to_name_page = '?q=' . path_to_name($typeDesignation->typeName->uuid);
105 300375f2 f.revilla
				$out .= '<li class="nameTypeDesignation"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>';
106 b32739d9 f.revilla
107 6d589240 f.revilla
				if($typeDesignation->citation){
108 44b1626d f.revilla
					$out .= type_designation_citation_layout($typeDesignation, $separator);
109 6d589240 f.revilla
					//footnotes
110 f0df1f96 f.revilla
					//$fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-typeDesignations-' . $typeDesignation->uuid, $typeDesignation->citation->titleCache);
111 8aabc503 f.revilla
					/*
112 44b1626d f.revilla
				  $fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-typeDesignations', $typeDesignation->citation->titleCache);
113 8aabc503 f.revilla
				  $out .= theme('cdm_footnote_key', $fkey_typeDesignation, $separator, true, true) . ')';
114
				  */
115 6d589240 f.revilla
				}
116 806baeb2 Andreas Kohlbecker
				if($typeDesignation->typeName->nomenclaturalReference){
117
					$referenceUri = url(path_to_reference($typeDesignation->typeName->nomenclaturalReference->uuid));
118
				}
119 300375f2 f.revilla
				$out .= ': ' . theme('cdm_taxonName', $typeDesignation->typeName, $link_to_name_page, $referenceUri, true, true);
120 806baeb2 Andreas Kohlbecker
			}
121
		}
122
	}
123
124
	if(!empty($specimenTypeDesignations)){
125
		// sorting might be different for dataportals so this has to be parameterized
126
		usort($specimenTypeDesignations, "compare_specimenTypeDesignationStatus");
127
		foreach($specimenTypeDesignations as $std){
128
			$typeReference = '';
129
			//show citation only for Lectotype or Neotype
130
			$showCitation = isset($std->typeStatus) && ($std->typeStatus->uuid == UUID_NEOTYPE || $std->typeStatus->uuid == UUID_LECTOTYPE);
131
			if($showCitation && !empty($std->citation)){
132 3147f061 f.revilla
				//$shortCitation = $std->citation->authorTeam->titleCache;
133 15f11e83 f.revilla
134 75b05e16 f.revilla
				$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std->citation->uuid);
135
				$shortCitation = $author_team->titleCache;
136 15f11e83 f.revilla
137 806baeb2 Andreas Kohlbecker
				$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
138
				if(strlen($shortCitation) == 0){
139 48650990 Andreas Kohlbecker
					$shortCitation = theme('cdm_reference', $std->citation);
140 806baeb2 Andreas Kohlbecker
					$missingShortCitation = true;
141
				}
142 75b05e16 f.revilla
143 806baeb2 Andreas Kohlbecker
				$typeReference .= '&nbsp;(' . t('designated by');
144
				$typeReference .= '&nbsp;<span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
145
				$typeReference .= $shortCitation.'</span>';
146 21f49347 f.revilla
				$typeReference .= ':'. $std->citationMicroReference .')';
147
148 75b05e16 f.revilla
				$_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-lectotypes', $std->citation->titleCache);
149 e5d101f3 f.revilla
				$typeReference .= theme('cdm_footnote_key', $_fkey2, $separator, true, true);
150 75b05e16 f.revilla
			}
151 806baeb2 Andreas Kohlbecker
152 75b05e16 f.revilla
			$derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $std->typeSpecimen->uuid);
153 6d589240 f.revilla
154 806baeb2 Andreas Kohlbecker
			$out .= '<li class="specimenTypeDesignation">';
155 44b1626d f.revilla
			$out .= '<span class="status">'
156 8aabc503 f.revilla
			.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type'))
157
			.$typeReference.'</span>: '.$derivedUnitFacadeInstance->titleCache;
158
			$out .= theme('cdm_specimen', $derivedUnitFacadeInstance);
159 21f49347 f.revilla
160 75b05e16 f.revilla
			//footnotes for synonymy acronyms
161 aa582de0 Andreas Kohlbecker
			$_fkey = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-acronyms', $derivedUnitFacadeInstance->collection->titleCache);
162 1f5b7a24 f.revilla
			$out .= theme('cdm_footnote_key', $_fkey, $separator);
163 806baeb2 Andreas Kohlbecker
			$out .= '</li>';
164 6d589240 f.revilla
165 21f49347 f.revilla
			if (!empty($std->citation)){
166
				$render_footnote_lectotypes = true;
167
			 //$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
168
			}
169 806baeb2 Andreas Kohlbecker
		}
170
	}
171
172
	$out .= '</ul>';
173 ac168ae1 Andreas Kohlbecker
174 317b632e f.revilla
	//render the footnotes at the end of the page
175 75b05e16 f.revilla
	if ($render_footnote_lectotypes){
176
		$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
177
	}
178 f0df1f96 f.revilla
	$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-acronyms', 'li');
179
	$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-typeDesignations', 'li');
180 1f5b7a24 f.revilla
	//$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-typeDesignations-' . $typeDesignation->uuid, 'li');
181 8aabc503 f.revilla
182 80e0aa8e Andreas Kohlbecker
	RenderHints::popFromRenderStack();
183 19216886 f.revilla
184 806baeb2 Andreas Kohlbecker
	return $out;
185
}
186
187
188
/**
189
 * FIXME this definitively has to be in another spot. just didn't know where to put it right now.
190
 * Compares the status of two SpecimenTypeDesignations
191
 * @param String $a 	a SpecimenTypeDesignations
192
 * @param String $b		another SpecimenTypeDesignations
193
 */
194
function compare_specimenTypeDesignationStatus($a, $b){
195
	/* this is the desired sort oder as of now:
196
	 * 	Holotype
197
	 * 	Isotype
198
	 * 	Lectotype
199
	 * 	Isolectotype
200
	 * 	Syntype
201
	 *
202
	 * TODO
203
	 * Basically, what we are trying to do is, we define an ordered array of TypeDesignation-states
204
	 * and use the index of this array for comparison. This array has to be filled with the cdm-
205
	 * TypeDesignation states and the order should be parameterisable inside the dataportal.
206
	 */
207
	// make that static for now
208
	$typeOrder = array('Holotype', 'Isotype', 'Lectotype', 'Isolectotype', 'Syntype');
209
210
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
211
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
212
213
	if ($aQuantifier == $bQuantifier) {
214
		// sort alphabetically
215
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
216
	}
217
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
218
219
}
220
221 0387c539 Andreas Kohlbecker
function theme_cdm_nameRelationships($nameRelationships, $skipTypes = false){
222 806baeb2 Andreas Kohlbecker
223 75b05e16 f.revilla
	if(!$nameRelationships){
224
		return;
225
	}
226
227 0387c539 Andreas Kohlbecker
	RenderHints::pushToRenderStack('nameRelationships');
228 75b05e16 f.revilla
	$footnoteListKey = 'nameRelationships';
229
	RenderHints::setFootnoteListKey($footnoteListKey);
230
231 806baeb2 Andreas Kohlbecker
	// group by relationship type
232
	$relationshipGroups = array();
233
	foreach($nameRelationships as $nameRelationship){
234
		if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
235
			$relationshipGroups[$nameRelationship->type->uuid] = array();
236
		}
237
		$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
238
	}
239
240
	// generate output
241
	$out = '';
242
	foreach($relationshipGroups as $group){
243
		$type = $group[0]->type;
244
245
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
246
			continue;
247
		}
248
249
		$block->module = 'cdm_dataportal';
250
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
251
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
252
253
		foreach($group as $relationship){
254
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
255
		}
256
257
		$block->content .= implode('; ', $relatedNames);
258
		$out .= theme('block', $block);
259
	}
260 eec5d691 f.revilla
	$out .= theme('cdm_footnotes', $footnoteListKey, 'li');
261 75b05e16 f.revilla
262 0387c539 Andreas Kohlbecker
	RenderHints::popFromRenderStack();
263 806baeb2 Andreas Kohlbecker
	return $out;
264
}
265
266
267
268
function theme_cdm_homotypicSynonymLine($taxon){
269
	$out = '';
270 b9438135 Andreas Kohlbecker
	$out .= '<li class="synonym">'.cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
271 75b05e16 f.revilla
272 806baeb2 Andreas Kohlbecker
	return $out;
273
}
274
275
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
276 75b05e16 f.revilla
277 80e0aa8e Andreas Kohlbecker
	RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
278 75b05e16 f.revilla
279 806baeb2 Andreas Kohlbecker
	$out = '';
280
	$out = '<ul class="heterotypicSynonymyGroup">';
281 75b05e16 f.revilla
	$footnoteListKey = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
282 0387c539 Andreas Kohlbecker
	RenderHints::setFootnoteListKey($footnoteListKey);
283 75b05e16 f.revilla
284 806baeb2 Andreas Kohlbecker
	$is_first_entry = true;
285
	$typeDesignations = null;
286
	foreach($homotypicalGroup as $synonym){
287
		if($is_first_entry){
288
			$is_first_entry = false;
289 12196fd5 f.revilla
			$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
290 806baeb2 Andreas Kohlbecker
			// is first list entry
291 b9438135 Andreas Kohlbecker
			$out .= '<li class="firstentry synonym">'.cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
292 806baeb2 Andreas Kohlbecker
		} else {
293 b9438135 Andreas Kohlbecker
			$out .= '<li class="synonym">'.cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
294 806baeb2 Andreas Kohlbecker
		}
295
	}
296 1f5b7a24 f.revilla
	//$test =  theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
297 75b05e16 f.revilla
	//tuypedesignations footnotes
298 d74aa4df Andreas Kohlbecker
299 806baeb2 Andreas Kohlbecker
	if($typeDesignations){
300
		$out .= theme('cdm_typedesignations', $typeDesignations);
301 6d589240 f.revilla
302 806baeb2 Andreas Kohlbecker
	}
303 d74aa4df Andreas Kohlbecker
304 75b05e16 f.revilla
	//annotation footnotes
305
	//$annotation_key = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
306
	//$fkey_annotations = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-annotations-' . $annotation_key, $annotation_key);
307 6d589240 f.revilla
	//$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-annotations-' . $annotation_key);
308
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
309 1f5b7a24 f.revilla
	//$out .= theme('cdm_annotation_footnotes', $footnoteListKey);
310 806baeb2 Andreas Kohlbecker
	$out .= '</ul>';
311 75b05e16 f.revilla
312
313
	RenderHints::popFromRenderStack();
314 806baeb2 Andreas Kohlbecker
	return $out;
315
}
316
317
318
319 b32739d9 f.revilla
function theme_cdm_homotypicSynonymyGroup($synonymList, $accepted_taxon_uuid, $prependedSynonyms = array()){
320 75b05e16 f.revilla
321 80e0aa8e Andreas Kohlbecker
	RenderHints::pushToRenderStack('homotypicSynonymyGroup');
322 75b05e16 f.revilla
323 0387c539 Andreas Kohlbecker
	$footnoteListKey = isset($prependedSynonyms[0]) ? $prependedSynonyms[0]->uuid : (isset($synonymList[0]) ? $synonymList[0]->uuid : 'NULL');
324 f0df1f96 f.revilla
	$accepted_taxon_footnoteListKey = RenderHints::getFootnoteListKey();
325 0387c539 Andreas Kohlbecker
	RenderHints::setFootnoteListKey($footnoteListKey);
326 d74aa4df Andreas Kohlbecker
327 806baeb2 Andreas Kohlbecker
	if(! is_array($synonymList) || count($synonymList) == 0){
328
		return;
329
	}
330
331
	$out = '<ul class="homotypicSynonyms">';
332
333
	if(!empty($prependedSynonyms)){
334
		foreach($prependedSynonyms as $taxon){
335 b9438135 Andreas Kohlbecker
			$out .= '<li class="synonym">'.cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
336 806baeb2 Andreas Kohlbecker
		}
337
	}
338
339
	foreach($synonymList as $synonym){
340 b9438135 Andreas Kohlbecker
		$out .= '<li class="synonym">'.cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
341 806baeb2 Andreas Kohlbecker
	}
342 ac168ae1 Andreas Kohlbecker
343 b32739d9 f.revilla
	$homonym_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonymList[0]->name->uuid);
344
    $accepted_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $accepted_taxon_uuid);
345
    if($accepted_typeDesignations){
346
        $typeDesignations = cdm_add_type_designations($homonym_typeDesignations, $accepted_typeDesignations);
347
    }else {
348
    	$typeDesignations = $homonym_typeDesignations;
349
    }
350 806baeb2 Andreas Kohlbecker
	if($typeDesignations){
351
		$out .= theme('cdm_typedesignations', $typeDesignations);
352
	}
353 8aabc503 f.revilla
	if($accepted_taxon_footnoteListKey){// to avoiding drupal warnings (#1830) why false???
354
		$out .= theme('cdm_footnotes', $accepted_taxon_footnoteListKey, 'li');
355
	}
356 ac168ae1 Andreas Kohlbecker
357 b5e773ef Andreas Kohlbecker
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
358 806baeb2 Andreas Kohlbecker
	$out .= '</ul>';
359 75b05e16 f.revilla
360 80e0aa8e Andreas Kohlbecker
	RenderHints::popFromRenderStack();
361 806baeb2 Andreas Kohlbecker
	return $out;
362
}
363
364 6cb938a3 Andreas Kohlbecker
function get_nameRenderTemplate($renderPath, $nameLink = NULL, $refenceLink = NULL){
365
  //TODO implement admin user interface to replace switch statement
366
  //     preliminar solution: using themes
367
368
  $template = null;
369
  // find best matching default RenderTemplate in theme
370
  //echo "<br/><br/>RENDER PATH:  ".$renderPath;
371
  //var_dump('RENDER PATH: ' . $renderPath);
372 2264b60d Andreas Kohlbecker
373
  // preserve renderPath_base
374
  if( ($separatorPos =  strpos($renderPath, '.')) >= 0 ){
375
  } else {
376
  	$separatorPos = strlen($renderPath);
377
  }
378
  $renderPath_base = substr($renderPath, 0, $separatorPos);
379
380
  // find in theme function if it exists
381
  if(theme_get_function('get_nameRenderTemplate')){
382
	  while(!is_array($template) && strlen($renderPath) > 0){
383
	    $template = theme('get_nameRenderTemplate', $renderPath);
384
	    $renderPath = substr($renderPath, 0, strrpos($renderPath, '.'));
385
	    //     if(!is_array($template)){
386
	    //         echo "<br/>->".$renderPath;
387
	    //     }
388
	  }
389 6cb938a3 Andreas Kohlbecker
  }
390
391
  // otherwise get default RenderTemplate from theme
392
  if(!is_array($template)){
393
    $template = theme('get_nameRenderTemplate', '#DEFAULT');
394
  }
395
  // otherwise get system default RenderTemplate
396
  if(!is_array($template)){
397 2264b60d Andreas Kohlbecker
    switch($renderPath_base){
398 6cb938a3 Andreas Kohlbecker
      case 'list_of_taxa':
399 2264b60d Andreas Kohlbecker
      case 'acceptedFor':
400 6cb938a3 Andreas Kohlbecker
      case 'taxon_page_synonymy':
401
      case 'typedesignations':
402
      case 'taxon_page_title':
403 2264b60d Andreas Kohlbecker
      case 'polytomousKey':
404 6cb938a3 Andreas Kohlbecker
      case 'na': $template = array(
405
              'namePart' => array('#uri'=>true),
406
      //'authorshipPart' => true,
407
      );
408
      break;
409
      case 'nar': $template = array(
410
                'namePart' => array('#uri'=>true),
411
      //'authorshipPart' => true,
412
                'referencePart' => array('#uri'=>true),
413
                'microreferencePart' => true,
414
      );
415
      break;
416
      default: $template = array(
417
          'namePart' => array('#uri'=>true),
418
          'authorshipPart' => true,
419
          'referencePart' => array('#uri'=>true),
420
          'microreferencePart' => true,
421
          'statusPart' => true,
422
          'descriptionPart' => true
423
      );
424
    }
425
  }
426
427
  if($nameLink && isset($template['nameAuthorPart']['#uri'])){
428
    $template['nameAuthorPart']['#uri'] = $nameLink;
429
  } else{
430
    unset($template['nameAuthorPart']['#uri']);
431
  }
432
433
  if($nameLink && isset($template['namePart']['#uri'])){
434
    $template['namePart']['#uri'] = $nameLink;
435
  } else{
436
    unset($template['namePart']['#uri']);
437
  }
438
439
  if($refenceLink && isset($template['referencePart']['#uri'])){
440
    $template['referencePart']['#uri'] = $refenceLink;
441
  }else{
442
    unset($template['referencePart']['#uri']);
443
  }
444
445
  return $template;
446
}
447
448
function get_partDefinition($taxonNameType){
449 2264b60d Andreas Kohlbecker
450 6cb938a3 Andreas Kohlbecker
  //TODO implement admin user interface to allow specify the partdefinitions for any type
451
  //     preliminar solution: using themes
452
453
  $partdef = theme('get_partDefinition', $taxonNameType);
454
455
  if(!is_array($partdef)){
456
    switch($taxonNameType){
457
      case 'ZoologicalName': $partdef = array(
458
        'namePart' => array(
459
          'name' => true,
460
      ),
461
        'referencePart' => array(
462
          'authorTeam' => true
463
      ),
464
        'microreferencePart' => array(
465
          'microreference' => true,
466
      ),
467
        'statusPart' => array(
468
          'status' => true,
469
      ),
470
        'descriptionPart' => array(
471
          'description' => true,
472
      ),
473
      );
474
      break;
475 2264b60d Andreas Kohlbecker
      case 'BotanicalName':
476
      default: $partdef = array(
477 6cb938a3 Andreas Kohlbecker
        'namePart' => array(
478
          'name' => true,
479
          'authors' => true
480
      ),
481
        'referencePart' => array(
482
          'reference' => true,
483
          'microreference' => true
484
      ),
485
        'statusPart' => array(
486
          'status' => true,
487
      ),
488
        'descriptionPart' => array(
489
          'description' => true,
490
      ),
491
      );
492
      break;
493 2264b60d Andreas Kohlbecker
//      default: $partdef = array(
494
//        'namePart' => array(
495
//          'name' => true,
496
//          'authorTeam' => true
497
//      ),
498
//      'referencePart' => array(
499
//          'reference' => true
500
//      ),
501
//        'microreferencePart' => array(
502
//          'microreference' => true,
503
//      ),
504
//        'statusPart' => array(
505
//          'status' => true,
506
//      ),
507
//        'descriptionPart' => array(
508
//          'description' => true,
509
//      ),
510
//      );
511 6cb938a3 Andreas Kohlbecker
    }
512
  }
513
  return $partdef;
514
}
515
516
517 806baeb2 Andreas Kohlbecker
518 44b1626d f.revilla
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL,
519 27b71dd0 f.revilla
	$show_annotations = true, $is_type_designation = false, $skiptags = array()){
520 4411af64 Andreas Kohlbecker
521 75b05e16 f.revilla
	$renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
522 806baeb2 Andreas Kohlbecker
	$partDefinition = get_partDefinition($taxonName->class);
523
524
	// apply defintions to template
525
	foreach($renderTemplate as $part=>$uri){
526
		if(isset($partDefinition[$part])){
527
			$renderTemplate[$part] = $partDefinition[$part];
528
		}
529
		if(is_array($uri)){
530
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
531
		}
532
	}
533
534 4411af64 Andreas Kohlbecker
   normalize_TaggedName($taxonName->taggedName);
535
536 806baeb2 Andreas Kohlbecker
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
537 2264b60d Andreas Kohlbecker
			&& is_string($taxonName->taggedName[0]->text)
538
			&& $taxonName->taggedName[0]->text != ''
539
			&& $taxonName->taggedName[0]->type == 'name';
540 75b05e16 f.revilla
541 806baeb2 Andreas Kohlbecker
	// got to use second entry as first one, see ToDo comment below ...
542
	if($firstEntryIsValidNamePart){
543
544
		$taggedName = $taxonName->taggedName;
545 75b05e16 f.revilla
546 806baeb2 Andreas Kohlbecker
		$lastAuthorElementString = false;
547
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
548
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
549
550
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
551
			//      // find author and split off from name
552
			//      // TODO expecting to find the author as the last element
553
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
554
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
555
			//        unset($taggedName[count($taggedName)- 1]);
556
			//      }
557
558
			// remove all authors
559
			$taggedNameNew = array();
560
			foreach($taggedName as $element){
561
				if($element->type != 'authors'){
562
					$taggedNameNew[] = $element;
563
				} else {
564
					$lastAuthorElementString = $element->text;
565
				}
566
			}
567
			$taggedName = $taggedNameNew;
568
569
		}
570 44b1626d f.revilla
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName, 'span', ' ', $skiptags).'</span>';
571 806baeb2 Andreas Kohlbecker
	} else {
572
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
573
	}
574
575
	// fill name into $renderTemplate
576
	array_setr('name', $name, $renderTemplate);
577
578
	//  // fill with authorTeam
579
	//  if($authorTeam){
580
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
581
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
582
	//  }
583
584
	// fill with reference
585 300375f2 f.revilla
	if(isset($renderTemplate['referencePart']) && !$is_type_designation){
586 806baeb2 Andreas Kohlbecker
587
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
588
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
589
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
590
			$microreference = null;
591
			if(isset($renderTemplate['referencePart']['microreference'])){
592
				$microreference = $taxonName->nomenclaturalMicroReference;
593
			}
594 a91d2f20 f.revilla
			$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid), "microReference=".urlencode($microreference));
595 806baeb2 Andreas Kohlbecker
			$citation = $citation->String;
596
			// find preceding element of the refrence
597
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
598
			if(str_beginsWith($citation, ", in")){
599
				$citation = substr($citation, 2);
600
				$separator = ' ';
601
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
602
				$separator = ', ';
603
			} else {
604
				$separator = ' ';
605
			}
606
607
			$referenceArray['#separator'] = $separator;
608
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
609
			array_setr('reference', $referenceArray, $renderTemplate);
610
		}
611
612
		// if authors have been removed from the name part the last named authorteam
613
		// should be added to the reference citation, otherwise, keep the separator
614
		// out of the reference
615
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
616
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
617
			// is whanted append the microreference to the authorTeam
618
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
619
				$separator = ": ";
620
				$citation = $taxonName->nomenclaturalMicroReference;
621
			}
622
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
623
			array_setr('authors', $referenceArray, $renderTemplate);
624
		}
625
626
	}
627
628
	// fill with status
629 abf8a2db Andreas Kohlbecker
	if(is_array($taxonName->status)){
630 8aabc503 f.revilla
		if(array_setr('status', true, $renderTemplate)){
631 abf8a2db Andreas Kohlbecker
			if(isset($taxonName->status[0])){
632
				foreach($taxonName->status as $status){
633 3c99472c Andreas Kohlbecker
					$statusHtml .= ', '.$status->type->representation_L10n_abbreviatedLabel;
634 8aabc503 f.revilla
				}
635 806baeb2 Andreas Kohlbecker
			}
636 38e46518 Andreas Kohlbecker
			array_setr('status', '<span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
637 806baeb2 Andreas Kohlbecker
		}
638 44b1626d f.revilla
	}
639 abf8a2db Andreas Kohlbecker
640 806baeb2 Andreas Kohlbecker
	// fill with protologues etc...
641
	if(array_setr('description', true, $renderTemplate)){
642 80e0aa8e Andreas Kohlbecker
		$descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
643 806baeb2 Andreas Kohlbecker
		foreach($descriptions as $description){
644
			if(!empty($description)){
645
				foreach($description->elements as $description_element){
646 75b05e16 f.revilla
					$second_citation = '';
647 7fc77599 f.revilla
					if ($description_element->multilanguageText_L10n->text){
648 75b05e16 f.revilla
						$second_citation = '[& ' . $description_element->multilanguageText_L10n->text . '].';
649 7fc77599 f.revilla
					}
650
					$descriptionHtml .= $second_citation;
651 806baeb2 Andreas Kohlbecker
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
652
				}
653
			}
654
		}
655
		array_setr('description', $descriptionHtml, $renderTemplate);
656
	}
657
658
	// render
659 2643c320 Katja Luther
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
660 75b05e16 f.revilla
661 806baeb2 Andreas Kohlbecker
	foreach($renderTemplate as $partName=>$part){
662
		$separator = '';
663
		$partHtml = '';
664
		$uri = false;
665
		if(!is_array($part)){
666
			continue;
667
		}
668
		if(isset($part['#uri']) && is_string($part['#uri'])){
669
			$uri = $part['#uri'];
670
			unset($part['#uri']);
671
		}
672
		foreach($part as $key=>$content){
673
			$html = '';
674
			if(is_array($content)){
675
				$html = $content['#html'];
676
				$separator = $content['#separator'];
677
			} else if(is_string($content)){
678
				$html = $content;
679
			}
680
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
681
		}
682
		if($uri){
683
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
684
		} else {
685
			$out .= $separator.$partHtml;
686 2efb8f43 Andreas Kohlbecker
687 806baeb2 Andreas Kohlbecker
		}
688
	}
689 75b05e16 f.revilla
	$out .= '</span>';
690 1f5b7a24 f.revilla
	if ($show_annotations){
691 8aabc503 f.revilla
		//$out .= theme('cdm_annotations_as_footnotekeys', $taxonName);
692 1f5b7a24 f.revilla
	}
693 0387c539 Andreas Kohlbecker
	return $out;
694 806baeb2 Andreas Kohlbecker
}
695
696
/**
697
 * Recursively searches the array for the $key and sets the given value
698
 * @param $key
699
 * @param $value
700
 * @param $array
701
 * @return true if the key has been found
702
 */
703
function &array_setr($key, $value, array &$array){
704
	foreach($array as $k=>&$v){
705
		if($key == $k){
706
			$v = $value;
707
			return $array;
708
		} else if(is_array($v)){
709
			$innerArray = array_setr($key, $value, $v);
710
			if($innerArray){
711
				return $array;
712
			}
713
		}
714
	}
715
	return null;
716
}
717
718
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
719
	$precedingElement = null;
720
	foreach($renderTemplate as &$part){
721
		foreach($part as $key=>&$element){
722
			if($key == $contentElementKey){
723
				return $precedingElement;
724
			}
725
			$precedingElement = $element;
726
		}
727
	}
728
	return null;
729
}
730
731
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
732
	$precedingKey = null;
733
	foreach($renderTemplate as &$part){
734 d74aa4df Andreas Kohlbecker
		if(is_array($part)){
735
			foreach($part as $key=>&$element){
736
				if($key == $contentElementKey){
737
					return $precedingKey;
738
				}
739
				if(!str_beginsWith($key, '#')){
740
					$precedingKey = $key;
741
				}
742 806baeb2 Andreas Kohlbecker
			}
743
		}
744
	}
745
	return null;
746
}
747
748
749
750
751
752
753