Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / 7.x / modules / cdm_dataportal / theme / cdm_dataportal.descriptions.theme @ 2bbc28c8

History | View | Annotate | Download (57.1 KB)

1
<?php
2
/**
3
 * @file
4
 * Description theming functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15

    
16
/**
17
 * @todo Please document this function.
18
 * @see http://drupal.org/node/1354
19
 */
20
function theme_cdm_feature_nodesTOC($variables) {
21
  $featureNodes = $variables['featureNodes'];
22
  $out = '';
23
  $out .= '<ul>';
24

    
25
  foreach ($featureNodes as $node) {
26

    
27
    if (hasFeatureNodeDescriptionElements($node)) {
28

    
29
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
30
      // HACK to implement images for taxa, should be removed.
31
      if ($node->feature->uuid != UUID_IMAGE) {
32
        $out .= '<li>' . l(t(theme('cdm_feature_name', array('feature_name' => $featureRepresentation))), $_GET['q'], array(
33
         'attributes' => array('class' => array('toc')), 'fragment' => generalizeString($featureRepresentation))) . '</li>';
34
      }
35
    }
36
  }
37

    
38
  $out .= '</ul>';
39
  return $out;
40
}
41

    
42
/**
43
 * Theme function to alter the feature representation.
44
 *
45
 * It is highly qeutionalbe if this function should be completely removed.
46
 * If a feature needs a different representation this should be edited directly
47
 * in the cdm data but it shoud not be tweeked like this in the portal.
48
 *
49
 * Used in:
50
 *  - theme_cdm_feature_nodesTOC()
51
 *  - theme_cdm_feature_nodes()
52
 *  - theme_cdm_media_mime_application()
53
 *  - theme_cdm_media_mime_text()
54
 *
55
 * TODO delete this function? (a.kohlbecker feb 2013)
56
 *
57
 */
58
function theme_cdm_feature_name($variables) {
59
  $feature_name = $variables['feature_name'];
60
  // TODO replace by using translations ?
61
  return t($feature_name);
62
}
63

    
64
/**
65
 * Returns HTML for a taxon profile from the $mergedFeatureNodes of a given $taxon.
66
 *
67
 * The taxon profile consists of description elements which are ordered by the
68
 * structure defined by specific FeatureTree. The chosen FeatureTree is merged
69
 * with the list of desctiprion elements prior to using this method.
70
 *
71
 * The merged nodes can be obtained by making use of the
72
 * function cdm_ws_descriptions_by_featuretree().
73
 *
74
 * @see cdm_ws_descriptions_by_featuretree()
75
 *
76
 * @param array $variables
77
 *   An associative array containing:
78
 *   - mergedFeatureNodes
79
 *   -taxon
80
 *
81
 * @ingroup themeable
82
 */
83
function theme_cdm_feature_nodes($variables) {
84

    
85
  $mergedFeatureNodes = $variables['mergedFeatureNodes'];
86
  $taxon = $variables['taxon'];
87
  $out = '';
88

    
89
  RenderHints::pushToRenderStack('feature_nodes');
90

    
91
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
92

    
93
  // Creating an array to place the description elements in.
94
  foreach ($mergedFeatureNodes as $node) {
95

    
96
    if (hasFeatureNodeDescriptionElements($node)) {
97

    
98
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
99
      $block = new stdclass(); // Empty object.
100
      $block->module = 'cdm_dataportal';
101
      $media_list = array();
102

    
103
      if (true || $node->feature->uuid != UUID_IMAGE) {
104

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

    
110
        /*
111
         * Content/DISTRIBUTION.
112
         */
113
        if ($node->feature->uuid == UUID_DISTRIBUTION) {
114

    
115
          $node->descriptionElements = cdm_description_elements_prefer_computed($node->descriptionElements);
116

    
117
          if (variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
118
            $distributionTextDataList = array();
119
            $distributionElementsList = array();
120

    
121
            foreach ($node->descriptionElements as $descriptionElement) {
122
              if ($descriptionElement->class == "TextData") {
123
                $distributionTextDataList[] = $descriptionElement;
124
              }
125
              else {
126
                $distributionElementsList[] = $descriptionElement;
127
              }
128
            }
129

    
130

    
131
            if (count($distributionTextDataList) > 0) {
132
              $node->descriptionElements = $distributionElementsList;
133
              $block->content .= theme('cdm_descriptionElements', array(
134
                'descriptionElements' => $distributionTextDataList,
135
                'featureUuid' => $node->feature->uuid,
136
                'taxon_uuid' => $taxon->uuid,
137
              ));
138
            }
139
          }
140

    
141
          // Display cdm distribution map TODO this is a HACK to a proper
142
          // generic implementation?
143
          $map_render_element = compose_distribution_map($taxon);
144
          $block->content .= $map_render_element['#markup'];
145
          $block->content .= theme('cdm_descriptionElements', array(
146
            'descriptionElements' => $node->descriptionElements,
147
            'featureUuid' => $node->feature->uuid,
148
            'taxon_uuid' => $taxon->uuid,
149
          ));
150

    
151
        }
152

    
153
        /*
154
         * Content/COMMON_NAME.
155
         */
156
        elseif ($node->feature->uuid == UUID_COMMON_NAME) {
157
          // TODO why is theme_cdm_descriptionElement_CommonTaxonName not
158
          // beeing used???
159
         $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
160
          /*
161
          }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
162
          $block->content .= theme('cdm_image_sources',
163
          $node->descriptionElements);
164
          */
165
        }
166

    
167
        /*
168
         * Content/ALL OTHER FEATURES.
169
         */
170
        else {
171
          if (isset($node->descriptionElements)) {
172
            $taxon_uuid = NULL;
173
            if(isset($taxon) ) {
174
              $taxon_uuid = $taxon->uuid;
175
            }
176
            $block->content .= theme('cdm_descriptionElements', array(
177
              'descriptionElements' => $node->descriptionElements,
178
              'featureUuid' => $node->feature->uuid,
179
              'taxon_uuid' => $taxon_uuid,
180
            ));
181
          }
182

    
183
//           Content/ALL OTHER FEATURES/Subordinate Features
184
//           subordinate features are printed inline in one floating text,
185
//           it is expected hat supordinate features can "contain" TextData,
186
//           Qualitative- and Qualitative- DescriptioneElements
187
          if (isset($node->children[0])) {
188

    
189
            // TODO support more than one level of children.
190
            // can this be solved by resursively calling this very function?
191
            // @see http://dev.e-taxonomy.eu/trac/ticket/2393
192
            $text = '';
193
            foreach ($node->children as $child) {
194

    
195
              if (isset($child->descriptionElements) && is_array($child->descriptionElements)) {
196
                foreach ($child->descriptionElements as $element) {
197

    
198
                  if (is_array($element->media)) {
199
                    // Append media of supordinate elements to list of main
200
                    // feature.
201
                    $media_list = array_merge($media_list, $element->media);
202
                  }
203

    
204
                  switch ($element->class) {
205
                    case 'TextData':
206
                      // TODO use theme_cdm_descriptionElementTextData()
207
                      $out_child_elements = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
208
                      $out_child_elements = str_replace($child->feature->titleCache, '<em>' . $child->feature->representation_L10n . '</em>', $out_child_elements);
209
                      break;
210
                    case 'CategoricalData':
211
                      $out_child_elements  = '<em>' . $child->feature->representation_L10n . '</em> '
212
                        . theme('cdm_descriptionElement_CategoricalData', array('element' => $element));
213
                      break;
214
                    case 'QuantitativeData':
215
                      $out_child_elements = '<em>' . $child->feature->representation_L10n . '</em> '
216
                        . theme('cdm_descriptionElement_QuantitativeData', array('element' => $element));
217

    
218
                  }
219

    
220
                }
221
                $text .= " " . $out_child_elements;
222
                $out_child_elements = '';
223
              }
224
            }
225
            $block->content .= $text;
226
          }
227
        }
228

    
229
        /*
230
         * Media/ALL FEATURES.
231
         */
232
        if (isset($node->descriptionElements)) {
233
          $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
234
        }
235
        $captionElements = array('title', 'rights');
236
        $gallery = '';
237
        if (isset($gallery_settings['cdm_dataportal_media_maxextend']) && isset($gallery_settings['cdm_dataportal_media_cols'])) {
238
          $gallery = theme('cdm_media_gallerie', array(
239
            'mediaList' => $media_list,
240
            'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
241
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
242
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
243
            'captionElements' => $captionElements,
244
          ));
245
        }
246
        $block->content .= $gallery;
247
        $block->content .= theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid));
248
        $block->content .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid));
249

    
250
        // Add anchor to subject.
251
        $block->subject = '<a name="' . $block->delta . '"></a>' . $block->subject;
252

    
253
        // In D6: $out .= theme('block', $block);
254
        // Comment @WA @TODO check if need to set a region, and which one.
255
        $block->region = FALSE;
256
        $out .= theme('block', array('elements' => array(
257
          '#block' => $block,
258
          '#children' => $block->content,
259
        )));
260
      }
261
    }
262
  }
263
  RenderHints::popFromRenderStack();
264
  return $out;
265
}
266

    
267
/**
268
 * @todo Please document this function.
269
 * @see http://drupal.org/node/1354
270
 */
271
function theme_FeatureTree_hierarchy($variables) {
272

    
273
  $FeatureTreeUuid = $variables['FeatureTreeUuid'];
274
  if (!is_uuid($FeatureTreeUuid)) {
275
    return;
276
  }
277

    
278
  $out = '';
279
  $featureTree = cdm_ws_get(CDM_WS_FEATURETREE, array(
280
    $FeatureTreeUuid,
281
  ));
282

    
283
  if (isset($featureTree) && isset($featureTree->root)) {
284
    $out = '<ul class="' . $featureTree->class . '">';
285
    $out .= theme('FeatureTree_hierarchy_children', array('node' => $featureTree->root));
286
    $out .= '</ul>';
287
  }
288
  return $out;
289
}
290

    
291
/**
292
 * @todo Please document this function.
293
 * @see http://drupal.org/node/1354
294
 */
295
function theme_FeatureTree_hierarchy_children($variables) {
296

    
297
  $node = $variables['node'];
298
  $out = '';
299
  if (isset($node->children)) {
300

    
301
    foreach ($node->children as $childNode) {
302
      $out .= '<li>' . check_plain($childNode->feature->representation_L10n);
303
      if (isset($childNode->children) && count($childNode->children) > 0) {
304
        $out .= '<ul>' . theme('FeatureTree_hierarchy_children', array('node' => $childNode)) . '</ul>';
305
      }
306
      $out .= '</li>';
307
    }
308
  }
309
  return $out;
310
}
311

    
312
/**
313
 * Returns HTML for the texts in a description $elementArray.
314
 *
315
 * Joins the texts in $elementArray and encloses with a HTML tag.
316
 *
317
 * @param array $variables
318
 *   An associative array containing:
319
 *   - elementArray
320
 *   - feature: The feature to which the elements given in $elementArray are
321
 *     belonging to.
322
 *   - glue: Defaults to empty string.
323
 *   - sortArray: Whether to sort the $elementArray alphabetically.
324
 *   - enclosingHtml
325
 *
326
 * @ingroup themeable
327
 */
328
function theme_cdm_descriptionElementArray($variables) {
329
  $elementArray = $variables['elementArray'];
330

    
331
  $feature = $variables['feature'];
332
  $glue = $variables['glue'];
333
  $sortArray = $variables['sortArray'];
334
  $enclosingHtml = $variables['enclosingHtml'];
335
  $out = '<' . $enclosingHtml . ' class="description" id="' . $feature->representation_L10n . '">';
336

    
337
  if ($sortArray) {
338
    sort($elementArray);
339
  }
340

    
341
  $out .= join($elementArray, $glue);
342

    
343
  $out .= '</' . $enclosingHtml . '>';
344
  return $out;
345
}
346

    
347
/**
348
 * @todo Please document this function.
349
 * @see http://drupal.org/node/1354
350
 */
351
function theme_cdm_descriptionElement_CommonTaxonName($variables) {
352
  $element = $variables['element'];
353
  $out = '<span class="' . html_class_atttibute_ref($element) . '">' . $element->language->representation_L10n . ' (' . $element->area->titleCache . '): ' . $element->name . '</span>';
354
  return $out;
355
}
356

    
357
/**
358
* @todo Please document this function.
359
* @see http://drupal.org/node/1354
360
*/
361
function theme_cdm_descriptionElement_CategoricalData($variables) {
362
  $element = $variables['element'];
363

    
364
  $state_data_strings = array();
365
  if (isset($element->states)) {
366
    foreach ($element->states as $stateData) {
367

    
368
      $state  = NULL;
369

    
370
      if(isset($stateData->state)){
371
        $state = cdm_term_representation($stateData->state);
372
      }
373

    
374
      if (isset($stateData->modifyingText_L10n)) {
375
        $state = ' ' . $stateData->modifyingText_L10n;
376
      }
377

    
378
      $modifiers_strings = cdm_modifers_representations($stateData);
379

    
380
      $state_data_strings[] = $state . ($modifiers_strings ? ' ' . $modifiers_strings : '');
381

    
382
      // FIXME render sources
383

    
384
    }
385
  }
386
  $out = '<span class="' . html_class_atttibute_ref($element) . '">' . implode(', ', $state_data_strings) . '</span>';
387
  return $out;
388
}
389

    
390
function theme_cdm_descriptionElement_QuantitativeData($variables) {
391
  /*
392
   * - statisticalValues
393
   *   - value
394
   *   - modifiers
395
   *   - type
396
   * - unit->representation_L10n
397
   * - modifyingText
398
   * - modifiers
399
   * - sources
400
   */
401
  $element = $variables['element'];
402

    
403
  $out = '';
404

    
405
  $type_representation = NULL;
406
  $modifiers_strings = array();
407

    
408

    
409
  if (isset($element->statisticalValues)) {
410
    $value_array = array();
411
    foreach ($element->statisticalValues as $val) {
412
      if (isset($val->value)) {
413
        $value_array[] = $val->value;
414
      }
415
    }
416

    
417
    $out .= implode($value_array, ', ');
418
  }
419

    
420
  if (isset($element->unit)) {
421
    $out .= ' '. cdm_term_representation($element->unit);
422
  }
423

    
424
  if (isset($element->statisticalValues->modifyingText_L10n)) {
425
    $out .=  ' ' . $element->statisticalValues->modifyingText_L10n;
426
  }
427
  $modifers_string = cdm_modifers_representations($element->statisticalValues);
428
  $out .= ($modifers_string ? ' ' . cdm_modifers_representations($element->statisticalValues) : '');
429

    
430
  // FIXME render sources
431

    
432
  return $out;
433

    
434
}
435

    
436
/**
437
 * Returns HTML for citations textdata elements.
438
 *
439
 * TODO: assign a new name to the function? Because it is used for the citations
440
 * textdata elements and not for all text data description elements.
441
 *
442
 * @param array $variables
443
 *   An associative array containing:
444
 *   - element: The description element which contains the text information.
445
 *   - asListElement: A boolean which determines whether the citations should
446
 *     be rendered as a list or not.
447
 *   - feature_uuid
448
 *
449
 * @ingroup themeable
450
 */
451
function theme_cdm_descriptionElementTextData($variables) {
452

    
453
  $element = $variables['element'];
454
  $asListElement = $variables['asListElement'];
455
  $feature_uuid = $variables['feature_uuid'];
456

    
457
  $description = '';
458
  if (isset($element->multilanguageText_L10n->text)) {
459
    $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
460
  }
461
  $sourceRefs = '';
462
  $result = array();
463
  $out = '';
464
  $res_author = '';
465
  $res_date = '';
466
  if (isset($element->sources) && is_array($element->sources) && count($element->sources) > 0) {
467
    foreach ($element->sources as $source) {
468
      $referenceCitation = theme('cdm_OriginalSource', array('source' => $source));
469
      if ($description && strlen($description) > 0 && $referenceCitation) {
470
        $sourceRefs .= ' (' . $referenceCitation . ')';
471
      }
472
      elseif ($referenceCitation) {
473
        $sourceRefs = $referenceCitation;
474
      }
475

    
476
      if (strlen($sourceRefs) > 0) {
477
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
478
      }
479
      $name_used_in_source_link_to_show = '';
480
      // Do a link to name page.
481
      if (isset($source->nameUsedInSource->uuid) && isset($source->nameUsedInSource->titleCache)) {
482
        $name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache, path_to_name($source->nameUsedInSource->uuid), array(
483
          'attributes' => array(),
484
          'absolute' => TRUE,
485
          'html' => TRUE,
486
        ));
487
      }
488
      // Show a text without link.
489
      elseif (isset($source->nameUsedInSource->originalNameString) && strlen($source->nameUsedInSource->originalNameString) > 0) {
490
        $name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
491
      }
492

    
493
      if ($asListElement) {
494

    
495
       $out = '<li class="descriptionText DescriptionElement">';
496
        // Adding ":" if necessary.
497
        if (!empty($name_used_in_source_link_to_show)) {
498
          if ( (!empty($description)|| !empty($sourceRefs)) && $feature_uuid != UUID_CHROMOSOMES_NUMBERS) {
499
            $out .= $name_used_in_source_link_to_show . ': ';
500
          } else {
501
            $out .= $name_used_in_source_link_to_show . ' ';
502
          }
503
        }
504
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $element, 'footnote_list_key' => $feature_uuid)) . '</li>';
505
      }
506
      else {
507
        if ($name_used_in_source_link_to_show) {
508
          $name_used_in_source_link_to_show = ' (name in source: ' . $name_used_in_source_link_to_show . ')';
509
        }
510

    
511
        $out = '<span class="DescriptionElement DescriptionElement-' . $element->class . '">' . $description . $sourceRefs . $name_used_in_source_link_to_show . '</span>';
512
      }
513
    }
514
  }
515
  else {
516
    // If no sources, print the description.
517
    $out = $description;
518
  }
519
  return $out;
520
}
521

    
522
/**
523
 * @todo Please document this function.
524
 * @see http://drupal.org/node/1354
525
 */
526
function theme_cdm_common_names($variables) {
527
  $elements = $variables['elements'];
528
  $text_data_out = '';
529
  $common_name_out = '';
530
  $separator = ',';
531
  $textData_commonNames = array();
532

    
533
  if (is_array($elements)) {
534
    foreach ($elements as $element) {
535
      if ($element->class == 'CommonTaxonName') {
536

    
537
        // common name without a language or area, should not happen but is possible
538
        $language_area_key = '';
539
        if (isset($element->language->representation_L10n)) {
540
          $language_area_key .= '<b>' . $element->language->representation_L10n . '</b>';
541
        }
542
        if(isset($element->area->titleCache) && strlen($element->area->titleCache) > 0){
543
          $language_area_key .= ($language_area_key ? ' '  : '') . '(' . $element->area->titleCache . ')';
544
        }
545

    
546
        if(isset($common_names[$language_area_key][$element->name])) {
547
          // same name already exists for language and areae combination, se we merge the description elements
548
          cdm_merge_description_elements($common_names[$language_area_key][$element->name], $element);
549
        } else{
550
          // otherwise add as new entry
551
          $common_names[$language_area_key][$element->name] = $element;
552
        }
553

    
554
      }
555
      elseif ($element->class == 'TextData') {
556
        $textData_commonNames[] = $element;
557
      }
558
    }
559
  }
560
  // Handling common names.
561
  if (isset($common_names) && count($common_names) > 0) {
562
    // Sorting the array based on the key (language, + area if set).
563
    // Comment @WA there are common names without a language, so this sorting
564
    // can give strange results.
565
    ksort($common_names);
566

    
567
    // Creating the output to be render by Drupal.
568
    foreach ($common_names as $key => $elements) {
569
      ksort($elements); // sort names alphabetically
570
      $rendered_element_list = '';
571
      foreach ($elements as $element) {
572
        $sourcesFootnoteKeyList = '';
573
        // Adding footnotes sources.
574
        foreach ($element->sources as $source) {
575
          if (_is_original_source_type($source)) {
576
            $_fkey = FootnoteManager::addNewFootnote(UUID_COMMON_NAME, theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
577
            $sourcesFootnoteKeyList .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => ($sourcesFootnoteKeyList ? $separator : '')));
578
          }
579
        }
580
        if ($element->name) {
581
          $rendered_element_list .= '<span class="' . html_class_atttibute_ref($element) . '">' . (strlen($rendered_element_list) > 0 ? ', ' : '') . $element->name . $sourcesFootnoteKeyList . '</span>';
582
        }
583
      }
584
      if ($key) {
585
        $common_name_out .= (strlen($common_name_out) > 0 ? '; ' : '') . $key . ': ' . $rendered_element_list;
586
      }
587
      else {
588
        $common_name_out .= (strlen($common_name_out) > 0 ? '; ' : '') . $rendered_element_list;
589
      }
590
    }
591
  }
592
  // Handling commons names as text data.
593
  foreach ($textData_commonNames as $text_data_element) {
594
    $text_data_out .= theme('cdm_descriptionElementTextData', array(
595
      'element' => $text_data_element,
596
      'asListElement' => TRUE,
597
      'feature_uuid' => $text_data_element->feature->uuid,
598
    ));
599
  }
600

    
601
  $common_name_out = "<div class=common_names_as_common_names> $common_name_out </div>";
602
  $out_array[] = $text_data_out;
603
  $common_name_out_text_data = '<div class=common_names_as_text_data>' . theme('cdm_descriptionElementArray', array('elementArray' => $out_array, 'feature' => $element->feature)) . '</div>';
604

    
605
  return $common_name_out . $common_name_out_text_data;
606
  /*
607
  return $common_name_out . theme('cdm_descriptionElementArray', $out_array,
608
  $element->feature);
609
  return "<div class=common_names> $common_name_out
610
  $common_name_out_text_data";
611
  */
612
}
613

    
614
/**
615
 * Return HTML for a list of description elements.
616
 *
617
 * Usually these are of a specific feature type.
618
 *
619
 * @param array $variables
620
 *   An associative array containing:
621
 *   - array of descriptionElements which belong to the same feature.
622
 *     These descriptions elements of a Description must be ordered by the chosen feature tree by
623
 *     calling the function _mergeFeatureTreeDescriptions().
624
 *     @see _mergeFeatureTreeDescriptions()
625
 *   - featureUuid: currently unused, accoding code disabled
626
 *   - taxon_uuid: only used for ordered dditributions (will be removed!)
627
 *
628
 * @ingroup themeable
629
 */
630
function theme_cdm_descriptionElements($variables) {
631

    
632
  $descriptionElements = $variables['descriptionElements'];
633
  $featureUuid = $variables['featureUuid'];
634
  $taxon_uuid = $variables['taxon_uuid'];
635
  $outArray = array();
636

    
637
  /*
638
  $userDefined = mixed_variable_get(LAYOUT_SETTING_PREFIX . $featureUuid, FEATURE_TREE_LAYOUT_DEFAULTS);
639
  if(variable_get('distribution_sort',
640
      'NO_SORT') != 'NO_SORT'){
641
      $glue = '';
642
      $enclosingTag = 'dl';
643
      $entryEnclosingTag = NULL;
644
  } else if($userDefined &&
645
      $userDefined['enabled']){
646
    $glue = $userDefined['glue'];
647
    $enclosingTag =  $userDefined['enclosingTag'];
648
    $entryEnclosingTag = $userDefined['entryEnclosingTag'];
649
  } else { // TODO remove once  LAYOUT_SETTING_PREFIX-{uuid} setting are configured to work for all portals(selenium test still missing!!!)
650
    $glue = ''; $enclosingTag = 'ul';
651
    $entryEnclosingTag = NULL ;
652
  }
653
  */
654

    
655

    
656
  if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
657
    $glue = '';
658
    $enclosingTag = 'dl';
659
  }
660
  else {
661
    $glue = '';
662
    $enclosingTag = 'ul';
663
  }
664

    
665
  $sortOutArray = FALSE;
666
  $distributionElements = array();
667

    
668
  RenderHints::pushToRenderStack('cdm_descriptionElements');
669

    
670
  // Avoiding warning box in drupal for flora malesiana.
671
  if (is_array($descriptionElements)) {
672
    foreach ($descriptionElements as $descriptionElement) {
673

    
674
      // --- DISTRIBUTION ---- //
675
      if ($descriptionElement->feature->uuid == UUID_DISTRIBUTION) {
676
        if ($descriptionElement->class == 'Distribution' && is_object($descriptionElement->area)) {
677
          $sortKey = $descriptionElement->area->representation_L10n;
678
          $distributionElements[$sortKey] = $descriptionElement;
679
        }
680
        elseif ($descriptionElement->class == 'TextData') {
681
          $asListElement = FALSE;
682
          $repr = theme('cdm_descriptionElementTextData', array(
683
            'element' => $descriptionElement,
684
            'asListElement' => $asListElement,
685
            'feature_uuid' => $descriptionElement->feature->uuid,
686
          ));
687

    
688
          if (!array_search($repr, $outArray)) {
689
            $outArray[] = $repr;
690
            // TODO HINT: sorting in theme_cdm_descriptionElementArray will
691
            // not work since this array contains html attributes with uuids
692
            // !!!!
693
            $sortOutArray = TRUE;
694
            $glue = '<br/> ';
695
            $enclosingTag = 'p';
696
          }
697
        }
698
      }
699

    
700
      // --- IMAGE_SOURCES --- //
701
      elseif ($descriptionElement->feature->uuid == UUID_IMAGE_SOURCES) {
702
        $image_sources[] = $descriptionElement;
703
      }
704
      // --- USE TEXTDATA --- //
705
      elseif ($descriptionElement->feature->uuid == UUID_USE) {
706
        // Do nothing to avoid rendering.
707
      } else {
708
        /* decide based on the description element class
709
         *
710
         * TODO provide api_hook as extension point for this
711
         */
712
        switch ($descriptionElement->class) {
713
          case 'TextData':
714
            $asListElement = TRUE;
715
            $outArray[] = theme('cdm_descriptionElementTextData', array(
716
              'element' => $descriptionElement,
717
              'asListElement' => $asListElement,
718
              'feature_uuid' => $descriptionElement->feature->uuid,
719
            ));
720
            break;
721
          case 'CommonTaxonName':
722
            $outArray[] = theme('cdm_descriptionElement_CommonTaxonName', array('element' => $descriptionElement));
723
          break;
724
          case 'CategoricalData':
725
            $outArray[] = theme('cdm_descriptionElement_CategoricalData', array('element' => $descriptionElement));
726
            break;
727
          case 'QuantitativeData':
728
            $outArray[] = theme('cdm_descriptionElement_QuantitativeData', array('element' => $descriptionElement));
729
            break;
730
          case 'Uses':
731
          /* IGNORE Uses classes, these are handled completely in theme_cdm_UseDescription */
732
          break;
733
        default:
734
        $outArray[] = '<li>No method for rendering unknown description class: ' . $descriptionElement->class . '</li>';
735
      }
736
    }
737
    }
738
  }
739

    
740
  // If feature = NAME USAGE sort the list of sources.
741
  // This is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE.
742
  if ($descriptionElement->feature->uuid == UUID_NAME_USAGE) {
743
    sort($outArray);
744
  }
745

    
746
  if (isset($image_sources)) {
747
    $outArray[] = theme('cdm_description_element_image_source', array('image_sources' => $image_sources, 'asListElement' => TRUE));
748
  }
749

    
750
  if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
751
    $outArray[] = theme('cdm_description_ordered_distributions', array('taxon_uuid' => $taxon_uuid, 'descriptionElements' => $distributionElements));
752
  }
753
  else {
754
    ksort($distributionElements);
755
    // TODO , $entryEnclosingTag);
756
    $outArray[] = theme('cdm_descriptionElementDistribution', array(
757
      'descriptionElements' => $distributionElements,
758
    ));
759
  }
760

    
761
  // Take the feature of the last $descriptionElement.
762
  $feature = $descriptionElement->feature;
763

    
764
  $out = theme('cdm_descriptionElementArray', array(
765
    'elementArray' => $outArray,
766
    'feature' => $feature,
767
    'glue' => $glue,
768
    'sortArray' => $sortOutArray,
769
    'enclosingHtml' => $enclosingTag,
770
  ));
771

    
772
  RenderHints::popFromRenderStack();
773
  return $out;
774
}
775

    
776
/**
777
 * @todo Please document this function.
778
 * @see http://drupal.org/node/1354
779
 */
780
function compare_image_sources($a, $b) {
781
  if ($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text) {
782
    return 0;
783
  }
784
  return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
785
}
786

    
787
/**
788
 * @todo Please document this function.
789
 * @see http://drupal.org/node/1354
790
 */
791
function theme_cdm_description_element_image_source($variables) {
792
  $image_sources = $variables['image_sources'];
793
  $asListElement = $variables['asListElement'];
794
  $out = '';
795
  $separator = ',';
796
  RenderHints::pushToRenderStack('descriptionElementImageSource');
797
  RenderHints::setFootnoteListKey(UUID_IMAGE_SOURCES);
798

    
799
  // Sorting the image sources.
800
  usort($image_sources, "compare_image_sources");
801
  // Generate the footnotes.
802
  foreach ($image_sources as $image_source) {
803
    $footNoteKeys = cdm_annotations_as_footnotekeys($image_source);
804
    foreach ($image_source->sources as $source) {
805
      if (_is_original_source_type($source)) {
806
        $fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array(
807
          'source' => $source,
808
          'doLink' => FALSE,
809
        )));
810
        // Ensure uniqueness of the footnote keys.
811
        cdm_add_footnote_to_array($footNoteKeys, $fn_key);
812
      }
813
    }
814
    // Sort and render footnote keys.
815
    $footnoteKeyListStr = '';
816
    asort($footNoteKeys);
817
    foreach ($footNoteKeys as $footNoteKey) {
818
      $footnoteKeyListStr .= theme('cdm_footnote_key', array('footnoteKey' => $footNoteKey, 'separator' => ($footnoteKeyListStr ? $separator : '')));
819
    }
820
    // Return value!
821
    $out .= '<span class="descriptionElement descriptionElement-' . $image_source->uuid . '">' . $image_source->multilanguageText_L10n->text . $footnoteKeyListStr . '; </span>';
822
  }
823

    
824
  RenderHints::popFromRenderStack();
825
  return $out;
826
}
827

    
828
/**
829
 * @todo Please document this function.
830
 * @see http://drupal.org/node/1354
831
 */
832
function theme_cdm_descriptionElementDistribution($variables) {
833
  $descriptionElements = $variables['descriptionElements'];
834
  $enclosingTag = $variables['enclosingTag'];
835
  if (!$enclosingTag) {
836
    $enclosingTag = "span";
837
  }
838

    
839
  $out = '';
840
  $separator = ',';
841
  RenderHints::pushToRenderStack('descriptionElementDistribution');
842
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
843

    
844
  foreach ($descriptionElements as $descriptionElement) {
845

    
846
    // Annotations as footnotes.
847
    $footNoteKeys = cdm_annotations_as_footnotekeys($descriptionElement);
848
    // Source references as footnotes.
849
    foreach ($descriptionElement->sources as $source) {
850
      if (_is_original_source_type($source)) {
851
        $fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array(
852
          'source' => $source,
853
          'doLink' => FALSE,
854
        )));
855
        // Ensure uniqueness of the footnote keys.
856
        cdm_add_footnote_to_array($footNoteKeys, $fn_key);
857
      }
858
    }
859
    // Sort and render footnote keys.
860
    $footnoteKeyListStr = '';
861
    asort($footNoteKeys);
862
    foreach ($footNoteKeys as $footNoteKey) {
863
      $footnoteKeyListStr .= theme('cdm_footnote_key', array('footnoteKey' => $footNoteKey, 'separator' => ($footnoteKeyListStr ? $separator : '')));
864
    }
865

    
866
    $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $descriptionElement->uuid . '">' . $descriptionElement->area->representation_L10n . $footnoteKeyListStr . ' </' . $enclosingTag . '>';
867
  }
868

    
869
  RenderHints::popFromRenderStack();
870
  return $out;
871
}
872

    
873
/**
874
 * Compare two different footnotes objects.
875
 *
876
 * The comparison is based on the footnote key. The one which is
877
 * displayed as footnote number.
878
 *
879
 * @param mixed $a
880
 *   Footnote object $a.
881
 * @param mixed $b
882
 *   Footnote object $b.
883
 */
884
function footnotes_key_compare($a, $b) {
885
  $res = 0;
886
  if (empty($a) || empty($b)) {
887
    return $res;
888
  }
889
  if ($a->keyStr < $b->keyStr) {
890
    $res = -1;
891
  }
892
  elseif ($a->keyStr > $b->keyStr) {
893
    $res = 1;
894
  }
895
  return $res;
896
}
897

    
898
/**
899
 * @todo Please document this function.
900
 * @see http://drupal.org/node/1354
901
 */
902
function theme_cdm_description_ordered_distributions($variables) {
903

    
904
  $taxon_uuid = $variables['taxon_uuid'];
905
  $descriptionElements = $variables['descriptionElements'];
906

    
907
  // Returning NULL if there are no description elements.
908
  if ($taxon_uuid == null || $descriptionElements == NULL) {
909
    return NULL;
910
  }
911

    
912
  // Initialization of some variables.
913
  $out = '';
914
  $separator = ',';
915
  RenderHints::pushToRenderStack('descriptionElementDistribution');
916
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
917

    
918
  // Getting all the taxon description for a given taxon.
919
  $markerTypesEmpty = array();
920
  // $markerTypesEmpty['markerTypes'] = 'af9860ff-08f5-4b4d-863c-49ae96985115';
921
  $markerTypesEmpty['markerTypes'] = '';
922
  $queryString = $markerTypesEmpty['markerTypes'] ? queryString($markerTypesEmpty) : '';
923

    
924
  $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon_uuid, $queryString);
925
  foreach ($taxonDescriptions as $description) {
926
    $descriptions_uuids[] = $description->uuid;
927
  }
928

    
929
  // Getting the sortered distributions (omitting level ??).
930
  $request_params = array();
931
  $request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
932
  $ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, join(',', $descriptions_uuids), queryString($request_params));
933
  if (isset($ordered_areas->rootElement->children)) {
934
    $ordered_areas = $ordered_areas->rootElement->children;
935
  }
936

    
937
  // Printing the distributions.
938
  if (is_array($ordered_areas) && count($ordered_areas) > 0) {
939
    foreach ($ordered_areas as $element_level1) {
940
      // Level1.
941
      if ($element_level1->data) {
942
        $out .= '<dt>' . $element_level1->data->area->representation_L10n . ':</dt> ';
943
      }
944
      $out .= '<dd>';
945

    
946
      // Level3.
947
      foreach ($element_level1->children as $element_level3) {
948
        if ($element_level3->data) {
949
          $text_l3 = $element_level3->data->area->representation_L10n;
950
        }
951
        $fnKeysLevel3Str = '';
952
        $fnKeysLevel3 = cdm_annotations_as_footnotekeys($element_level3->data);
953
        foreach ($element_level3->data->sources as $source) {
954
          if (_is_original_source_type($source)) {
955
            $fn_key3 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
956
            cdm_add_footnote_to_array($fnKeysLevel3, $fn_key3);
957
          }
958
        }
959
        // Level4.
960
        $l4_regions = array();
961
        foreach ($element_level3->children as $element_level4) {
962
          if ($element_level4->data) {
963
            $text_l4 = $element_level4->data->area->representation_L10n;
964
            $l4_regions[$element_level3->data->area->representation_L10n] = '';
965
            $fnKeysLevel4Str = '';
966
            $fnKeysLevel4 = cdm_annotations_as_footnotekeys($element_level4->data);
967
            foreach ($element_level4->data->sources as $source) {
968
              if (_is_original_source_type($source)) {
969
                $fn_key4 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
970
                cdm_add_footnote_to_array($fnKeysLevel4, $fn_key4);
971
              }
972
            }
973
            usort($fnKeysLevel4, "footnotes_key_compare");
974
            $l4_regions[$text_l4] = $fnKeysLevel4;
975
          }
976
        }// Level4.
977
        // Managing level3 and level4 for generating the right output.
978
        usort($fnKeysLevel3, "footnotes_key_compare");
979
        foreach ($fnKeysLevel3 as $key3) {
980
          foreach ($l4_regions as $key4 => $value4) {
981
            cdm_add_footnote_to_array($l4_regions[$key4], $key3);
982
          }
983
        }
984
        if ($element_level3->numberOfChildren == 1 && $text_l3 == $element_level3->children[0]->data->area->representation_L10n) {
985
          // var_dump($element_level3->children[0]->data->area->representation_L10n);
986
          $fnStr = '';
987
          $region = array_pop($l4_regions);
988
          foreach ($region as $key) {
989
            $fnStr .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnStr ? $separator : '')));
990
          }
991
          $out .= "$text_l3 $fnStr; ";
992
          // Removing whitespaces when &fnStr is empty.
993
          if (substr($out, -3) == ' ; ') {
994
            $out = substr($out, 0, -3) . '; ';
995
          }
996
        }
997
        else {
998
          $fnKeysLevel3Str = '';
999
          foreach ($fnKeysLevel3 as $key) {
1000
            $fnKeysLevel3Str .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnKeysLevel3Str ? $separator : '')));
1001
          }
1002
          $text_l4_aux = '';
1003
          foreach ($l4_regions as $key => $value) {
1004
            $fnKeysLevel4Str = '';
1005
            if (is_array($l4_regions[$key])) {
1006
              foreach ($l4_regions[$key] as $fnkey) {// Warning why?
1007
                $fnKeysLevel4Str .= theme('cdm_footnote_key', array('footnoteKey' => $fnkey, 'separator' => ($fnKeysLevel4Str ? $separator : '')));
1008
              }
1009
            }
1010
            // if ($key != $text_l3 || sizeof($l4_regions > 1)){
1011
            if ($key != $text_l3) {
1012
              $text_l4_aux .= "$key $fnKeysLevel4Str, ";
1013
            }
1014
          }
1015
          $text_l4_aux = substr($text_l4_aux, 0, -2);
1016

    
1017
          if (strlen($text_l4_aux) > 0) {
1018
            $out .= "$text_l3 $fnKeysLevel3Str ($text_l4_aux); ";
1019
          }
1020
          else {
1021
            $out .= "$text_l3 $fnKeysLevel3Str; ";
1022
          }
1023
        }
1024
      }// Level3.
1025
      $out = substr($out, 0, -2);
1026
      $out .= '.</dd>';
1027
    }// Level1.
1028
  }
1029
  RenderHints::popFromRenderStack();
1030
  return $out;
1031
}
1032

    
1033

    
1034
/*
1035
function theme_cdm_descriptionElementDistribution($descriptionElements){ $out
1036
  = ''; $separator = ',';
1037
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1038
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1039
  foreach($descriptionElements as $descriptionElement){ // annotations as
1040
  footnotes $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys',
1041
  $descriptionElement); // source references as footnotes
1042
  $sourcesFootnoteKeyList = ''; foreach($descriptionElement->sources as
1043
  $source){ if(_is_original_source_type($source)){ $_fkey =
1044
  FootnoteManager::addNewFootnote(UUID_DISTRIBUTION,
1045
  theme('cdm_OriginalSource', $source, FALSE));
1046
  $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey,
1047
  UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : '')); } }
1048
  if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
1049
  $annotationFootnoteKeys .= $separator; } $out .=
1050
  $descriptionElement->area->representation_L10n . $annotationFootnoteKeys .
1051
  $sourcesFootnoteKeyList . ' '; } $out = substr($out, 0,
1052
  strlen($out)-strlen($separator) ); RenderHints::popFromRenderStack(); return
1053
  $out; }
1054
*/
1055

    
1056
/**
1057
 * Composes the render array for a distribution map of the given taxon.
1058
 *
1059
 * The distribution map can either be a plain image or a dynamic open layers map
1060
 * depending on the settings.
1061
 *
1062
 * compose_hook() implementation
1063
 *
1064
 * @param $taxon
1065
 *   The CDM Taxon instance to create the distribution map for.
1066
 * @return array
1067
 *    A drupal render array
1068
 *
1069
 * Similar compose function compose_map()
1070
 *
1071
 * @ingroup compose
1072
 */
1073
function compose_distribution_map($taxon) {
1074

    
1075
  $out = '';
1076
  $settings = get_edit_map_service_settings();
1077

    
1078
  $fontStyles = array(
1079
    0 => "plane",
1080
    1 => "italic",
1081
  );
1082

    
1083
  // Query cdm server for map service uri parameters.
1084
  $query_string = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
1085
  $query_string = $query_string->String;
1086
  $out .= "<!-- map_data_parameters:" . print_r($query_string, TRUE) . " -->";
1087
  if (!$query_string) {
1088
    // The $query_string is empty if there are no distribution areas defined.
1089
    return;
1090
  }
1091

    
1092
  /* ------ choose the display mode, either openlayers or static image ------ */
1093

    
1094
  $map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
1095

    
1096
  if ($map_settings['map_type'] == 1) {
1097

    
1098
    /* =========== display distributions using the openlayers map viewer =========== */
1099

    
1100
    $legendFormatQueryStr = "format=image" . urlencode('/') . "png"
1101
         . "&TRANSPARENT=TRUE"
1102
         . "&WIDTH=" . $map_settings['legend']['icon_width']
1103
         . "&HEIGHT=" . $map_settings['legend']['icon_height']
1104
           // TODO why is the layer=topp:tdwg_level_4 parameter needed at all here??
1105
           // AK: i think the tdwg_level_4 is used as place holder and will be replaced later on
1106
           // => search for "tdwg_level_4" in the code
1107
         . "&layer=topp" . urlencode(':') . "tdwg_level_4"
1108
         . "&LEGEND_OPTIONS=forceLabels" . urlencode(':') . "on"
1109
             . ";fontStyle" . urlencode(':') . $fontStyles[$map_settings['legend']['font_style']]
1110
             . ";fontSize" . urlencode(':') .  $map_settings['legend']['font_size']
1111
         . "&SLD=";
1112

    
1113
    $out .= get_openlayers_map(
1114
        $map_settings['width'],
1115
        $map_settings['height'],
1116
        $map_settings['bbox'],
1117
        NULL,
1118
        $query_string,
1119
        $legendFormatQueryStr,
1120
        $map_settings['caption']
1121
     );
1122
  }
1123
  else {
1124
    $legendFormatQueryStr = '';
1125
    $out = get_image_map(
1126
        $map_settings['width'],
1127
        $map_settings['height'],
1128
        $map_settings['bbox'],
1129
        NULL,
1130
        $query_string,
1131
        $legendFormatQueryStr,
1132
        $map_settings['caption']
1133
    );
1134
  }
1135
  return markup_to_render_array($out);
1136
}
1137

    
1138
/**
1139
 * Returns a list of a specific type of IdentificationKeys.
1140
 *
1141
 * The list can be restricteded by a taxon.
1142
 *
1143
 * @param string $type
1144
 *   The simple name of the cdm class implementing the interface
1145
 *   IdentificationKey, valid values are:
1146
 *   PolytomousKey, MediaKey, MultiAccessKey.
1147
 * @param string $taxonUuid
1148
 *   If given this parameter restrict the listed keys to those which have
1149
 *   the taxon identified be this uuid in scope.
1150
 *
1151
 * @return array
1152
 *   List with identification keys.
1153
 */
1154
function _list_IdentificationKeys($type, $taxonUuid = NULL, $pageSize = NULL, $pageNumber = NULL) {
1155
  if (!$type) {
1156
    drupal_set_message(t('Type parameter is missing'), 'error');
1157
    return;
1158
  }
1159
  $cdm_ws_pasepath = NULL;
1160
  switch ($type) {
1161
    case "PolytomousKey":
1162
      $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY;
1163
      break;
1164

    
1165
    case "MediaKey":
1166
      $cdm_ws_pasepath = CDM_WS_MEDIAKEY;
1167
      break;
1168

    
1169
    case "MultiAccessKey":
1170
      $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY;
1171
      break;
1172

    
1173
  }
1174

    
1175
  if (!$cdm_ws_pasepath) {
1176
    drupal_set_message(t('Type parameter is not valid: ') . $type, 'error');
1177
  }
1178

    
1179
  $queryParameters = '';
1180
  if (is_numeric($pageSize)) {
1181
    $queryParameters = "pageSize=" . $pageSize;
1182
  }
1183
  else {
1184
    $queryParameters = "pageSize=0";
1185
  }
1186

    
1187
  if (is_numeric($pageNumber)) {
1188
    $queryParameters = "pageNumber=" . $pageNumber;
1189
  }
1190
  else {
1191
    $queryParameters = "pageNumber=0";
1192
  }
1193
  $queryParameters = NULL;
1194
  if ($taxonUuid) {
1195
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
1196
  }
1197
  $pager = cdm_ws_get($cdm_ws_pasepath, NULL, $queryParameters);
1198

    
1199
  if (!$pager || $pager->count == 0) {
1200
    return array();
1201
  }
1202
  return $pager->records;
1203
}
1204

    
1205
/**
1206
 * @todo Please document this function.
1207
 * @see http://drupal.org/node/1354
1208
 */
1209
function theme_cdm_IdentificationKey($variables) {
1210
  $out = '';
1211
  $identificationKey = $variables['identificationKey'];
1212
  $doLinkToKeyPage = $variables['doLinkToKeyPage'];
1213
  $showIdentificationKeyTitle = $variables['showIdentificationKeyTitle'];
1214
  $parentRenderPath = RenderHints::getRenderPath();
1215
  RenderHints::pushToRenderStack("IdentificationKey");
1216

    
1217
  if ($showIdentificationKeyTitle) {
1218
    if ($doLinkToKeyPage) {
1219
      $out = l($identificationKey->titleCache, path_to_key($identificationKey->class, $identificationKey->uuid));
1220
    }
1221
    else {
1222
      $out = $identificationKey->titleCache;
1223
    }
1224
  }
1225
  if (isset($identificationKey->sources) && is_array($identificationKey->sources)) {
1226
    // order and display sources.
1227
    $sources = oder_sources($identificationKey->sources, TRUE);
1228
    $out .= '<div class="sources">';
1229
    $out .=  implode('', $sources);
1230
    $out .= '</div>';
1231
  }
1232
  // Display annotations.
1233
  $out .= theme('cdm_annotations', array('annotations' => cdm_ws_getAnnotationsFor($identificationKey), 'enclosingTag' => 'div'));
1234
  RenderHints::popFromRenderStack();
1235
  return $out;
1236
}
1237

    
1238
/**
1239
 * @todo Please document this function.
1240
 * @see http://drupal.org/node/1354
1241
 */
1242
function theme_cdm_polytomousKey($variables) {
1243
  $polytomousKey = $variables['polytomousKey'];
1244

    
1245
  // TODO settings needed.
1246
  // @see http://en.wikipedia.org/wiki/Single_access_key#Presentation_styles
1247
  // @see http://dev.e-taxonomy.eu/trac/ticket/2152
1248
  $keyStyle = "linkedStyle";
1249

    
1250
  RenderHints::pushToRenderStack("polytomousKey");
1251
  // Key nodes in linked style.
1252
  $out = '<table class="polytomousKey polytomousKey_' . $keyStyle . '">';
1253
  $out .= theme('cdm_polytomousKey_' . $keyStyle . '_subgraph', array('polytomousKeyNode' => $polytomousKey->root));
1254
  $out .= '</table>';
1255
  RenderHints::popFromRenderStack();
1256
  return $out;
1257
}
1258

    
1259
/**
1260
 * @todo Please document this function.
1261
 * @see http://drupal.org/node/1354
1262
 */
1263
function theme_cdm_polytomousKey_linkedStyle_subgraph($variables) {
1264
  $polytomousKeyNode = $variables['polytomousKeyNode'];
1265
  static $statementCountCharacter = '\'';
1266
  $out = "";
1267

    
1268
  if (is_array($polytomousKeyNode->children)) {
1269
    $childIndex = 0;
1270

    
1271
    // Render edges of the current node.
1272
    foreach ($polytomousKeyNode->children as &$child) {
1273

    
1274
      if (!isset($child->statement) && isset($child->taxon->uuid)) {
1275
        // Skip node with empty statements (see below for explanation: "Special
1276
        // case").
1277
        // this skipping here happens always in the next deeper level of iteration
1278
        // the check below is node on the level above
1279
        continue;
1280
      }
1281

    
1282
      /*
1283
       * Special case: Child nodes with empty statements but taxa as leaf are to
1284
       * treated as if all those taxa where direct children of the source node.
1285
       */
1286
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
1287
      $islinkToTaxon = isset($child->taxon->uuid);
1288
      $islinkToSubKey = isset($child->subkey->uuid);
1289
      $islinkToOtherNode = isset($child->otherNode);
1290
      // Either NULL or 0.
1291
      $islinkToNode = $child->nodeNumber && !$islinkToManyTaxa && !$islinkToOtherNode;
1292
      $hasQuestion = !empty($polytomousKeyNode->question->label_l10n);
1293
      $hasFeature = isset($polytomousKeyNode->feature);
1294

    
1295
      // $indentEdge = $hasQuestion && $childIndex > 0;
1296
      // Question.
1297
      if ($hasQuestion && $childIndex == 0) {
1298
        // Place question, as extra table row.
1299
        $out .= '<tr class="question new_section">';
1300
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber) . "</td>";
1301
        $out .= '<td class="question">' . $polytomousKeyNode->question->label_l10n . '</td>';
1302
        $out .= '</tr>';
1303
      }
1304

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

    
1307
      if ($hasQuestion) {
1308
        $out .= '<td class="nodeNumber"></td>';
1309
      }
1310
      else {
1311
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childIndex, $statementCountCharacter)) . "</td>";
1312
      }
1313

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

    
1316
      // Feature.
1317
      if ($hasFeature) {
1318
        $out .= $polytomousKeyNode->feature->representation_L10n . ": ";
1319
      }
1320

    
1321
      // Statement.
1322
      $out .= $child->statement->label_l10n;
1323

    
1324
      // --- Links to nodes taxa and subkeys.
1325
      $out .= '<div class="nodeLink">';
1326

    
1327
      // Link to a PolytomousKeyNode.
1328
      if ($islinkToNode) {
1329
        $out .= '<div class="nodeLinkToNode">';
1330
        if (is_object($child->modifyingText)) {
1331
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1332
        }
1333
        $out .= l($child->nodeNumber, request_path(), array(
1334
          'attributes' => NULL,
1335
          'query' => NULL,
1336
          'fragment' => $child->uuid,
1337
        )) . '</div>';
1338
      }
1339

    
1340
      // Link to a PolytomousKeyNode.
1341
      if ($islinkToOtherNode) {
1342
        $out .= '<div class="nodeLinkToOtherNode">';
1343
        if (is_object($child->modifyingText)) {
1344
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1345
        }
1346
        $out .= l($child->otherNode->nodeNumber, $_REQUEST["q"], array(
1347
          'attributes' => NULL,
1348
          'query' => NULL,
1349
          'fragment' => $child->otherNode->uuid,
1350
        )) . '</div>';
1351
      }
1352

    
1353
      // Link to one or many taxa.
1354
      if ($islinkToTaxon || $islinkToManyTaxa) {
1355

    
1356
        if ($islinkToManyTaxa) {
1357
          $taxonChildren = $child->children;
1358
        }
1359
        else {
1360
          $taxonChildren = array(
1361
            $child,
1362
          );
1363
        }
1364

    
1365
        foreach ($taxonChildren as $taxonChild) {
1366
          // TODO many taxa $child->children->taxon.
1367
          $out .= '<div class="nodeLinkToTaxon">';
1368
          if (is_object($taxonChild->modifyingText)) {
1369
            $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $taxonChild->modifyingText));
1370
          }
1371
          $out .= theme("cdm_taxonName", array('taxonName' => $taxonChild->taxon->name, 'nameLink' => url(path_to_taxon($taxonChild->taxon->uuid))));
1372
          $out .= '</div>';
1373
        }
1374

    
1375
        // Link to a subkey.
1376
        if ($islinkToSubKey) {
1377
          $out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', array('identificationKey' => $child->subkey)) . '</div>';
1378
        }
1379
      }
1380

    
1381
      $out .= '</div>'; // End node link.
1382
      $out .= '</td>'; // End edge.
1383
      $out .= '</tr>';
1384

    
1385
      $childIndex++;
1386
    }
1387

    
1388
    // Recurse into child nodes.
1389
    foreach ($polytomousKeyNode->children as &$child) {
1390
      $out .= theme('cdm_polytomousKey_linkedStyle_subgraph', array('polytomousKeyNode' => $child));
1391
    }
1392
  }
1393

    
1394
  return $out;
1395
}
1396

    
1397
/**
1398
 * @todo Please document this function.
1399
 * @see http://drupal.org/node/1354
1400
 */
1401
function theme_cdm_poytomousKeyNode_modifyingText($variables) {
1402
  $out = '';
1403
  $modifyingText = $variables['modifyingText'];
1404
  if (is_object($modifyingText)) {
1405
    $i = 0;
1406
    foreach (get_object_vars($modifyingText) as $lang => $languageString) {
1407
      $out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">' . $languageString->text . '</span> ';
1408
    }
1409
  }
1410
  return $out;
1411
}
1412

    
1413
/**
1414
 * Returns HTML for a list of a specific type of IdentificationKeys.
1415
 *
1416
 * The list can be restricteded by a taxon.
1417
 *
1418
 * @param array $variables
1419
 *   An associative array containing:
1420
 *   - type: The simple name of the cdm class implementing the interface
1421
 *     IdentificationKey, valid values are:
1422
 *     PolytomousKey, MediaKey, MultiAccessKey
1423
 *   - taxonUuid: If given, this parameter restrict the listed keys to those
1424
 *     which have the taxon identified be this uuid in scope.
1425
 *
1426
 * @ingroup themeable
1427
 */
1428
function theme_cdm_list_IdentificationKeys($variables) {
1429
  $type = $variables['type'];
1430
  $taxonUuid = $variables['taxonUuid'];
1431
  $keyList = _list_IdentificationKeys($type, $taxonUuid);
1432
  if (!$keyList || count($keyList) == 0) {
1433
    return;
1434
  }
1435

    
1436
  RenderHints::pushToRenderStack('list_IdentificationKeys');
1437
  $out = '<ul>';
1438
  foreach ($keyList as $key) {
1439
    $out .= '<li>';
1440
    $out .= theme('cdm_IdentificationKey', array('identificationKey' => $key));
1441
    $out .= '</li>';
1442
  }
1443
  $out .= '</ul>';
1444
  $out .= theme("cdm_annotation_footnotes", array('footnoteListKey' => RenderHints::getRenderPath()));
1445
  RenderHints::popFromRenderStack();
1446

    
1447
  return $out;
1448
}
1449

    
1450
/**
1451
 * @todo Please document this function.
1452
 * @see http://drupal.org/node/1354
1453
 */
1454
function theme_cdm_block_IdentificationKeys($variables) {
1455
  $taxonUuid = $variables['taxonUuid'];
1456
  static $types = array(
1457
    "PolytomousKey" => "Polytomous",
1458
    "MediaKey" => "Media",
1459
    "MultiAccessKey" => "Multiaccess",
1460
  );
1461
  RenderHints::pushToRenderStack('block_IdentificationKeys');
1462
  $out = '';
1463
  foreach ($types as $type => $label) {
1464
    $keylist = theme('cdm_list_IdentificationKeys', array('type' => $type, 'taxonUuid' => $taxonUuid));
1465
    if (!$keylist) {
1466
      continue;
1467
    }
1468
    $out .= '<div class="' . $type . '">';
1469
    $out .= '<h3>' . t($label) . "</h3>";
1470
    $out .= $keylist;
1471
    $out .= '</div>';
1472
  }
1473
  RenderHints::popFromRenderStack();
1474
  return $out;
1475
}
1476

    
1477
/**
1478
 * This theming function formats the use description and use record list for
1479
 * these descriptions.
1480
 *
1481
 * @see http://drupal.org/node/1354
1482
 */
1483
function theme_cdm_UseDescription($variables) {
1484
  $descriptions = $variables['description'];
1485
  $taxonUuid = $variables['taxonUuid'];
1486
  $out = '<div id="content"><ul id="Description" class ="description">';
1487
  if ($descriptions == NULL) {
1488
    return;
1489
  }
1490
  $descriptionSynonyms = '';
1491
  $descriptionOut = '';
1492
  $synonymOut = '';
1493
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
1494

    
1495
  foreach ($descriptions as $description) {
1496
    $useSummary = '';
1497
    foreach ($description->elements as $element) {
1498

    
1499
      if ($element->feature->uuid == UUID_USE && !(strlen($useSummary) > 0)) {
1500
        $useSummary = $element->multilanguageText_L10n->text;
1501
      }
1502
    }
1503
    // uses will be ordered by source
1504
    foreach ($description->sources as $source) {
1505
      $is_about_current_taxon = FALSE;
1506
      $originalTaxonUsedInSource = NULL;
1507
      $originalTaxonPager = NULL;
1508
      if ($source->originalNameString) {
1509
        $request_params = array();
1510
        $request_params['query'] = $source->originalNameString;
1511
        $request_params['matchMode'] = "EXACT";
1512
        $originalTaxonPager = cdm_ws_get(CDM_WS_PORTAL_NAME_FINDBYNAME, NULL, queryString($request_params));
1513
        if ($originalTaxonPager->count > 0) {
1514
          $originalTaxonUsedInSource = $originalTaxonPager->records[0];
1515
        }
1516
        else {
1517
          $originalTaxonUsedInSource = $currentTaxon->name;
1518
        }
1519
      }
1520
      else {
1521
        $originalTaxonUsedInSource = $currentTaxon->name;
1522
      }
1523

    
1524
      $is_about_current_taxon = $currentTaxon->name->uuid == $originalTaxonUsedInSource->uuid;
1525

    
1526
      if (!$is_about_current_taxon) {
1527
        $descriptionOut .= '<li class="descriptionText DescriptionElement">';
1528
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1529
          'absolute' => TRUE,
1530
          'html' => TRUE,
1531
        ));
1532
        $descriptionOut .= $name_used_in_source_link_to_show_use . ': ';
1533
        $descriptionOut .= $useSummary;
1534
        foreach ($description->sources as $source) {
1535
          $descriptionOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1536
        }
1537
        $hasUseRecords = FALSE;
1538
        $descriptionUseRecordOut = '<div id=useRecords><table><th>Use Category</th><th>Use Sub Category</th><th>Plant Part</th><th>Human Group</th><th>Ethnic Group</th><th>Country</th>';
1539
        foreach ($description->elements as $descriptionElement) {
1540
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1541
            $hasUseRecords = TRUE;
1542
            // FIXME localization hardcoded to English
1543
            $useRecordTags = explode(';', $descriptionElement->modifyingText->English->text);
1544
            $descriptionUseRecordOut .= '<tr>';
1545
            $descriptionUseRecordOut .= '<td>' . $useRecordTags[0] . '</td>' . '<td>' . $useRecordTags[1] . '</td>' . '<td>' . $useRecordTags[3] . '</td>' . '<td>' . $useRecordTags[4] . '</td>' . '<td>' . $useRecordTags[5] . '</td>' . '<td>' . $useRecordTags[2] . '</td>';
1546
            $descriptionUseRecordOut .= '</tr>';
1547
          }
1548
        }
1549
        $descriptionUseRecordOut .= '</table></div>';
1550
        if ($hasUseRecords) {
1551
          $descriptionOut .= $descriptionUseRecordOut . '</li>';
1552
        }
1553
      }
1554
      else {
1555
        // TODO +/- duplicate of above, unify this code
1556
        $synonymOut .= '<li class="descriptionText DescriptionElement">';
1557
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1558
          'absolute' => TRUE,
1559
          'html' => TRUE,
1560
        ));
1561

    
1562
        $synonymOut .= $name_used_in_source_link_to_show_use . ': ';
1563
        $synonymOut .= $useSummary;
1564
        foreach ($description->sources as $source) {
1565
          $synonymOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1566
        }
1567

    
1568
        $hasUseRecords = FALSE;
1569
        $useRecordTableOut = '<div id=useRecords><table><th>Use Category</th><th>Use Sub Category</th><th>Plant Part</th><th>Human Group</th><th>Ethnic Group</th><th>Country</th>';
1570
        foreach ($description->elements as $descriptionElement) {
1571
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1572
            $hasUseRecords = TRUE;
1573
            $useRecordTags = explode(';', $descriptionElement->modifyingText->English->text);
1574
            $useRecordTableOut .= '<tr>';
1575
            $useRecordTableOut .= '<td>' . $useRecordTags[0] . '</td>' . '<td>' . $useRecordTags[1] . '</td>' . '<td>' . $useRecordTags[3] . '</td>' . '<td>' . $useRecordTags[4] . '</td>' . '<td>' . $useRecordTags[5] . '</td>' . '<td>' . $useRecordTags[2] . '</td>';
1576
            $useRecordTableOut .= '</tr>';
1577
          }
1578
        }
1579
        $useRecordTableOut .= '</table></div>';
1580
        if ($hasUseRecords) {
1581
          $synonymOut .= $useRecordTableOut . '</li>';
1582
        }
1583
      }
1584

    
1585
      // }
1586
    }
1587
  }
1588
  $out .= $descriptionOut . $synonymOut;
1589
  $out .= "</ul></div>";
1590
  return $out;
1591
}
1592

    
1593
// The Uses theming function here will handle the display of the
1594
// Uses Descriptions.
1595
// Comment @WA: $pageSize is not used.
1596
// function theme_cdm_block_Uses ($taxonUuid = NULL, $pageSize = NULL {
1597
/**
1598
 * @todo Please document this function.
1599
 * @see http://drupal.org/node/1354
1600
 */
1601
function theme_cdm_block_Uses($variables) {
1602
  $taxonUuid = $variables['taxonUuid'];
1603
  RenderHints::pushToRenderStack('block_Uses');
1604

    
1605
  if ($taxonUuid == NULL) {
1606
    return;
1607
  }
1608
  $out = '';
1609
  $markerTypes = array();
1610
  $markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
1611
  $useDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxonUuid, queryString($markerTypes));
1612
  if (!empty($useDescriptions)) {
1613
    // FIXME use theme_block instaed of hardcoding the block html here !!!!
1614
    $out .= '<div id="block-cdm_dataportal-feature-description" class="clear-block block block-cdm_dataportal-feature"><H2><a name="userecords"> </a> Uses </H2>';
1615
    $formatUseDescriptions = theme('cdm_UseDescription', array('description' => $useDescriptions, 'taxonUuid' => $taxonUuid));
1616

    
1617
    $out .= $formatUseDescriptions;
1618
    $out .= "</div>";
1619
  }
1620

    
1621
  return $out;
1622
}
Add picture from clipboard (Maximum size: 40 MB)