Project

General

Profile

« Previous | Next » 

Revision b7a20282

Added by Andreas Kohlbecker almost 8 years ago

refactoring: reducing amount of theme functions, functions moved into includes/

View differences:

modules/cdm_dataportal/theme/cdm_dataportal.taxon.theme
13 13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14 14
 */
15 15

  
16
/**
17
 * Returns HTML for misapplied names and invalid designations.
18
 *
19
 * Both relation types are currently treated the same!
20
 *
21
 * @param array $variables
22
 *   An associative array containing:
23
 *   - taxonRelationships
24
 *   - focusedTaxon
25
 *
26
 * @ingroup themeable
27
 *
28
 * @return string
29
 *    the rendered html
30
 */
31
function theme_cdm_taxonRelationships($variables) {
32
  $taxonRelationships = $variables['taxonRelationships'];
33
  $focusedTaxon = $variables['focusedTaxon'];
34
  if (!$taxonRelationships) {
35
    return null;
36
  }
37

  
38
  RenderHints::pushToRenderStack('taxonRelationships');
39
  $footnoteListKey = 'taxonRelationships';
40
  RenderHints::setFootnoteListKey($footnoteListKey);
41

  
42
  $misapplied = array();
43
  $joinedAuthorTeams = array();
44

  
45
  $taxon_relationship_types = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
46

  
47
  // Aggregate misapplied names having the same fullname:
48
  foreach ($taxonRelationships as $taxonRelation) {
49

  
50
    if (in_array($taxonRelation->type->uuid, $taxon_relationship_types)) {
51

  
52
      if ($taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR) {
53

  
54
        $name = $taxonRelation->fromTaxon->name->titleCache;
55

  
56
        if(isset($taxonRelation->fromTaxon->sec)) {
57
          // taxa not always are have a sec reference (e.g. doubtful taxa)
58
          $authorteam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $taxonRelation->fromTaxon->sec->uuid);
59
          $authorteam = $authorteam->titleCache;
60
        }
61

  
62
        if (!isset($misapplied[$name])) {
63
          // Render the first name found as representative for all others.
64
          $misapplied[$name]['out'] = cdm_related_taxon($taxonRelation->fromTaxon, UUID_MISAPPLIED_NAME_FOR);
65
        }
66
        else {
67
          // We need to add the anchors for all of the other mispplied names not
68
          // being rendered explicitly.
69
          $misapplied[$name]['out'] = uuid_anchor($taxonRelation->fromTaxon->uuid, $misapplied[$name]['out']);
70
        }
71

  
72
        // Collect all authors for this fullname.
73
        if (isset($authorteam)) {
74
          $misapplied[$name]['authorteam'][$authorteam] = '';
75
          $joinedAuthorTeams[$authorteam] = 'sensu ' . theme('cdm_reference', array('reference' => $taxonRelation->fromTaxon->sec));
76
        }
77
      }
78
      else {
79
        // All relationsship types but misapplied_name_for
80
        // invalid_designation_for.
81
        $taxon_relationships_lines[] = cdm_taxonRelationship($taxonRelation, TRUE, _is_invers_taxonRelationship($taxonRelation, $focusedTaxon));
82
      }
83
    }
84
  }
85

  
86
  // Sort the joinedAuthorTeams and create footnotes and footnotekeys.
87
  ksort($joinedAuthorTeams);
88
  foreach ($joinedAuthorTeams as $authorteam => $sensuCitation) {
89
    $footnoteKey = FootnoteManager::addNewFootnote($footnoteListKey, $sensuCitation);
90
    $joinedAuthorTeams[$authorteam] = '<span class="sensu">sensu '
91
      . $authorteam
92
      . theme('cdm_footnote_key', array('footnoteKey' => $footnoteKey))
93
      . '</span>';
94
  }
95

  
96
  // ---- Generate output ---- //
97

  
98
  $out = '<div class="taxon-relationships">';
99
  if (is_array($misapplied) && count($misapplied) > 0) {
100
    $out .= '<ul class="misapplied">';
101
    foreach ($misapplied as $misapplied_name) {
102

  
103
      $out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name['out'] . ' </span>';
104

  
105
      if (isset($misapplied_name['authorteam'])) {
106
        // Fill authors with the renderedFootnoteKey and sorting 'em.
107
        foreach ($misapplied_name['authorteam'] as $authorteam => &$renderedFootnoteKey) {
108
          $renderedFootnoteKey = $joinedAuthorTeams[$authorteam];
109
        }
110
        ksort($misapplied_name['authorteam']);
111
        $out .= join('; ', $misapplied_name['authorteam']);
112
      }
113
      $out .= '</li>';
114
    }
115
    $out .= '</ul>';
116
  }
117

  
118
  if (isset($taxon_relationships_lines) && is_array($taxon_relationships_lines) && count($taxon_relationships_lines) > 0) {
119
    $out .= '<ul class="taxonRelationships">';
120
    foreach ($taxon_relationships_lines as $taxon_relationship_line) {
121
      $out .= '<li class="synonym">' . $taxon_relationship_line . '</li>';
122
    }
123
    $out .= '</ul>';
124
  }
125

  
126
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => $footnoteListKey, 'enclosingTag' => 'li'));
127
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnoteListKey, 'enclosingTag' => 'li'));
128

  
129
// AK: why splitting footnotes at the sensu string ??? this is weired and hacky
130
//     TODO remove below dead code
131
//   $tr_footnotes_exploded = explode('sensu', $tr_footnotes);
132
//   $tr_footnotes_aux = '';
133
//   foreach ($tr_footnotes_exploded as $element) {
134
//     $tr_footnotes_aux .= $element;
135
//   }
136

  
137
  $out .= '<ul class="footnotes">' . $footnotes . '</ul>';
138

  
139
  $out .= '</div>';
140

  
141
  RenderHints::popFromRenderStack();
142
  return $out;
143
}
144

  
145 16
/**
146 17
 * @todo Please document this function.
147 18
 * @see http://drupal.org/node/1354
......
362 233
  return $out;
363 234
}
364 235

  
365
/**
366
 * Renders a representation of the given taxon relationship.
367
 *
368
 * According name relationships are also being rendered.
369
 *
370
 * @param unknown_type $taxonRelationship
371
 * @param boolean $doLinkTaxon
372
 *     whether to create a link to the related taxon
373
 * @param boolean $inverse
374
 *     whether the $taxonRelationship should be treaded as invers relation
375
 *
376
 * @return void|string
377
 */
378
function cdm_taxonRelationship($taxonRelationship, $doLinkTaxon = FALSE, $inverse = FALSE) {
379

  
380
  // Validate object.
381
  if (!(isset($taxonRelationship->toTaxon) && isset($taxonRelationship->fromTaxon) && isset($taxonRelationship->type))) {
382
    return null;
383
  }
384

  
385
  $taxonRelationType = $taxonRelationship->type;
386

  
387
  if ($inverse) {
388
    $toTaxon = $taxonRelationship->fromTaxon;
389
    $relsign = $taxonRelationType->inverseRepresentation_L10n_abbreviatedLabel;
390
    $reltype_representation = $taxonRelationType->inverseRepresentation_L10n;
391
  }
392
  else {
393
    $toTaxon = $taxonRelationship->toTaxon;
394
    $relsign = $taxonRelationType->representation_L10n_abbreviatedLabel;
395
    $reltype_representation = $taxonRelationType->representation_L10n;
396
  }
397

  
398
  return cdm_related_taxon($toTaxon, NULL, $relsign, $reltype_representation, $taxonRelationship->doubtful, $doLinkTaxon);
399
}
400

  
401
/**
402
 * Renders a representation of the given taxon relationship.
403
 *
404
 * According name relationships are also being rendered.
405
 *
406
 * @param $taxon
407
 *  The CDM TaxonBase entity
408
 * @param $reltype_uuid
409
 *  The UUID of the TaxonRelationshipType
410
 * @param $relsign
411
 *  Optional. Can be  used to override the internal decision strategy on finding a suitable icon for the relationship
412
 * @param $reltype_representation
413
 *   Optional: Defines the value for the title attribute of the html element enclosing the relsign
414
 * @param $doubtful
415
 *   TODO
416
 * @param $doLinkTaxon
417
 *   The taxon will be rendered as clickable link when true.
418
 *
419
 * @return string
420
 *   Markup for the taxon relationship.
421
 */
422
function cdm_related_taxon($taxon, $reltype_uuid = NULL, $relsign = NULL, $reltype_representation = NULL, $doubtful=false, $doLinkTaxon = FALSE) {
423
  static $relsign_homo = '≡';
424
  static $relsign_hetero = '=';
425
  static $relsign_invalid = '&ndash;';
426
  static $nom_status_invalid_type_uuids =  array(
427
      UUID_NOMENCLATURALSTATUS_TYPE_INVALID,
428
      UUID_NOMENCLATURALSTATUS_TYPE_NUDUM,
429
      UUID_NOMENCLATURALSTATUS_TYPE_COMBINATIONINVALID,
430
      UUID_NOMENCLATURALSTATUS_TYPE_PROVISIONAL
431
  );
432

  
433
  // 'taxonRelationships';
434
  $footnoteListKey = NULL;
435

  
436
  $skip_tags = array();
437

  
438
  $is_invalid = false;
439

  
440
  if (!$relsign) {
441

  
442
    switch ($reltype_uuid) {
443
      case UUID_HETEROTYPIC_SYNONYM_OF:
444
      case UUID_SYNONYM_OF:
445
        $relsign = $relsign_hetero;
446
        break;
447

  
448
      case UUID_HOMOTYPIC_SYNONYM_OF:
449
        $relsign = $relsign_homo;
450
        break;
451

  
452
      case UUID_MISAPPLIED_NAME_FOR:
453
      case UUID_INVALID_DESIGNATION_FOR:
454
        $skip_tags[] = 'authors';
455
        $is_invalid = true;
456
        $relsign = $relsign_invalid;
457

  
458
        break;
459

  
460
      default:
461
        $relsign = $relsign_invalid;
462
    }
463

  
464
  }
465

  
466
  if($doubtful) {
467
    $relsign = '?' . $relsign;
468
  }
469

  
470
  /*
471
  Names with status invalid or nudum are to be displayed with the
472
  $relsign_invalid, these names appear at the end of all names in their
473
  homotypic group (ordered correctly by the java cdm_lib).
474
  */
475
  if (isset($taxon->name->status) && is_array($taxon->name->status)) {
476
    foreach ($taxon->name->status as $status) {
477
      if (in_array($status->type->uuid , $nom_status_invalid_type_uuids)) {
478
        $relsign = $relsign_invalid;
479
        break;
480
      }
481
    }
482
  }
483

  
484
  // Now rendering starts ..
485
  RenderHints::pushToRenderStack('related_taxon');
486

  
487
  if (isset($taxon->name->nomenclaturalReference)) {
488
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
489
  }
490
  $taxonUri = '';
491
  if ($doLinkTaxon) {
492
    $taxonUri = url(path_to_taxon($taxon->uuid, "synonymy"));
493
  }
494
  // Printing the taxonName and the handling the special case of annotations.
495
  if (!isset($referenceUri)) {
496
    $referenceUri = FALSE;
497
  }
498
  $out_taxon_part = render_taxon_or_name($taxon, $taxonUri, $referenceUri, TRUE, FALSE, $skip_tags, $is_invalid);
499
  $taxon_footnotes = theme('cdm_annotations_as_footnotekeys',
500
       array('cdmBase_list' => array(
501
         $taxon->name,
502
         $taxon,
503
       ),
504
       'footnote_list_key' => $footnoteListKey)
505
  );
506

  
507
  $homonyms = cdm_name_relationships_of($taxon);
508

  
509
  $out = '<span class="relation_sign" title="' . $reltype_representation . '">' . $relsign . '</span>'
510
      . $out_taxon_part . $taxon_footnotes . ' '  . $homonyms;
511

  
512
  $out = uuid_anchor($taxon->uuid, $out);
513

  
514
  RenderHints::popFromRenderStack();
515

  
516
  return $out;
517
}
518

  
519

  
520 236
  /**
521 237
 * @todo document this function.
522 238
 */

Also available in: Unified diff