Project

General

Profile

Download (44 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

    
14
function theme_cdm_feature_nodesTOC($featureNodes){
15

    
16
  $out .= '<ul>';
17
  
18
  foreach($featureNodes as $node){
19

    
20
    if(hasFeatureNodeDescriptionElements($node)){
21

    
22
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
23
      // HACK to implement images for taxa, should be removed
24
      if($node->feature->uuid != UUID_IMAGE){
25
        $out .= '<li>'.l(t(theme('cdm_feature_name', $featureRepresentation)), $_GET['q'], array("class"=>"toc"), NULL, generalizeString($featureRepresentation)).'</li>';
26
      }
27
    }
28
  }
29
  
30
  $out .= '</ul>';
31
  return $out;
32
}
33

    
34
function theme_cdm_feature_name($feature_name){
35
  //TODO replace by using translations ?
36
  switch($feature_name){
37
    default: return t(ucfirst($feature_name));
38
  }
39
}
40

    
41
/**
42
 * Renders the taxon profile. The taxon profile consists of description elements
43
 * which are ordered by the structure defined by specific FeatureTree. The chosen
44
 * FeatureTree is merged with the list of desctiprion elements prior to using this
45
 * method (see function cdm_ws_descriptions_by_featuretree() ).
46
 *
47
 * @param unknown_type $mergedTrees
48
 * @param unknown_type $taxon The taxon whose sprofile to show
49
 */
50
function theme_cdm_featureTrees($mergedTrees, $taxon){
51
  if(!$mergedTrees){
52
    return;
53
  }
54
  foreach($mergedTrees as &$mTree){
55
    //TODO display title and reference in case of multiple $mergedTrees -> theme
56
    $out .= theme('cdm_feature_nodes', $mTree->root->children, $taxon);
57
  }
58
  
59
  return $out;
60
}
61

    
62

    
63
function theme_cdm_featureTreeTOCs($mergedTrees){
64

    
65
  if(!$mergedTrees){
66
    return;
67
  }
68
  //FIXME
69
  $out = '<div id="featureTOC">';
70
  $out .= '<h2>' . t('Content') .'</h2>';
71

    
72
  //TODO diplay title and reference in case of multiple $mergedTrees -> theme
73

    
74
  foreach($mergedTrees as &$mTree){
75
    $out .= theme('cdm_feature_nodesTOC', $mTree->root->children);
76
  }
77

    
78
  $out .= '</div>';
79
  return $out;
80
}
81

    
82

    
83
/**
84
 * Renders the $mergedFeatureNodes for the given $taxon.
85
 * The merged nodes can be obtained by making use of the
86
 * function cdm_ws_descriptions_by_featuretree()
87
 *
88
 * @param unknown_type $featureNodes
89
 * @param unknown_type $taxon
90
 */
91
function theme_cdm_feature_nodes($mergedFeatureNodes, $taxon){
92

    
93
  RenderHints::pushToRenderStack('feature_nodes');
94
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
95
  //Creating an array to place the description elements in 
96
  
97
  foreach($mergedFeatureNodes as $node){
98

    
99
    if(hasFeatureNodeDescriptionElements($node)) {
100

    
101
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
102
      $block->module = 'cdm_dataportal';
103
      $media_list = array();
104

    
105
      if($node->feature->uuid != UUID_IMAGE) {
106

    
107
        $block->delta = generalizeString($featureRepresentation);
108
        $block->subject = '<span class="'. html_class_atttibute_ref($node->feature) . '">' . theme('cdm_feature_name', $featureRepresentation) . '</span>';
109
        $block->module = "cdm_dataportal-feature";
110
        $block->content = '';
111

    
112
        /*
113
         * Content/DISTRIBUTION
114
         */
115
        if($node->feature->uuid == UUID_DISTRIBUTION){
116

    
117
          if(variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)){
118
            $distributionTextDataList = array();
119
            $distributionElementsList = array();
120
            foreach($node->descriptionElements as $descriptionElement){
121
              if($descriptionElement->class == "TextData"){
122
                $distributionTextDataList[] = $descriptionElement;
123
              } else {
124
                $distributionElementsList[] = $descriptionElement;
125
              }
126
            }
127
            if(count($distributionTextDataList) > 0){
128
              $node->descriptionElements = $distributionElementsList;
129
              $block->content .= theme('cdm_descriptionElements', $distributionTextDataList, $node->feature->uuid, $taxon->uuid);
130
            }
131
          }
132

    
133
          // Display cdm distribution map TODO this is a HACK to a proper generic implementation?
134
          $block->content .= theme('cdm_distribution_map', $taxon);
135
          $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
136
        }
137

    
138
        /*
139
         * Content/COMMON_NAME
140
         */
141
        else if ($node->feature->uuid == UUID_COMMON_NAME){
142
          //TODO why is theme_cdm_descriptionElement_CommonTaxonName not beeing used???
143
          $block->content .= theme('cdm_common_names', $node->descriptionElements);
144
        /*
145
        }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
146
          $block->content .= theme('cdm_image_sources', $node->descriptionElements);
147
        */
148
        }
149

    
150
        /*
151
         * Content/ALL OTHER FEATURES
152
         */
153
        else {
154
          $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
155

    
156
          /*
157
           *  Content/ALL OTHER FEATURES/Subordinate Features
158
           *
159
           *  subordinate features are printed inline in one floating text,
160
           *  it is expected that supordinate features only "contain" TextData elements
161
           */
162
          // TODO move into own theme
163
          if(count($node->children) > 0){
164

    
165
            //TODO support more than one level of childen http://dev.e-taxonomy.eu/trac/ticket/2393
166
            $text = '';
167
            foreach ($node->children as $child){
168

    
169
             if (is_array($child->descriptionElements)){
170
               foreach ($child->descriptionElements as $element) {
171

    
172
                 if(is_array($element->media)){
173
                   // append media of supordinate emelents to list of main feature
174
                   $media_list = array_merge($media_list, $element->media);
175
                 }
176

    
177
                 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
178
                //TODO use localized version of feature name, the locale must match the locale of the multilanguage text (http://dev.e-taxonomy.eu/trac/ticket/2394)
179
                 $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
180
               }
181
               $text .= " " . $description;
182
               $description = '';
183
             }
184

    
185
            }
186
            $block->content .= $text;
187
          }
188

    
189
        }
190

    
191
        /*
192
         * Media/ALL FEATURES
193
         */
194
        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
195
        $captionElements = array('title', 'rights');
196

    
197
        $gallery = theme('cdm_media_gallerie', $media_list, CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME.'_'.$node->feature->uuid,
198
              $gallery_settings['cdm_dataportal_media_maxextend'],
199
              $gallery_settings['cdm_dataportal_media_cols'],
200
              $gallery_settings['cdm_dataportal_media_maxRows'],
201
              $captionElements
202
        );
203

    
204
        $block->content .= $gallery;
205
        $block->content .= theme('cdm_footnotes', $node->feature->uuid);
206
        $block->content .= theme('cdm_annotation_footnotes', $node->feature->uuid);
207
        
208
        
209
        
210
        // add anchor to subject        
211
        $block->subject = '<a name="'.$block->delta.'"></a>'.  $block->subject;
212
       	
213
  		
214
        $out .= theme('block', $block);
215
        
216
      }
217
    
218
      
219
      
220
      
221
    }
222
    
223
  }
224
  RenderHints::popFromRenderStack();
225
  return $out;
226
}
227

    
228
function theme_FeatureTree_hierarchy($FeatureTreeUuid){
229

    
230
  if(!is_uuid($FeatureTreeUuid)){
231
    return;
232
  }
233
  $out = '';
234
  $featureTree = cdm_ws_get(CDM_WS_FEATURETREE, array($FeatureTreeUuid));
235
  if($featureTree && $featureTree->root){
236
    $out = '<ul class="'.$featureTree->class.'">';
237
    $out .= theme('FeatureTree_hierarchy_children', $featureTree->root);
238
    $out .= '</ul>';
239
  }
240
  return $out;
241
}
242

    
243
function theme_FeatureTree_hierarchy_children($node){
244

    
245
  $out = '';
246
  if($node->children){
247

    
248
    foreach($node->children as $childNode){
249
      $out .= '<li>'.check_plain($childNode->feature->representation_L10n);
250
      if($childNode->children && count($childNode->children) > 0){
251
        $out .= '<ul>'.theme('FeatureTree_hierarchy_children', $childNode).'</ul>';
252
      }
253
      $out .= '</li>';
254
    }
255
  }
256
  return $out;
257
}
258

    
259

    
260

    
261
/**
262
 *
263
 * Join the texts in $elementArray and enclose with a HTML tag
264
 * @param unknown_type $elementArray
265
 * @param unknown_type $feature the feature to which the elements given in $elementArray are belonging to
266
 * @param unknown_type $glue defaults to empty string
267
 * @param unknown_type $sortArray whether to sort the $elementArray alphabetically
268
 * @param unknown_type $enclosingHtml
269
 */
270
function theme_cdm_descriptionElementArray($elementArray, $feature, $glue = '', $sortArray = false, $enclosingHtml = 'ul'){
271
  $out = '<'.$enclosingHtml.' class="description" id="'.$feature->representation_L10n.'">';
272

    
273
  if($sortArray) sort($elementArray);
274

    
275
  $out .= join($elementArray, $glue);
276

    
277
  $out .= '</'.$enclosingHtml.'>';
278
  return $out;
279
}
280

    
281

    
282
function theme_cdm_descriptionElement_CommonTaxonName($element){
283
  $out = '<span class="' .  html_class_atttibute_ref($element). '">' . $element->language->representation_L10n . ' (' . $element->area->titleCache . '): ' . $element->name .'</span>';
284
  return $out;
285
}
286

    
287

    
288
/**
289
 * TODO: assign a new name to the function? because it is used for the citations
290
 *       textdata elements and not for all text data description elements
291
 * @param $element The description element which contains the text information
292
 * @param $asListElement A boolean which determines whether the citations should
293
 *                       be renderer as a list or not
294
 * @return unknown_type Html to be renderized in drupal
295
 */
296
function theme_cdm_descriptionElementTextData($element, $asListElement, $feature_uuid = null){
297

    
298
  $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
299
  $sourceRefs = '';
300
  $result = array();
301
  $out;
302
  $res_author;
303
  $res_date;
304

    
305
  if(is_array($element->sources)){
306
    foreach($element->sources as $source){
307
      $referenceCitation = theme('cdm_DescriptionElementSource', $source);
308
      if($description && strlen($description) > 0 && $referenceCitation ){
309
        $sourceRefs .= ' ('.$referenceCitation.')' ;
310
      }else if ($referenceCitation){
311
        $sourceRefs = $referenceCitation;
312
      }
313

    
314
      if(strlen($sourceRefs) > 0){
315
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
316
      }
317

    
318
      if ($source->nameUsedInSource->uuid){ //do a link to name page
319
        $name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache,
320
	        path_to_name($source->nameUsedInSource->uuid),
321
	        array(), NULL, NULL, FALSE ,TRUE);
322
      }else if (strlen($source->nameUsedInSource->originalNameString) > 0){ //show a text without link
323
        $name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
324
      }
325

    
326
      if ($asListElement){
327
        $out = '<li class="descriptionText DescriptionElement">' . $name_used_in_source_link_to_show;
328
        //adding ":" if necesary
329
        if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
330
          $out .= ': ';
331
        }
332
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', $element, $feature_uuid) . '</li>';
333
      }else{
334
        if ($name_used_in_source_link_to_show){
335
          $name_used_in_source_link_to_show = ' (name in source: '. $name_used_in_source_link_to_show . ')';
336
        }
337
        $out = '<span class="DescriptionElement DescriptionElement-' . $element->class .'">' . $description . $sourceRefs . $name_used_in_source_link_to_show . '</span>';
338
      }
339
    }
340
  }
341
  //if no sources, print the description
342
  if(!isset($out)) {
343
    $out = $description;
344
  }
345

    
346
  return $out;
347
}
348

    
349

    
350
function theme_cdm_common_names($elements){
351
  $text_data_out = '';
352
  $common_name_out = '';
353
  $separator = ',';
354
  $textData_commonNames = array();
355

    
356

    
357
  if (is_array($elements)){
358
    foreach ($elements as $element){
359
      if ($element->class == 'CommonTaxonName'){
360
        //$key = '<b>' . $element->language->representation_L10n . '</b> (' . $element->area->titleCache . ')';
361
        if ($element->language->representation_L10n){
362
          $key = '<b>' . $element->language->representation_L10n . '</b>';
363
          $key .= (strlen($element->area->titleCache)>0) ? ' (' . $element->area->titleCache . ')' : '';
364
        }
365
        $common_names[$key][] = $element;
366
      }else if ($element->class == 'TextData'){
367
     //else if ($element->class == 'TextData' && $element->feature->uuid == UUID_COMMON_NAME){
368
        $textData_commonNames[] = $element;
369
      }
370
    }
371
  }
372
  //handling common names
373

    
374
  if (count($common_names) > 0){
375
    //sorting the a-array based on the area (key)
376
    ksort($common_names);
377
    //creating the output to be render by drupal
378
    foreach ($common_names as $key => $elements){
379
      $rendered_element_list = '';
380
      foreach($elements as $element){
381
        $sourcesFootnoteKeyList = '';
382
        // adding footnotes sources
383
        foreach($element->sources as $source){
384
          if(_is_original_source_type($source)){
385
            $_fkey = FootnoteManager::addNewFootnote(UUID_COMMON_NAME, theme('cdm_DescriptionElementSource', $source, false));
386
            $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, ($sourcesFootnoteKeyList ? $separator : ''));
387
          }
388
        }
389
        if($element->name){
390
          $rendered_element_list .= '<span class="' .  html_class_atttibute_ref($element). '">' . (strlen($rendered_element_list) > 0 ? ', ': '') . $element->name . $sourcesFootnoteKeyList . '</span>';
391
        }
392
      }
393
      if ($key){
394
       $common_name_out .= (strlen($common_name_out) > 0 ? '; ': '') . $key . ': ' . $rendered_element_list;
395
      }else{
396
        $common_name_out .= (strlen($common_name_out) > 0 ? '; ': '') . $rendered_element_list;
397
      }
398
    }
399
  }
400
  //handling commons names as text data
401
  foreach($textData_commonNames as $text_data_element){
402
    $text_data_out .= theme('cdm_descriptionElementTextData', $text_data_element, true, $text_data_element->feature->uuid);
403
  }
404

    
405
  $common_name_out = "<div class=common_names_as_common_names> $common_name_out </div>";
406
    $out_array[] = $text_data_out;
407
  $common_name_out_text_data = '<div class=common_names_as_text_data>' . theme('cdm_descriptionElementArray', $out_array, $element->feature) . '</div>';
408

    
409
  return $common_name_out . $common_name_out_text_data;
410
  //return $common_name_out . theme('cdm_descriptionElementArray', $out_array, $element->feature);
411
  //return "<div class=common_names> $common_name_out $common_name_out_text_data";
412
}
413

    
414
/**
415
 * Theme a list of description elements, usually of a specific feature type
416
 * @param $descriptionElements
417
 * @return unknown_type
418
 */
419
function theme_cdm_descriptionElements($descriptionElements, $featureUuid, $taxon_uuid){
420

    
421
  $outArray = array();
422

    
423
/*
424
  $userDefined = mixed_variable_get(LAYOUT_SETTING_PREFIX . $featureUuid, FEATURE_TREE_LAYOUT_DEFAULTS);
425
  if(variable_get('distribution_sort', 'NO_SORT')  != 'NO_SORT'){
426
    $glue = '';
427
    $enclosingTag = 'dl';
428
    $entryEnclosingTag = null;
429
  } else if($userDefined && $userDefined['enabled']){
430
      $glue = $userDefined['glue'];
431
      $enclosingTag = $userDefined['enclosingTag'];
432
      $entryEnclosingTag = $userDefined['entryEnclosingTag'];
433
  } else {
434
    // TODO remove once LAYOUT_SETTING_PREFIX-{uuid} seeting are confired to work for all portals (selenium test still missing!!!)
435
    $glue = '';
436
    $enclosingTag = 'ul';
437
    $entryEnclosingTag = null ;
438
  }
439
*/
440

    
441
	if(variable_get('distribution_sort', 'NO_SORT')  != 'NO_SORT'){
442
		$glue = '';
443
		$enclosingTag = 'dl';
444
	} else {
445
		$glue = '';
446
		$enclosingTag = 'ul';
447
	}
448

    
449
  $sortOutArray = false;
450
  $distributionElements = array();
451

    
452
  RenderHints::pushToRenderStack('cdm_descriptionElements');
453

    
454
  if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana
455
    foreach($descriptionElements as $descriptionElement) {
456

    
457
      // --- DISTRIBUTION ---- //
458
      if($descriptionElement->feature->uuid == UUID_DISTRIBUTION){
459
        if($descriptionElement->class == 'Distribution'){
460
          $sortKey = $descriptionElement->area->representation_L10n;
461
          $distributionElements[$sortKey]= $descriptionElement;
462
        } else if($descriptionElement->class == 'TextData'){
463
          $asListElement = false;
464
          $repr = theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
465

    
466
          if( !array_search($repr, $outArray)){
467
          	$outArray[] = $repr;
468
            //TODO HINT: sorting in theme_cdm_descriptionElementArray will not work since this array contains html attributes with uuids !!!!
469
            $sortOutArray = true;
470
            $glue = '<br/> ';
471
            $enclosingTag = 'p';
472
          }
473
        }
474
      }
475

    
476
       // --- IMAGE_SOURCES --- //
477
      else if($descriptionElement->feature->uuid == UUID_IMAGE_SOURCES){
478
        $image_sources[] = $descriptionElement;
479
      }
480

    
481
      // ---- class == TextData ---- //
482
      else if($descriptionElement->class == 'TextData'){
483
        $asListElement = true;
484
        $outArray[] = theme('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
485
      }else if ($descriptionElement->class == 'CommonTaxonName') {
486
        $outArray[] = theme('cdm_descriptionElement_CommonTaxonName', $descriptionElement);
487
      }else {
488
        $outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
489
      }
490
    }
491
  }
492

    
493
  //if feature = NAME USAGE sort the list of sources
494
  //this is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE
495
  if($descriptionElement->feature->uuid == UUID_NAME_USAGE){
496
    sort($outArray);
497
  }
498

    
499

    
500
  if($image_sources){
501
      $outArray[] = theme('cdm_description_element_image_source', $image_sources, true);
502

    
503
  }
504

    
505
  if(variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT'){
506
    $outArray[] = theme('cdm_description_ordered_distributions', $taxon_uuid, $distributionElements);
507
  }else{
508
    ksort($distributionElements);
509
    $outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements); // TODO , $entryEnclosingTag);
510
  }
511

    
512
  // take the feature of the last $descriptionElement
513
  $feature = $descriptionElement->feature;
514
  $out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingTag);
515

    
516
  RenderHints::popFromRenderStack();
517
  return $out;
518
}
519

    
520

    
521

    
522
/**
523
 *
524
 * Enter description here ...
525
 * @param unknown_type $a
526
 * @param unknown_type $b
527
 */
528
function compare_image_sources($a, $b){
529
    if($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text){
530
      return 0;
531
    }
532
    return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
533
}
534

    
535
/**
536
 *
537
 */
538
function theme_cdm_description_element_image_source($image_sources, $asListElement) {
539
    $out = '';
540
    $separator = ',';
541
    RenderHints::pushToRenderStack('descriptionElementImageSource');
542
    RenderHints::setFootnoteListKey(UUID_IMAGE_SOURCES);
543

    
544
    //sorting the image sources
545
    usort($image_sources, "compare_image_sources");
546
    //generate the footnotes
547
    foreach($image_sources as $image_source){
548
        $footNoteKeys = cdm_annotations_as_footnotekeys($image_source);
549
        foreach($image_source->sources as $source){
550
            if(_is_original_source_type($source)){
551
                $fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
552
                cdm_add_footnote_to_array($footNoteKeys, $fn_key);// ensure uniqueness of the footnote keys
553
            }
554
        }
555
        //sort and render footnote keys
556
        $footnoteKeyListStr = '';
557
        asort($footNoteKeys);
558
        foreach($footNoteKeys as $footNoteKey){
559
            $footnoteKeyListStr .= theme('cdm_footnote_key', $footNoteKey, ($footnoteKeyListStr ? $separator : ''));
560
        }
561
        //return value!
562
        $out .= '<span class="descriptionElement descriptionElement-'.$image_source->uuid.'">'.$image_source->multilanguageText_L10n->text . $footnoteKeyListStr . '; </span>';
563

    
564
    }
565

    
566
    RenderHints::popFromRenderStack();
567
    return $out;
568
}
569

    
570
/**
571
 *
572
 * @param unknown_type $descriptionElements
573
 * @param String $enclosingTag
574
 */
575
function theme_cdm_descriptionElementDistribution($descriptionElements, $enclosingTag = "span"){
576

    
577

    
578
	if(!$enclosingTag){
579
		$enclosingTag = "span";
580
	}
581

    
582
  $out = '';
583
  $separator = ',';
584
  RenderHints::pushToRenderStack('descriptionElementDistribution');
585
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
586

    
587
  foreach($descriptionElements as $descriptionElement){
588

    
589
    // annotations as footnotes
590
    $footNoteKeys = cdm_annotations_as_footnotekeys($descriptionElement);
591
    // source references as footnotes
592
    foreach($descriptionElement->sources as $source){
593
      if(_is_original_source_type($source)){
594
        $fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
595
        cdm_add_footnote_to_array($footNoteKeys, $fn_key);// ensure uniqueness of the footnote keys
596
      }
597
    }
598
    // sort and render footnote keys
599
    $footnoteKeyListStr = '';
600
    asort($footNoteKeys);
601
    foreach($footNoteKeys as $footNoteKey){
602
      $footnoteKeyListStr .= theme('cdm_footnote_key', $footNoteKey, ($footnoteKeyListStr ? $separator : ''));
603
    }
604

    
605
    $out .= '<'. $enclosingTag .' class="descriptionElement descriptionElement-'.$descriptionElement->uuid.'">'
606
      . $descriptionElement->area->representation_L10n . $footnoteKeyListStr . ' </'. $enclosingTag .'>';
607
  }
608

    
609
  RenderHints::popFromRenderStack();
610
  return $out;
611
}
612

    
613
/**
614
 * Function target is to compare two different foootnotes objects.
615
 * The comparation is based on the footnote key. The one which is
616
 * displayed as footnote number.
617
 *
618
 * @param footnote object $a
619
 * @param footnote object $b
620
 */
621
function footnotes_key_compare($a, $b){
622
  $res = 0;
623
  if ($a->keyStr < $b->keyStr){
624
    $res = -1;
625
  }elseif ($a->keyStr > $b->keyStr){
626
    $res = 1;
627
  }
628
  return $res;
629
}
630

    
631
function theme_cdm_description_ordered_distributions($taxon_uuid, $descriptionElements){
632
  //returning null if no description elements
633
  if ($descriptionElements == null){
634
    return '';
635
  }
636
  //initialization some variables
637
  $out = '';
638
  $separator = ',';
639
  RenderHints::pushToRenderStack('descriptionElementDistribution');
640
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
641
  //getting all the taxon description for a given taxon
642
  $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, array($taxon_uuid, 'test'));
643
  foreach ($taxonDescriptions as $description){
644
    $descriptions_uuids[] = $description->uuid;
645
  }
646
  //getting the sortered distributions (omiting level ??)
647
  $request_params = array();
648
  $request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
649
  $ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, join(',',$descriptions_uuids), queryString($request_params));
650
  $ordered_areas = $ordered_areas->rootElement->children;
651

    
652
  //printing the distributions
653
  foreach ($ordered_areas as $element_level1){
654
    //level1
655
    if ($element_level1->data){
656
      $out .= '<dt>' . $element_level1->data->area->representation_L10n . ':</dt> ';
657
    }
658
    $out .= '<dd>';
659

    
660
    //level3
661
    foreach ($element_level1->children as $element_level3){
662
      if ($element_level3->data){
663
        $text_l3 = $element_level3->data->area->representation_L10n;
664
      }
665
      $fnKeysLevel3Str = '';
666
      $fnKeysLevel3 = cdm_annotations_as_footnotekeys($element_level3->data);
667
      foreach($element_level3->data->sources as $source){
668
        if(_is_original_source_type($source)){
669
          $fn_key3 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
670
          cdm_add_footnote_to_array($fnKeysLevel3, $fn_key3);
671
        }
672
      }
673
      //level4
674
      $l4_regions = array();
675
      foreach ($element_level3->children as $element_level4){
676
        if ($element_level4->data){
677
          $text_l4 = $element_level4->data->area->representation_L10n;
678
          $l4_regions[$element_level3->data->area->representation_L10n] = '';
679
          $fnKeysLevel4Str = '';
680
          $fnKeysLevel4 = cdm_annotations_as_footnotekeys($element_level4->data);
681
          foreach($element_level4->data->sources as $source){
682
            if(_is_original_source_type($source)){
683
              $fn_key4 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
684
              cdm_add_footnote_to_array($fnKeysLevel4, $fn_key4);
685
            }
686
          }
687
          usort($fnKeysLevel4, "footnotes_key_compare");
688
          $l4_regions[$text_l4] = $fnKeysLevel4;
689
        }
690
      }//level4
691
      //managing level3 and level4 for generating the right output
692
      usort($fnKeysLevel3, "footnotes_key_compare");
693
      foreach ($fnKeysLevel3 as $key3){
694
        foreach ($l4_regions as $key4 => $value4){
695
          cdm_add_footnote_to_array($l4_regions[$key4], $key3);
696
        }
697
      }
698
      if ($element_level3->numberOfChildren == 1 &&
699
       $text_l3 == $element_level3->children[0]->data->area->representation_L10n){
700
        //var_dump($element_level3->children[0]->data->area->representation_L10n);
701
        $fnStr = '';
702
        $region = array_pop($l4_regions);
703
        foreach($region as $key){
704
          $fnStr .= theme('cdm_footnote_key', $key, ($fnStr ? $separator : ''));
705
        }
706
        $out .= "$text_l3 $fnStr; ";
707
              //removing whitespaces when &fnStr is empty
708
        if(substr($out, -3) == ' ; '){
709
          $out = substr($out, 0, -3) . '; ';
710
        }
711
      }else{
712
        $fnKeysLevel3Str = '';
713
        foreach($fnKeysLevel3 as $key){
714
          $fnKeysLevel3Str .= theme('cdm_footnote_key', $key, ($fnKeysLevel3Str ? $separator : ''));
715
        }
716
        $text_l4_aux = '';
717
        foreach ($l4_regions as $key => $value){
718
          $fnKeysLevel4Str = '';
719
          if (is_array($l4_regions[$key])) {
720
            foreach ($l4_regions[$key] as $fnkey){//warning why?
721
              $fnKeysLevel4Str .= theme('cdm_footnote_key', $fnkey, ($fnKeysLevel4Str ? $separator : ''));
722
            }
723
          }
724
          //if ($key != $text_l3 || sizeof($l4_regions > 1)){
725
          if ($key != $text_l3){
726
            $text_l4_aux .= "$key $fnKeysLevel4Str, ";
727
          }
728
        }
729
        $text_l4_aux = substr($text_l4_aux, 0, -2);
730

    
731
        if (strlen($text_l4_aux) > 0){
732
          $out .= "$text_l3 $fnKeysLevel3Str ($text_l4_aux); ";
733
        }else{
734
          $out .= "$text_l3 $fnKeysLevel3Str; ";
735
        }
736

    
737
      }
738
    }//level3
739
    $out = substr($out, 0, -2);
740
    $out .= '.</dd>';
741
  }//level1
742

    
743
  RenderHints::popFromRenderStack();
744
  return $out;
745
}
746

    
747
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
748

    
749
  if(isset($descriptionElementSource->citation)){
750
  	$out = theme('cdm_reference', $descriptionElementSource->citation, $descriptionElementSource->citationMicroReference, $doLink);
751
  }
752
  return $out;
753
}
754

    
755
function theme_cdm_IdentifieableSource($source, $doLink = TRUE){
756

    
757
  if(isset($source->citation)){
758
    $out = theme('cdm_reference', $source->citation, $source->citationMicroReference, $doLink);
759
  }
760
  return $out;
761
}
762

    
763

    
764

    
765

    
766

    
767
/*
768
 function theme_cdm_descriptionElementDistribution($descriptionElements){
769

    
770
 $out = '';
771
 $separator = ',';
772
 RenderHints::pushToRenderStack('descriptionElementDistribution');
773
 RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
774
 foreach($descriptionElements as $descriptionElement){
775
 // annotations as footnotes
776
 $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
777
 // source references as footnotes
778
 $sourcesFootnoteKeyList = '';
779
 foreach($descriptionElement->sources as $source){
780
 if(_is_original_source_type($source)){
781
 $_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_DescriptionElementSource', $source, false));
782
 $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : ''));
783
 }
784
 }
785
 if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
786
 $annotationFootnoteKeys .= $separator;
787
 }
788
 $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList . ' ';
789
 }
790

    
791
 $out = substr($out, 0, strlen($out)-strlen($separator) );
792

    
793
 RenderHints::popFromRenderStack();
794
 return $out;
795

    
796
 }
797
 */
798

    
799

    
800
/**
801
 * TODO
802
 * Quick-and-dirty solution to show distribution service to exemplar groups
803
 *
804
 * @param unknown_type $featureTo
805
 * @return unknown
806
 */
807
function theme_cdm_distribution_map($taxon){
808

    
809
  $server = getEDITMapServiceURI();
810

    
811
  if(!$server){
812
    //warning message
813
    drupal_set_message('No \'Geoservice Access Point\' has been set so far. '
814
    . 'Please configure the variable \'Geoservice Access Point\' here '
815
    . l('CDM Dataportal Settings', 'admin/settings/cdm_dataportal/geo'), 'warning');
816
    //message to render
817
    return "<p>No geoservice specified</p>";
818
  }
819

    
820

    
821
  $fontStyles = array(0 => "plane", 1 => "italic");
822

    
823
  // query cdm server for map service uri parameters
824
  $map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
825
  $out .= "<!-- map_data_parameters:". print_r($map_data_parameters, true) . " -->";
826
  $query_string = $map_data_parameters->String;
827
  if(!$query_string){
828
    // the $query_string is empty if there are no distribution areas defined
829
    return ;
830
  }
831

    
832
  // some cleaning of the URI paramters, TODO is this still needed?
833
  $query_string = str_replace('%3A', ":", $query_string);
834

    
835

    
836
  /* ------ choose the display mode, either openlayers or static image ------ */
837

    
838
  if(variable_get('cdm_dataportal_map_openlayers', 1)){
839

    
840
    /* =========== display distributions using the openlayers map viewer =========== */
841

    
842
    $legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
843
    $legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
844
    $legend_url_font_style = $fontStyles[$legend_url_font_style];
845
    $legend_url_icon_width  = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
846
    $legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
847

    
848
    $legendFormatQueryStr  = "format=image".urlencode('/')."png&TRANSPARENT=TRUE";
849
    $legendFormatQueryStr .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
850
    //TODO why is the layer=topp:tdwg_level_4 parameter neede at all here??
851
    $legendFormatQueryStr .="layer=topp".urlencode(':')."tdwg_level_4&LEGEND_OPTIONS=forceLabels".urlencode(':')."on;fontStyle".urlencode(':').$legend_url_font_style.";fontSize".urlencode(':').$legend_url_font_size."&SLD=".urlencode($sldLegend);
852

    
853
    $out .= get_openlayers_map(
854
      variable_get('cdm_dataportal_geoservice_display_width', 300),
855
      variable_get('cdm_dataportal_geoservice_bounding_box', false),
856
      null,
857
      $query_string,
858
      $legendFormatQueryStr,
859
      variable_get('cdm_dataportal_geoservice_map_caption', '')
860
    );
861

    
862
  } else {
863

    
864
    return get_image_map(
865
        variable_get('cdm_dataportal_geoservice_display_width', 300),
866
        variable_get('cdm_dataportal_geoservice_bounding_box', false),
867
        null,
868
        $query_string,
869
        $legendFormatQueryStr,
870
        variable_get('cdm_dataportal_geoservice_map_caption', '')
871
      );
872

    
873

    
874
    // simple image
875
    $mapStaticCaption = '&mc_s=Georgia,15,blue&mc=' . variable_get('cdm_dataportal_geoservice_map_caption', '');
876

    
877

    
878
    $query_string .= '&img=true';
879
    $query_string .= '&legend=1&mlp=3' . $mapStaticCaption . '&recalculate=false';
880

    
881
    $map_service_script_name = "areas.php";
882

    
883
    // apply Plain Image map settings
884
    if (getEDITMapServiceVersionNumber() >= 1.1){
885
      /*
886
       * example : title=a:Naturalized++non-invasive
887
       * &ad=cyprusdivs:bdcode:a:5&as=a:ff9900,,0.1,&l=tdwg4
888
       * &ms=500&bbox=32,34,35,36&img=true&legend=1&mlp=3
889
       * &mc_s=Georgia,15,blue&mc=&recalculate=false
890
       *
891
       * http://edit.br.fgov.be/edit_wp5/v1/rest_gen.php?
892
       * l=background_gis:b,cyprusdivs&ad=cyprusdivs%3Abdcode%3Aa%3A8%2C4
893
       * &as=a%3A339966%2C%2C0.1%2C|b:0000ff,,
894
       * &bbox=32%2C34%2C35%2C36&img=true&legend=1&mc=&mc_s=Georgia%2C15%2Cblue
895
       * &mlp=3&ms=500&recalculate=false&title=a%3Aindigenous
896
       */
897

    
898
      $map_service_script_name = "rest_gen.php";
899

    
900
      $bgcolor_areaStyleId= "y";
901
      $baselayer_areaStyleId= "z";
902
      $bgcolor_layer='';
903
      $additional_area_styles = array();
904

    
905
      // background color:
906
      if(variable_get('map_bg_color', '')){
907
        $bgcolor_layer = "background_gis:".$bgcolor_areaStyleId;
908
        $additional_area_styles[] = $bgcolor_areaStyleId . ":" . variable_get('map_bg_color', '') . ",,";
909
      }
910

    
911
      //TODO HACK to replace the default base layer which currently is tdwg4 !!!
912
      if(strpos($query_string, "?l=") !== FALSE){
913
        $layer_param_token = "?l=";
914
      } else {
915
        $layer_param_token = "&l=";
916
      }
917
      if(strpos($query_string, "?as=") !== FALSE){
918
        $areystyle_param_token = "?as=";
919
      } else {
920
        $areystyle_param_token = "&as=";
921
      }
922

    
923
      if(variable_get('map_base_layer', '')){
924
        $query_string = str_replace($layer_param_token."tdwg4", "$layer_param_token".variable_get('map_base_layer', ''). ":" . $baselayer_areaStyleId, $query_string);
925
      } else {
926
        $query_string = str_replace($layer_param_token."tdwg4", $layer_param_token."tdwg4:".$baselayer_areaStyleId . ",", $query_string);
927
      }
928

    
929
      if($bgcolor_layer){
930
        $query_string = str_replace($layer_param_token, $layer_param_token . $bgcolor_layer . ",", $query_string);
931
      }
932

    
933
      if(variable_get('map_base_layer_style', '')){
934
        $additional_area_styles[] = $baselayer_areaStyleId . ":" . variable_get('map_base_layer_style', '');
935
      }
936

    
937
      foreach ($additional_area_styles as $as) {
938
        $query_string = str_replace($areystyle_param_token, $areystyle_param_token . $as . "|", $query_string);
939
      }
940

    
941
    }
942

    
943
    $mapUri = url("$server/$map_service_script_name?$query_string");
944
    $out .= '<img class="distribution_map" src="' . $mapUri . '" alt="Distribution Map" />';
945
  }
946
  return $out;
947

    
948
}
949

    
950
/**
951
 * Returns a list of a specific type of IdentificationKeys, the list can be restricteded by a taxon.
952
 * @param $type The simple name of the cdm class implementing the interface IIdentificationKey,
953
 *          valid values are : PolytomousKey, MediaKey, MultiAccessKey
954
 * @param $taxonUuid if given this parameter restrict the listed keys to
955
 *          those which have the taxon identified be this uuid in scope.
956
 */
957
function _list_IdentificationKeys($type, $taxonUuid = null, $pageSize = null, $pageNumber = null){
958

    
959
  if(!$type){
960
    drupal_set_message("Type parameter is missing", "error");
961
    return;
962
  }
963
  $cdm_ws_pasepath = null;
964
  switch($type){
965
    case "PolytomousKey" : $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY; break;
966
    case "MediaKey" : $cdm_ws_pasepath = CDM_WS_MEDIAKEY; break;
967
    case "MultiAccessKey" : $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY; break;
968
  }
969

    
970
  if(!$cdm_ws_pasepath){
971
    drupal_set_message("Type parameter is not valid: ".$type, "error");
972
  }
973

    
974
  $queryParameters  = '';
975
  if(is_numeric($pageSize)){
976
    $queryParameters  = "pageSize=".$pageSize;
977
  } else {
978
    $queryParameters  = "pageSize=0";
979
  }
980

    
981
  if(is_numeric($pageNumber)){
982
    $queryParameters  = "pageNumber=".$pageNumber;
983
  } else {
984
    $queryParameters  = "pageNumber=0";
985
  }
986
  $queryParameters  = null;
987
  if($taxonUuid){
988
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
989
  }
990
  $pager = cdm_ws_get($cdm_ws_pasepath, null, $queryParameters);
991

    
992
  if(!$pager || $pager->count == 0){
993
      return array();
994
  }
995
  return $pager->records;
996
}
997

    
998
function theme_cdm_IdentificationKey($identificationKey, $doLinkToKeyPage = true, $showIdentificationKeyTitle = true){
999

    
1000
   $parentRenderPath = RenderHints::getRenderPath();
1001
   RenderHints::pushToRenderStack("IdentificationKey");
1002

    
1003
   if($showIdentificationKeyTitle){
1004
     if($doLinkToKeyPage) {
1005
       $out = l($identificationKey->titleCache, path_to_key($identificationKey->class, $identificationKey->uuid));
1006
     } else {
1007
       $out = $identificationKey->titleCache;
1008
     }
1009
   }
1010
   if(is_array($identificationKey->sources)){
1011
     // display sources
1012
     $i = 0;
1013
     $out .= '<div>';
1014
     foreach($identificationKey->sources as $source){
1015
      $out .= ($i++ > 0 ? ', ' : '' ) . theme("cdm_IdentifieableSource", $source);
1016
     }
1017
     $out .= '</div>';
1018
   }
1019
     // display annotations
1020
   $out .= theme('cdm_annotations', cdm_ws_getAnnotationsFor($identificationKey), 'div');
1021
   RenderHints::popFromRenderStack();
1022
   return $out;
1023
}
1024

    
1025
function theme_cdm_polytomousKey(&$polytomousKey){
1026

    
1027
  $keyStyle = "linkedStyle"; // TODO settings needed
1028

    
1029
  RenderHints::pushToRenderStack("polytomousKey");
1030
  // key nodes in linked style
1031
  $out = '<table class="polytomousKey polytomousKey_'.$keyStyle.'">';
1032
  $out .= theme('cdm_polytomousKey_'.$keyStyle.'_subgraph', $polytomousKey->root);
1033
  $out .= '</table>';
1034
  RenderHints::popFromRenderStack();
1035
  return $out;
1036
}
1037

    
1038
function theme_cdm_polytomousKey_linkedStyle_subgraph(&$polytomousKeyNode){
1039

    
1040
  static $statementCountCharacter = '\'';
1041

    
1042
  $out = "";
1043

    
1044
  if(is_array($polytomousKeyNode->children)){
1045

    
1046
    $childIndex = 0;
1047

    
1048
    // render edges of the current node
1049
    foreach($polytomousKeyNode->children as &$child){
1050

    
1051
      if(!isset($child->statement)){
1052
        // skip node with empty statements (see below for explanation: "Special case")
1053
        continue;
1054
      }
1055

    
1056
      /*
1057
       * Special case:
1058
       * Child nodes with empty statements but taxa as leaf are to
1059
       * treated as if all those taxa where direct children of the source node.
1060
       */
1061
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
1062
      $islinkToTaxon = isset($child->taxon->uuid);
1063
      $islinkToSubKey = isset($child->subkey->uuid);
1064
      $islinkToOtherNode = isset($child->otherNode);
1065
      $islinkToNode = $child->nodeNumber && !$islinkToManyTaxa && !$islinkToOtherNode; // either null or 0
1066
      $hasQuestion = isset($polytomousKeyNode->question->label_l10n);
1067
      $hasFeature = isset($polytomousKeyNode->feature);
1068

    
1069
      //$indentEdge = $hasQuestion && $childIndex > 0;
1070

    
1071
      // Question
1072
      if($hasQuestion && $childIndex == 0){
1073
          // place question, as extra table row
1074
          $out .= '<tr class="question new_section">';
1075
          $out .= '<td class="nodeNumber">'. uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber) . "</td>";
1076
          $out .= '<td class="question">' . $polytomousKeyNode->question->label_l10n . '</td>';
1077
          $out .= '</tr>';
1078
      }
1079

    
1080
      $out .= '<tr class="childCount_' . $childIndex . (!$hasQuestion && $childIndex == 0 ? ' new_section':''). '">';
1081

    
1082
      if($hasQuestion){
1083
        $out .= '<td class="nodeNumber"></td>';
1084
      } else {
1085
        $out .= '<td class="nodeNumber">'. uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childIndex , $statementCountCharacter)) . "</td>";
1086
      }
1087

    
1088
      $out .= '<td ' . RenderHints::getHtmlElementID($child) . '  class="edge'.($hasQuestion? ' edge-indent': '').'">';
1089

    
1090
      // Feature
1091
      if($hasFeature){
1092
        $out .= $polytomousKeyNode->feature->representation_L10n . ": ";
1093
      }
1094

    
1095
      // Statement
1096
      $out .=  $child->statement->label_l10n;
1097

    
1098
      // --- links to nodes taxa and subkeys
1099
      $out .= '<div class="nodeLink">';
1100

    
1101
     // link to a PolytomousKeyNode
1102
      if($islinkToNode){
1103
        $out .= '<div class="nodeLinkToNode">';
1104
        if(is_object($child->modifyingText)){
1105
            $out .= theme('cdm_poytomousKeyNode_modifyingText', $child->modifyingText);
1106
        }
1107
        $out .= l($child->nodeNumber, $_REQUEST["q"], null, null, $child->uuid) . '</div>';
1108
      }
1109

    
1110
      // link to a PolytomousKeyNode
1111
      if($islinkToOtherNode){
1112
        $out .= '<div class="nodeLinkToOtherNode">';
1113
        if(is_object($child->modifyingText)){
1114
            $out .= theme('cdm_poytomousKeyNode_modifyingText', $child->modifyingText);
1115
        }
1116
        $out .= l($child->otherNode->nodeNumber, $_REQUEST["q"], null, null, $child->otherNode->uuid) . '</div>';
1117
      }
1118

    
1119
      // link to one or many taxa
1120
      if($islinkToTaxon || $islinkToManyTaxa){
1121

    
1122
        if($islinkToManyTaxa){
1123
          $taxonChildren = $child->children;
1124
        } else {
1125
          $taxonChildren = array($child);
1126
        }
1127

    
1128
        foreach($taxonChildren as $taxonChild){
1129
          // TODO many taxa $child->children->taxon
1130
          $out .= '<div class="nodeLinkToTaxon">';
1131
          if(is_object($taxonChild->modifyingText)){
1132
            $out .= theme('cdm_poytomousKeyNode_modifyingText', $taxonChild->modifyingText);
1133
          }
1134
          $out .=  theme("cdm_taxonName", $taxonChild->taxon->name, url(path_to_taxon($taxonChild->taxon->uuid)));
1135
          $out .=  '</div>';
1136
        }
1137

    
1138
        // link to a subkey
1139
        if($islinkToSubKey){
1140
          $out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', $child->subkey) . '</div>';
1141
        }
1142

    
1143
      }
1144

    
1145
      $out .= '</div>'; // end node link
1146
      $out .= '</td>'; // end edge
1147
      $out .= '</tr>';
1148

    
1149
      $childIndex++;
1150
    }
1151

    
1152
    // recurse into child nodes
1153
    foreach($polytomousKeyNode->children as &$child){
1154
      $out .= theme('cdm_polytomousKey_linkedStyle_subgraph', $child);
1155
    }
1156

    
1157
  }
1158

    
1159
  return $out;
1160
}
1161

    
1162
function theme_cdm_poytomousKeyNode_modifyingText($modifyingText){
1163
  if(is_object($modifyingText)){
1164
    $i = 0;
1165
    foreach(get_object_vars($modifyingText) as $language=>$languageString){
1166
      $out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">'. $languageString->text . '</span> ';
1167
    }
1168
  }
1169
  return $out;
1170
}
1171

    
1172
/**
1173
 * Renders a list of a specific type of IdentificationKeys, the list can be restricteded by a taxon.
1174
 * @param $type The simple name of the cdm class implementing the interface IIdentificationKey,
1175
 *          valid values are : PolytomousKey, MediaKey, MultiAccessKey
1176
 * @param $taxonUuid if given this parameter restrict the listed keys to
1177
 *          those which have the taxon identified be this uuid in scope.
1178
 */
1179
function theme_cdm_list_IdentificationKeys($type, $taxonUuid = null, $pageSize, $pageNumber){
1180

    
1181
  $keyList = _list_IdentificationKeys($type, $taxonUuid);
1182
  if(!$keyList || count ($keyList) == 0){
1183
    return;
1184
  }
1185

    
1186
  RenderHints::pushToRenderStack('list_IdentificationKeys');
1187
  $out = '<ul>';
1188
  foreach ($keyList as $key){
1189
    $out .= '<li>';
1190
    $out .= theme('cdm_IdentificationKey', $key);
1191
    $out .= '</li>';
1192
  }
1193
  $out .= '</ul>';
1194
  $out .= theme("cdm_annotation_footnotes", RenderHints::getRenderPath());
1195
  RenderHints::popFromRenderStack();
1196

    
1197
  return $out;
1198
}
1199

    
1200
function theme_cdm_block_IdentificationKeys($taxonUuid = null, $pageSize = null){
1201

    
1202
  static $types = array("PolytomousKey"=>"Polytomous", "MediaKey"=>"Media", "MultiAccessKey"=>"Multiaccess");
1203
  RenderHints::pushToRenderStack('block_IdentificationKeys');
1204
  $out = '';
1205
  foreach($types as $type=>$label){
1206
    $keylist = theme('cdm_list_IdentificationKeys', $type, $taxonUuid, $pageSize, $pageNumber);
1207
    if(!$keylist){
1208
      continue;
1209
    }
1210
    $out .= '<div class="'.$type.'">';
1211
    $out .= '<h3>'.t($label)."</h3>";
1212
    $out .= $keylist;
1213
    $out .= '</div>';
1214
  }
1215
  RenderHints::popFromRenderStack();
1216
  return $out;
1217
}
(2-2/8)