Project

General

Profile

Download (3.14 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/**
4
 * Compose a description as a table of Feature<->State
5
 *
6
 * @param $description_uuid
7
 *
8
 * @return array
9
 *    The drupal render array for the page
10
 *
11
 * @ingroup compose
12
 */
13
function compose_agent($agent, $enclosing_tag) {
14

    
15

    
16
  $names_and_lifespan = $agent->titleCache;
17

    
18
  if(isset($agent->nomenclaturalTitle) && $agent->nomenclaturalTitle != $agent->titleCache){
19
    $names_and_lifespan .=  ' [' . $agent->nomenclaturalTitle . ']';
20
  }
21

    
22
  $visible_extensions_sorted = visible_extensions_sorted($agent);
23
  // FIXME:-------------- "Life span" as Extension -------------
24
  $lifespan_extension = null;
25
  // 7d1a269b-9bdd-44eb-beba-2f8acee941af is the phycobank specific ext type for "Life span" which will become obsolete!!!!
26
  if(isset($visible_extensions_sorted['7d1a269b-9bdd-44eb-beba-2f8acee941af'])){
27
    // as first element after the titleCache
28
    $lifespan_extension = $visible_extensions_sorted['7d1a269b-9bdd-44eb-beba-2f8acee941af'][0]->value;
29
    unset($visible_extensions_sorted['7d1a269b-9bdd-44eb-beba-2f8acee941af']);
30
  }
31
  // ------------------------------------
32
  if(!$lifespan_extension && isset($agent->lifespan)){
33
    $names_and_lifespan .= ', ' . timePeriodToString($agent->lifespan);
34
  } else {
35
    $names_and_lifespan .= ", " . $lifespan_extension;
36
  }
37

    
38
  $names_and_lifespan_markup = '<div class="names-and-lifespan">' . $names_and_lifespan . '</div> ';
39

    
40
  $name_details = [];
41
  $name_details_markup = '';
42
  if(isset($agent->familyName) || isset($agent->givenName)){
43
    if(isset($agent->familyName)){
44
      $name_details[] = '<span class="label">' . t('Family name') . ': </span>'. $agent->familyName;
45
    }
46
    if(isset($agent->givenName)){
47
      $name_details[] = '<span class="label">' . t('Given name') . ': </span>'. $agent->givenName;
48
    }
49
    $name_details_markup = ' <div class="name-details">(' .  join(', ', $name_details) .')</div> ';
50
  }
51

    
52
  // extensions
53
  $extensions = [];
54
  foreach ($visible_extensions_sorted as $type_uuid => $exts){
55
    foreach ($exts as $ext){
56
      if($ext->value){
57
        $extensions[] = '<span class="label">' . $ext->type->representation_L10n . ': </span>'. $ext->value;
58
      }
59
    }
60
  }
61
  $extensions_markup = '';
62
  if(count($extensions) > 0 ){
63
    $extensions_markup = '<div class="extensions">' . join(', ', $extensions) . '</div>';
64
  }
65

    
66
  // IDs
67
  $identifiers_markup = '';
68
  $identifiers_render_array = [];
69
  if(isset($agent->orcid)){
70
    $orcid_id = number_format($agent->orcid->digitsOnly, 0, '.', '-');
71
    $identifiers_render_array[] = markup_to_render_array(l('https://orcid.org/' . $orcid_id, 'https://orcid.org/' . $orcid_id) . ' ');
72
  }
73
  if(isset($agent->identifiers)){
74
    $identifiers_render_array = array_merge($identifiers_render_array, compose_identifiers($agent->identifiers));
75
  }
76
  if(count($identifiers_render_array) > 0){
77
    $identifiers_markup = '<div class="identifier">' . drupal_render($identifiers_render_array) . '</div>';
78
  }
79

    
80

    
81
  $render_array = markup_to_render_array($names_and_lifespan_markup . $name_details_markup  . $extensions_markup . $identifiers_markup, null, '<' . $enclosing_tag . ' class="' . html_class_attribute_ref($agent) . '">', '</' . $enclosing_tag . '>');
82

    
83
  return $render_array;
84
}
(1-1/14)