Project

General

Profile

Download (49.1 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 if ($descriptionElement->class == 'Uses') {
492
          $outArray[] = theme('cdm_descriptionElement_Uses', $descriptionElement);
493
        }else {
494
        $outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
495
      }
496
    }
497
  }
498

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

    
505

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

    
509
  }
510

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

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

    
522
  RenderHints::popFromRenderStack();
523
  return $out;
524
}
525

    
526

    
527

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

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

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

    
570
    }
571

    
572
    RenderHints::popFromRenderStack();
573
    return $out;
574
}
575

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

    
583

    
584
	if(!$enclosingTag){
585
		$enclosingTag = "span";
586
	}
587

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

    
593
  foreach($descriptionElements as $descriptionElement){
594

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

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

    
615
  RenderHints::popFromRenderStack();
616
  return $out;
617
}
618

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

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

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

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

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

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

    
752
  RenderHints::popFromRenderStack();
753
  return $out;
754
}
755

    
756
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
757

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

    
764
function theme_cdm_IdentifieableSource($source, $doLink = TRUE){
765

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

    
772

    
773

    
774

    
775

    
776
/*
777
 function theme_cdm_descriptionElementDistribution($descriptionElements){
778

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

    
800
 $out = substr($out, 0, strlen($out)-strlen($separator) );
801

    
802
 RenderHints::popFromRenderStack();
803
 return $out;
804

    
805
 }
806
 */
807

    
808

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

    
818
  $server = getEDITMapServiceURI();
819

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

    
829

    
830
  $fontStyles = array(0 => "plane", 1 => "italic");
831

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

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

    
844

    
845
  /* ------ choose the display mode, either openlayers or static image ------ */
846

    
847
  if(variable_get('cdm_dataportal_map_openlayers', 1)){
848

    
849
    /* =========== display distributions using the openlayers map viewer =========== */
850

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

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

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

    
871
  } else {
872

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

    
882

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

    
886

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

    
890
    $map_service_script_name = "areas.php";
891

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

    
907
      $map_service_script_name = "rest_gen.php";
908

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

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

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

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

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

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

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

    
950
    }
951

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

    
957
}
958

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

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

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

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

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

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

    
1007
function theme_cdm_IdentificationKey($identificationKey, $doLinkToKeyPage = true, $showIdentificationKeyTitle = true){
1008

    
1009
   $parentRenderPath = RenderHints::getRenderPath();
1010
   RenderHints::pushToRenderStack("IdentificationKey");
1011

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

    
1034
function theme_cdm_polytomousKey(&$polytomousKey){
1035

    
1036
  $keyStyle = "linkedStyle"; // TODO settings needed
1037

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

    
1047
function theme_cdm_polytomousKey_linkedStyle_subgraph(&$polytomousKeyNode){
1048

    
1049
  static $statementCountCharacter = '\'';
1050

    
1051
  $out = "";
1052

    
1053
  if(is_array($polytomousKeyNode->children)){
1054

    
1055
    $childIndex = 0;
1056

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

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

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

    
1078
      //$indentEdge = $hasQuestion && $childIndex > 0;
1079

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

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

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

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

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

    
1104
      // Statement
1105
      $out .=  $child->statement->label_l10n;
1106

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

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

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

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

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

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

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

    
1152
      }
1153

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

    
1158
      $childIndex++;
1159
    }
1160

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

    
1166
  }
1167

    
1168
  return $out;
1169
}
1170

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

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

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

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

    
1206
  return $out;
1207
}
1208

    
1209
function theme_cdm_block_IdentificationKeys($taxonUuid = null, $pageSize = null){
1210

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

    
1228

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

    
1316
			}
1317
		}
1318
	}
1319
	$out .= $descriptionOut . $synonymOut;
1320
	$out .= "</ul></div>";
1321
	return $out;
1322
}
1323

    
1324
//The Use theming function here will handle the display of the Use Descriptions 
1325
function theme_cdm_block_Uses ($taxonUuid = null, $pageSize = null) {
1326
	RenderHints::pushToRenderStack('block_Uses');
1327
	
1328
	if ($taxonUuid == null) {
1329
		return;
1330
	}
1331
	$out = '';
1332
	$markerTypes = array();
1333
	$markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
1334
	$useDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxonUuid, queryString($markerTypes));
1335
	if(!empty($useDescriptions)) {
1336
		$out .= '<div id="block-cdm_dataportal-feature-description" class="clear-block block block-cdm_dataportal-feature"><H2><a name="userecords"> </a> Uses </H2>';
1337
  		$formatUseDescriptions = theme('cdm_UseDescription', $useDescriptions, $taxonUuid, $pageSize, $pageNumber);
1338
		$out .= $formatUseDescriptions;
1339
		$out .="</div>";
1340
  	}
1341
	
1342
	return $out;
1343
}
(2-2/8)