Project

General

Profile

Download (49.3 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
      // --- USE TEXTDATA --- //
481
      else if($descriptionElement->feature->uuid == UUID_USE){
482
      	//Do nothing to avoid rendering	
483
      }
484

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

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

    
503

    
504
  if($image_sources){
505
      $outArray[] = theme('cdm_description_element_image_source', $image_sources, true);
506

    
507
  }
508

    
509
  if(variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT'){
510
    $outArray[] = theme('cdm_description_ordered_distributions', $taxon_uuid, $distributionElements);
511
  }else{
512
    ksort($distributionElements);
513
    $outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements); // TODO , $entryEnclosingTag);
514
  }
515

    
516
  // take the feature of the last $descriptionElement
517
  $feature = $descriptionElement->feature;
518
  $out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingTag);
519

    
520
  RenderHints::popFromRenderStack();
521
  return $out;
522
}
523

    
524

    
525

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

    
539
/**
540
 *
541
 */
542
function theme_cdm_description_element_image_source($image_sources, $asListElement) {
543
    $out = '';
544
    $separator = ',';
545
    RenderHints::pushToRenderStack('descriptionElementImageSource');
546
    RenderHints::setFootnoteListKey(UUID_IMAGE_SOURCES);
547

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

    
568
    }
569

    
570
    RenderHints::popFromRenderStack();
571
    return $out;
572
}
573

    
574
/**
575
 *
576
 * @param unknown_type $descriptionElements
577
 * @param String $enclosingTag
578
 */
579
function theme_cdm_descriptionElementDistribution($descriptionElements, $enclosingTag = "span"){
580

    
581

    
582
	if(!$enclosingTag){
583
		$enclosingTag = "span";
584
	}
585

    
586
  $out = '';
587
  $separator = ',';
588
  RenderHints::pushToRenderStack('descriptionElementDistribution');
589
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
590

    
591
  foreach($descriptionElements as $descriptionElement){
592

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

    
609
    $out .= '<'. $enclosingTag .' class="descriptionElement descriptionElement-'.$descriptionElement->uuid.'">'
610
      . $descriptionElement->area->representation_L10n . $footnoteKeyListStr . ' </'. $enclosingTag .'>';
611
  }
612

    
613
  RenderHints::popFromRenderStack();
614
  return $out;
615
}
616

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

    
635
function theme_cdm_description_ordered_distributions($taxon_uuid, $descriptionElements){
636
  //returning null if no description elements
637
  if ($descriptionElements == null){
638
    return '';
639
  }
640
  //initialization some variables
641
  $out = '';
642
  $separator = ',';
643
  RenderHints::pushToRenderStack('descriptionElementDistribution');
644
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
645
  //getting all the taxon description for a given taxon
646
  $markerTypesEmpty = array();
647
  //$markerTypesEmpty['markerTypes'] = 'af9860ff-08f5-4b4d-863c-49ae96985115';
648
  $markerTypesEmpty['markerTypes'] = '';
649
  $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon_uuid, queryString($markerTypesEmpty));
650
  foreach ($taxonDescriptions as $description){
651
    $descriptions_uuids[] = $description->uuid;
652
  }
653
  //getting the sortered distributions (omiting level ??)
654
  $request_params = array();
655
  $request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
656
  $ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, join(',',$descriptions_uuids), queryString($request_params));
657
  $ordered_areas = $ordered_areas->rootElement->children;
658

    
659
  //printing the distributions
660
  foreach ($ordered_areas as $element_level1){
661
    //level1
662
    if ($element_level1->data){
663
      $out .= '<dt>' . $element_level1->data->area->representation_L10n . ':</dt> ';
664
    }
665
    $out .= '<dd>';
666

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

    
738
        if (strlen($text_l4_aux) > 0){
739
          $out .= "$text_l3 $fnKeysLevel3Str ($text_l4_aux); ";
740
        }else{
741
          $out .= "$text_l3 $fnKeysLevel3Str; ";
742
        }
743

    
744
      }
745
    }//level3
746
    $out = substr($out, 0, -2);
747
    $out .= '.</dd>';
748
  }//level1
749

    
750
  RenderHints::popFromRenderStack();
751
  return $out;
752
}
753

    
754
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
755

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

    
762
function theme_cdm_IdentifieableSource($source, $doLink = TRUE){
763

    
764
  if(isset($source->citation)){
765
    $out = theme('cdm_reference', $source->citation, $source->citationMicroReference, $doLink);
766
  }
767
  return $out;
768
}
769

    
770

    
771

    
772

    
773

    
774
/*
775
 function theme_cdm_descriptionElementDistribution($descriptionElements){
776

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

    
798
 $out = substr($out, 0, strlen($out)-strlen($separator) );
799

    
800
 RenderHints::popFromRenderStack();
801
 return $out;
802

    
803
 }
804
 */
805

    
806

    
807
/**
808
 * TODO
809
 * Quick-and-dirty solution to show distribution service to exemplar groups
810
 *
811
 * @param unknown_type $featureTo
812
 * @return unknown
813
 */
814
function theme_cdm_distribution_map($taxon){
815

    
816
  $server = getEDITMapServiceURI();
817

    
818
  if(!$server){
819
    //warning message
820
    drupal_set_message('No \'Geoservice Access Point\' has been set so far. '
821
    . 'Please configure the variable \'Geoservice Access Point\' here '
822
    . l('CDM Dataportal Settings', 'admin/settings/cdm_dataportal/geo'), 'warning');
823
    //message to render
824
    return "<p>No geoservice specified</p>";
825
  }
826

    
827

    
828
  $fontStyles = array(0 => "plane", 1 => "italic");
829

    
830
  // query cdm server for map service uri parameters
831
  $map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
832
  $out .= "<!-- map_data_parameters:". print_r($map_data_parameters, true) . " -->";
833
  $query_string = $map_data_parameters->String;
834
  if(!$query_string){
835
    // the $query_string is empty if there are no distribution areas defined
836
    return ;
837
  }
838

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

    
842

    
843
  /* ------ choose the display mode, either openlayers or static image ------ */
844

    
845
  if(variable_get('cdm_dataportal_map_openlayers', 1)){
846

    
847
    /* =========== display distributions using the openlayers map viewer =========== */
848

    
849
    $legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
850
    $legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
851
    $legend_url_font_style = $fontStyles[$legend_url_font_style];
852
    $legend_url_icon_width  = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
853
    $legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
854

    
855
    $legendFormatQueryStr  = "format=image".urlencode('/')."png&TRANSPARENT=TRUE";
856
    $legendFormatQueryStr .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
857
    //TODO why is the layer=topp:tdwg_level_4 parameter neede at all here??
858
    $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);
859

    
860
    $out .= get_openlayers_map(
861
      variable_get('cdm_dataportal_geoservice_display_width', 300),
862
      variable_get('cdm_dataportal_geoservice_bounding_box', false),
863
      null,
864
      $query_string,
865
      $legendFormatQueryStr,
866
      variable_get('cdm_dataportal_geoservice_map_caption', '')
867
    );
868

    
869
  } else {
870

    
871
    return get_image_map(
872
        variable_get('cdm_dataportal_geoservice_display_width', 300),
873
        variable_get('cdm_dataportal_geoservice_bounding_box', false),
874
        null,
875
        $query_string,
876
        $legendFormatQueryStr,
877
        variable_get('cdm_dataportal_geoservice_map_caption', '')
878
      );
879

    
880

    
881
    // simple image
882
    $mapStaticCaption = '&mc_s=Georgia,15,blue&mc=' . variable_get('cdm_dataportal_geoservice_map_caption', '');
883

    
884

    
885
    $query_string .= '&img=true';
886
    $query_string .= '&legend=1&mlp=3' . $mapStaticCaption . '&recalculate=false';
887

    
888
    $map_service_script_name = "areas.php";
889

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

    
905
      $map_service_script_name = "rest_gen.php";
906

    
907
      $bgcolor_areaStyleId= "y";
908
      $baselayer_areaStyleId= "z";
909
      $bgcolor_layer='';
910
      $additional_area_styles = array();
911

    
912
      // background color:
913
      if(variable_get('map_bg_color', '')){
914
        $bgcolor_layer = "background_gis:".$bgcolor_areaStyleId;
915
        $additional_area_styles[] = $bgcolor_areaStyleId . ":" . variable_get('map_bg_color', '') . ",,";
916
      }
917

    
918
      //TODO HACK to replace the default base layer which currently is tdwg4 !!!
919
      if(strpos($query_string, "?l=") !== FALSE){
920
        $layer_param_token = "?l=";
921
      } else {
922
        $layer_param_token = "&l=";
923
      }
924
      if(strpos($query_string, "?as=") !== FALSE){
925
        $areystyle_param_token = "?as=";
926
      } else {
927
        $areystyle_param_token = "&as=";
928
      }
929

    
930
      if(variable_get('map_base_layer', '')){
931
        $query_string = str_replace($layer_param_token."tdwg4", "$layer_param_token".variable_get('map_base_layer', ''). ":" . $baselayer_areaStyleId, $query_string);
932
      } else {
933
        $query_string = str_replace($layer_param_token."tdwg4", $layer_param_token."tdwg4:".$baselayer_areaStyleId . ",", $query_string);
934
      }
935

    
936
      if($bgcolor_layer){
937
        $query_string = str_replace($layer_param_token, $layer_param_token . $bgcolor_layer . ",", $query_string);
938
      }
939

    
940
      if(variable_get('map_base_layer_style', '')){
941
        $additional_area_styles[] = $baselayer_areaStyleId . ":" . variable_get('map_base_layer_style', '');
942
      }
943

    
944
      foreach ($additional_area_styles as $as) {
945
        $query_string = str_replace($areystyle_param_token, $areystyle_param_token . $as . "|", $query_string);
946
      }
947

    
948
    }
949

    
950
    $mapUri = url("$server/$map_service_script_name?$query_string");
951
    $out .= '<img class="distribution_map" src="' . $mapUri . '" alt="Distribution Map" />';
952
  }
953
  return $out;
954

    
955
}
956

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

    
966
  if(!$type){
967
    drupal_set_message("Type parameter is missing", "error");
968
    return;
969
  }
970
  $cdm_ws_pasepath = null;
971
  switch($type){
972
    case "PolytomousKey" : $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY; break;
973
    case "MediaKey" : $cdm_ws_pasepath = CDM_WS_MEDIAKEY; break;
974
    case "MultiAccessKey" : $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY; break;
975
  }
976

    
977
  if(!$cdm_ws_pasepath){
978
    drupal_set_message("Type parameter is not valid: ".$type, "error");
979
  }
980

    
981
  $queryParameters  = '';
982
  if(is_numeric($pageSize)){
983
    $queryParameters  = "pageSize=".$pageSize;
984
  } else {
985
    $queryParameters  = "pageSize=0";
986
  }
987

    
988
  if(is_numeric($pageNumber)){
989
    $queryParameters  = "pageNumber=".$pageNumber;
990
  } else {
991
    $queryParameters  = "pageNumber=0";
992
  }
993
  $queryParameters  = null;
994
  if($taxonUuid){
995
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
996
  }
997
  $pager = cdm_ws_get($cdm_ws_pasepath, null, $queryParameters);
998

    
999
  if(!$pager || $pager->count == 0){
1000
      return array();
1001
  }
1002
  return $pager->records;
1003
}
1004

    
1005
function theme_cdm_IdentificationKey($identificationKey, $doLinkToKeyPage = true, $showIdentificationKeyTitle = true){
1006

    
1007
   $parentRenderPath = RenderHints::getRenderPath();
1008
   RenderHints::pushToRenderStack("IdentificationKey");
1009

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

    
1032
function theme_cdm_polytomousKey(&$polytomousKey){
1033

    
1034
  $keyStyle = "linkedStyle"; // TODO settings needed
1035

    
1036
  RenderHints::pushToRenderStack("polytomousKey");
1037
  // key nodes in linked style
1038
  $out = '<table class="polytomousKey polytomousKey_'.$keyStyle.'">';
1039
  $out .= theme('cdm_polytomousKey_'.$keyStyle.'_subgraph', $polytomousKey->root);
1040
  $out .= '</table>';
1041
  RenderHints::popFromRenderStack();
1042
  return $out;
1043
}
1044

    
1045
function theme_cdm_polytomousKey_linkedStyle_subgraph(&$polytomousKeyNode){
1046

    
1047
  static $statementCountCharacter = '\'';
1048

    
1049
  $out = "";
1050

    
1051
  if(is_array($polytomousKeyNode->children)){
1052

    
1053
    $childIndex = 0;
1054

    
1055
    // render edges of the current node
1056
    foreach($polytomousKeyNode->children as &$child){
1057

    
1058
      if(!isset($child->statement)){
1059
        // skip node with empty statements (see below for explanation: "Special case")
1060
        continue;
1061
      }
1062

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

    
1076
      //$indentEdge = $hasQuestion && $childIndex > 0;
1077

    
1078
      // Question
1079
      if($hasQuestion && $childIndex == 0){
1080
          // place question, as extra table row
1081
          $out .= '<tr class="question new_section">';
1082
          $out .= '<td class="nodeNumber">'. uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber) . "</td>";
1083
          $out .= '<td class="question">' . $polytomousKeyNode->question->label_l10n . '</td>';
1084
          $out .= '</tr>';
1085
      }
1086

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

    
1089
      if($hasQuestion){
1090
        $out .= '<td class="nodeNumber"></td>';
1091
      } else {
1092
        $out .= '<td class="nodeNumber">'. uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childIndex , $statementCountCharacter)) . "</td>";
1093
      }
1094

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

    
1097
      // Feature
1098
      if($hasFeature){
1099
        $out .= $polytomousKeyNode->feature->representation_L10n . ": ";
1100
      }
1101

    
1102
      // Statement
1103
      $out .=  $child->statement->label_l10n;
1104

    
1105
      // --- links to nodes taxa and subkeys
1106
      $out .= '<div class="nodeLink">';
1107

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

    
1117
      // link to a PolytomousKeyNode
1118
      if($islinkToOtherNode){
1119
        $out .= '<div class="nodeLinkToOtherNode">';
1120
        if(is_object($child->modifyingText)){
1121
            $out .= theme('cdm_poytomousKeyNode_modifyingText', $child->modifyingText);
1122
        }
1123
        $out .= l($child->otherNode->nodeNumber, $_REQUEST["q"], null, null, $child->otherNode->uuid) . '</div>';
1124
      }
1125

    
1126
      // link to one or many taxa
1127
      if($islinkToTaxon || $islinkToManyTaxa){
1128

    
1129
        if($islinkToManyTaxa){
1130
          $taxonChildren = $child->children;
1131
        } else {
1132
          $taxonChildren = array($child);
1133
        }
1134

    
1135
        foreach($taxonChildren as $taxonChild){
1136
          // TODO many taxa $child->children->taxon
1137
          $out .= '<div class="nodeLinkToTaxon">';
1138
          if(is_object($taxonChild->modifyingText)){
1139
            $out .= theme('cdm_poytomousKeyNode_modifyingText', $taxonChild->modifyingText);
1140
          }
1141
          $out .=  theme("cdm_taxonName", $taxonChild->taxon->name, url(path_to_taxon($taxonChild->taxon->uuid)));
1142
          $out .=  '</div>';
1143
        }
1144

    
1145
        // link to a subkey
1146
        if($islinkToSubKey){
1147
          $out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', $child->subkey) . '</div>';
1148
        }
1149

    
1150
      }
1151

    
1152
      $out .= '</div>'; // end node link
1153
      $out .= '</td>'; // end edge
1154
      $out .= '</tr>';
1155

    
1156
      $childIndex++;
1157
    }
1158

    
1159
    // recurse into child nodes
1160
    foreach($polytomousKeyNode->children as &$child){
1161
      $out .= theme('cdm_polytomousKey_linkedStyle_subgraph', $child);
1162
    }
1163

    
1164
  }
1165

    
1166
  return $out;
1167
}
1168

    
1169
function theme_cdm_poytomousKeyNode_modifyingText($modifyingText){
1170
  if(is_object($modifyingText)){
1171
    $i = 0;
1172
    foreach(get_object_vars($modifyingText) as $language=>$languageString){
1173
      $out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">'. $languageString->text . '</span> ';
1174
    }
1175
  }
1176
  return $out;
1177
}
1178

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

    
1188
  $keyList = _list_IdentificationKeys($type, $taxonUuid);
1189
  if(!$keyList || count ($keyList) == 0){
1190
    return;
1191
  }
1192

    
1193
  RenderHints::pushToRenderStack('list_IdentificationKeys');
1194
  $out = '<ul>';
1195
  foreach ($keyList as $key){
1196
    $out .= '<li>';
1197
    $out .= theme('cdm_IdentificationKey', $key);
1198
    $out .= '</li>';
1199
  }
1200
  $out .= '</ul>';
1201
  $out .= theme("cdm_annotation_footnotes", RenderHints::getRenderPath());
1202
  RenderHints::popFromRenderStack();
1203

    
1204
  return $out;
1205
}
1206

    
1207
function theme_cdm_block_IdentificationKeys($taxonUuid = null, $pageSize = null){
1208

    
1209
  static $types = array("PolytomousKey"=>"Polytomous", "MediaKey"=>"Media", "MultiAccessKey"=>"Multiaccess");
1210
  RenderHints::pushToRenderStack('block_IdentificationKeys');
1211
  $out = '';
1212
  foreach($types as $type=>$label){
1213
    $keylist = theme('cdm_list_IdentificationKeys', $type, $taxonUuid, $pageSize, $pageNumber);
1214
    if(!$keylist){
1215
      continue;
1216
    }
1217
    $out .= '<div class="'.$type.'">';
1218
    $out .= '<h3>'.t($label)."</h3>";
1219
    $out .= $keylist;
1220
    $out .= '</div>';
1221
  }
1222
  RenderHints::popFromRenderStack();
1223
  return $out;
1224
}
1225

    
1226

    
1227
//this theming function formats the use description and use record list for these descriptions 
1228
function theme_cdm_UseDescription($descriptions = null, $pageSize, $pageNumber) {
1229
	$out = '<div id="content"><ul id="Description" class ="description">';
1230
	if ($descriptions == null) {
1231
		return;
1232
	}
1233
	$descriptionSynonyms;
1234
	$descriptionOut = "";
1235
	$synonymOut = "";
1236
	foreach($descriptions as $description) {
1237
		$useSummary = "";
1238
		$synonyms = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY,$description->taxon->uuid);
1239
		$serializedSynonyms = serialize($synonyms);
1240
		foreach ($description->elements as $element) {
1241
			
1242
			if($element->feature->uuid == UUID_USE && !(strlen($useSummary)> 0)){
1243
				$useSummary = $element->multilanguageText_L10n->text;
1244
			}
1245
		}
1246
		foreach ($description->sources as $source) {
1247
			$isSynonym = false;
1248
			if($source->originalNameString) {
1249
				$originalTaxonUsedInSource = cdm_ws_get(CDM_WS_PORTAL_NAME_NAMESBYNAME, $source->originalNameString . ".");
1250
				
1251
				if (strpos($serializedSynonyms, $originalTaxonUsedInSource->uuid)) {
1252
					$isSynonym = true;
1253
				}
1254
				
1255
				if (!$isSynonym) {
1256
					$descriptionOut .='<li class="descriptionText DescriptionElement">';
1257
					$name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid),array(), NULL, NULL, FALSE ,TRUE);
1258
					$descriptionOut .= $name_used_in_source_link_to_show_use . ': ';
1259
					$descriptionOut .= $useSummary;
1260
					foreach ($description->sources as $source) {
1261
						if($source->originalNameString) {
1262
							//$out = $source->originalNameString . ':' . $out;
1263
						}
1264
						$descriptionOut .= " (" . theme('cdm_DescriptionElementSource', $source, true) . ")";
1265
					}
1266
					$descriptionOut .= '<ul>';
1267
					foreach ($description->elements as $descriptionElement) {
1268
						if($descriptionElement->feature->uuid == UUID_USE_RECORD){
1269
							$useRecordTags = explode(';', $descriptionElement->modifyingText->English->text);
1270
							//$descriptionOut .= '<li class="use_record_list">- ' . $useRecordTags[0] . '[' . $useRecordTags[1] . ']' . ' - ' . $useRecordTags[2] . ' - ' . $useRecordTags[3]. '[' .$useRecordTags[4]. ']' . ' - ' .   $useRecordTags[5] . '</li>';
1271
							$descriptionOut .= '<li class="use_record_list">- ' . $useRecordTags[0] . '[' . $useRecordTags[1] . ']'  . ' - ' . $useRecordTags[3]. ' - ' . $useRecordTags[4]. '[' .   $useRecordTags[5] . ']' .  ' - ' . $useRecordTags[2] . '</li>';
1272
						}
1273
					}
1274
					$descriptionOut .= '</ul></li>';
1275
					
1276
					
1277
				}
1278
				else {
1279
					
1280
					$synonymOut .='<li class="descriptionText DescriptionElement">';
1281
					$name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid),array(), NULL, NULL, FALSE ,TRUE);
1282
						
1283
					//$out .= $source->originalNameString . ': ';
1284
					$synonymOut .= $name_used_in_source_link_to_show_use . ': ';
1285
					$synonymOut .= $useSummary;
1286
					foreach ($description->sources as $source) {
1287
						if($source->originalNameString) {
1288
							//$out = $source->originalNameString . ':' . $out;
1289
						}
1290
						$synonymOut .= " (" . theme('cdm_DescriptionElementSource', $source, true) . ")";
1291
					}
1292
					$synonymOut .= '<ul>';
1293
					foreach ($description->elements as $descriptionElement) {
1294
						//print_r($descriptionElement);
1295
						if($descriptionElement->feature->uuid == UUID_USE_RECORD){
1296
							$useRecordTags = explode(';', $descriptionElement->modifyingText->English->text);
1297
							//$synonymOut .= '<li class="use_record_list">- ' . $useRecordTags[0] . '[' . $useRecordTags[1] . ']' . ' - ' . $useRecordTags[2] . ' - ' . $useRecordTags[3]. '[' .$useRecordTags[4]. ']' . ' - ' .   $useRecordTags[5] . '</li>';
1298
							$synonymOut .='<li class="use_record_list">- ' . $useRecordTags[0] . '[' . $useRecordTags[1] . ']'  . ' - ' . $useRecordTags[3]. ' - ' . $useRecordTags[4]. '[' .   $useRecordTags[5] . ']' .  ' - ' . $useRecordTags[2] . '</li>';
1299
						}
1300
					}
1301
					$synonymOut .= '</ul></li>';
1302
					
1303
				}
1304

    
1305
			}
1306
		}
1307
	}
1308
	$out .= $descriptionOut . $synonymOut;
1309
	$out .= "</ul></div>";
1310
	return $out;
1311
}
1312

    
1313
//The Use theming function here will handle the display of the Use Descriptions 
1314
function theme_cdm_block_Uses ($taxonUuid = null, $pageSize = null) {
1315
	RenderHints::pushToRenderStack('block_Uses');
1316
	
1317
	if ($taxonUuid == null) {
1318
		return;
1319
	}
1320
	$out = '';
1321
	$markerTypes = array();
1322
	$markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
1323
	$useDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxonUuid, queryString($markerTypes));
1324
	//$out .=  print_r($useDescriptions);
1325
	if(!empty($useDescriptions)) {
1326
		//$out .= print_r($useDescriptions);
1327
  		//$out .= print_r($useDescriptions);
1328
		$out .= '<div id="block-cdm_dataportal-feature-description" class="clear-block block block-cdm_dataportal-feature"><H2><a name="userecords"> </a> Uses </H2>';
1329
  		$formatUseDescriptions = theme('cdm_UseDescription', $useDescriptions, $pageSize, $pageNumber);
1330
		$out .= $formatUseDescriptions;
1331
		$out .="</div>";
1332
  	}
1333
	
1334
	return $out;
1335
}
(2-2/8)