Project

General

Profile

Revision 83dc60b9

ID83dc60b9d288d64fe69247a44814e50887f9dd8f
Parent a01ad6fe
Child 2978b0c8

Added by Andreas Kohlbecker over 3 years ago

ref #7658 adapting cdm_taxonRelationships() to new taxon relationship DTO webservice
- test case
- extending tagged text functions
- adapting misapplied name redering

View differences:

modules/cdm_dataportal/includes/taxon.inc
50 50
 */
51 51
function cdm_taxonRelationships($taxonRelationshipsDTO, $focusedTaxon){
52 52

  
53
  static $NULL_AUTHORTEAM = 'NULL_AUTHORTEAM';
54

  
55 53
  if (!$taxonRelationshipsDTO || $taxonRelationshipsDTO->size < 1) {
56 54
    return null;
57 55
  }
58 56

  
59 57
  RenderHints::pushToRenderStack('taxon_relationships');
60
  $footnoteListKey = 'taxon_relationships';
61
  RenderHints::setFootnoteListKey($footnoteListKey);
58
  $footnote_list_key = 'taxon_relationships';
59
  RenderHints::setFootnoteListKey($footnote_list_key);
62 60

  
63 61
  $misapplied = array();
64
  $joinedAuthorTeams = array();
62
  $joined_sensu_refs = array();
65 63

  
66 64
  $taxon_relationship_types = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
67 65

  
68 66
  // Aggregate misapplied names having the same fullname:
69 67
  //  - deduplicate misapplied names, so that the same name it not shown multiple times in case it
70 68
  //    the duplicates only have different sensu references/author teams (see #5647)
71
  //  - show the author team as sec reference
72
  //  - show the according reference as footnote to this author team
73
  //  - if the sec reference has no author team it should show instead the title cache
69
  //  - show only the author team as short citation for the sec reference
70
  //  - show the according reference as footnote to this short citation
74 71
  //
75 72
  // Example:
76 73
  // "Xenoxylum foobar" sensu Grumbach¹; sensu Lem²
......
85 82

  
86 83
          RenderHints::pushToRenderStack('misapplied_name_for'); // TODO the render path string should in future come from $taxonRelation->type->...
87 84

  
88
          $name = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('name')));
89

  
90
          $sensu_citation_footnote_str = null;
91

  
92
          if (!isset($misapplied[$name])) {
93
            // Render the first name found as representative for all others.
94

  
95
            //###OLD: $misapplied[$name]['out'] = cdm_related_taxon($taxon_relation->fromTaxon, UUID_MISAPPLIED_NAME_FOR);
96
            $name_tagged_text = array();
97
            $secref_tagged_text = null;
98
            foreach($taxon_relation->taggedText as $tt){
99
              if($tt->type !== 'secReference' && !$secref_tagged_text){
100
                $name_tagged_text[] = $tt;
101
              } else {
102
                if(!$secref_tagged_text){
103
                  // initialize $secref_tagged_text
104
                  $secref_tagged_text = array();
105
                  $secref_tagged_text[] = array_pop($name_tagged_text); // remmove last elemetn wich is a separator in this case
106
                }
107
                $secref_tagged_text[] = $tt;
85
          // using name tags + author as full name key
86
          $full_name_key = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('name', 'authors')));
87

  
88
          // Render the first name found as representative for all others.
89
          //###OLD: $misapplied[$name]['out'] = cdm_related_taxon($taxon_relation->fromTaxon, UUID_MISAPPLIED_NAME_FOR);
90
          $sensu_tagged_text = tagged_text_extract_secref($taxon_relation->taggedText, "secReference", true);
91
          $relsec_tagged_text = tagged_text_extract_secref($taxon_relation->taggedText, "relSecReference", true);
92

  
93
          if (isset($sensu_tagged_text[1])) {
94
            array_shift($sensu_tagged_text); // remove first element which contains the "sensu", this will be added later in this code
95
            $sensu_citation_short_markup = cdm_tagged_text_to_markup($sensu_tagged_text);
96
            $sensu_citation_short = cdm_tagged_text_to_string($sensu_tagged_text);
97
            $sensu_uuid = $sensu_tagged_text[0]->entityReference->uuid;
98
            $misapplied[$full_name_key]['sensu_uuids'][] = $sensu_uuid;
99
            if (!isset($joined_sensu_refs[$sensu_uuid])) {
100
              $joined_sensu_refs[$sensu_uuid] = array(
101
                'short_citation' => $sensu_citation_short,
102
                'markup' => $sensu_citation_short_markup // to be expanded later as short_citation + footnote key
103
              );
104
            }
105

  
106
            if (isset($relsec_tagged_text[1])) {
107
              array_shift($relsec_tagged_text); // remove first element which contains the "err. sec", this will be added later in this code
108
              $relsec_citation_short_markup = cdm_tagged_text_to_markup($relsec_tagged_text);
109
              $relsec_citation_short = cdm_tagged_text_to_string($relsec_tagged_text);
110
              $relsec_uuid = $relsec_tagged_text[0]->entityReference->uuid;
111
              $misapplied[$full_name_key]['relsec_uuids'][] = $relsec_uuid;
112
              if (!isset($joined_sensu_refs[$relsec_uuid])) {
113
                $joined_sensu_refs[$relsec_uuid] = array(
114
                  'short_citation' => $relsec_citation_short,
115
                  'markup' => $relsec_citation_short_markup // to be expanded later as short_citation + footnote key
116
                );
108 117
              }
109 118
            }
110
            $misapplied[$name]['out'] = cdm_tagged_text_to_markup($name_tagged_text);
111
          } else {
112
            // We need to add the anchors for all of the other misapplied names not
113
            // being rendered explicitly.
114
            $misapplied[$name]['out'] = uuid_anchor($taxon_relation->taxonUuid, $misapplied[$name]['out']);
115
          }
116 119

  
117
          // Collect all authors for this fullname.
118
          if (isset($authorteam_str) && $authorteam_str != $NULL_AUTHORTEAM) {
119
            // prepare entry for the footnote key of the sensu citation footnote
120
            $misapplied[$name]['authorteam'][$authorteam_str] = '';
121
            // map sensu citation footnote to the authorteam string
122
            $joinedAuthorTeams[$authorteam_str] = $sensu_citation_footnote_str;
120
            if (!isset($misapplied[$full_name_key]['out'])) {
121
              $misapplied[$full_name_key]['out'] = cdm_tagged_text_to_markup($taxon_relation->taggedText);
122
            } else {
123
              // We need to add the anchors for all of the other misapplied names not
124
              // being rendered explicitly.
125
              $misapplied[$full_name_key]['out'] = uuid_anchor($taxon_relation->taxonUuid, $misapplied[$full_name_key]['out']);
126
            }
127
          } else {
128
            RenderHints::pushToRenderStack('other_taxon_relationship');
129
            // All relationship types except misapplied_name_for and invalid_designation_for.
130
            $taxon_relationships_lines[] = cdm_taxonRelationship($taxon_relation, TRUE, _is_invers_taxonRelationship($taxon_relation, $focusedTaxon));
123 131
          }
124 132

  
125
        } else {
126
          RenderHints::pushToRenderStack('other_taxon_relationship');
127
          // All relationship types except misapplied_name_for and invalid_designation_for.
128
          $taxon_relationships_lines[] = cdm_taxonRelationship($taxon_relation, TRUE, _is_invers_taxonRelationship($taxon_relation, $focusedTaxon));
133
          RenderHints::popFromRenderStack();
129 134
        }
130

  
131
        RenderHints::popFromRenderStack();
132 135
      }
133
    }
136
    } // END loop over $taxonRelationshipsDTO->relations
134 137
  }
135 138

  
136
  // Sort the joinedAuthorTeams and create footnotes and footnotekeys.
137
  ksort($joinedAuthorTeams);
138
  $author_team_cnt = 0;
139
  foreach ($joinedAuthorTeams as $authorteam_str => $sensu_citation) {
140
    $footnoteKey = '';
141
    if(!empty($sensu_citation)) {
142
      $footnoteKey = FootnoteManager::addNewFootnote($footnoteListKey, $sensu_citation);
143
      $footnoteKey = theme('cdm_footnote_key', array('footnoteKey' => $footnoteKey));
139
  // Sort the $joined_sensu_refs and create footnotes and footnote keys.
140
  uasort($joined_sensu_refs, function($a, $b) {
141
    if ($a['short_citation'] == $b['short_citation']) {
142
      return 0;
144 143
    }
145
    $sensu = '';
146
    if($authorteam_str != $NULL_AUTHORTEAM){
147
      $sensu = ++$author_team_cnt == 0 ? '' : 'sensu ' . $authorteam_str;
144
    return ($a['short_citation'] < $b['short_citation']) ? -1 : 1;
145
  });
146

  
147

  
148
  foreach ($joined_sensu_refs as $sensu_uuid => $sensu_strings) {
149
    $footnote_key = '';
150
    if(!empty($sensu_strings)) {
151
      $sensu_reference = cdm_ws_get(CDM_WS_REFERENCE, $sensu_uuid);
152
      if(!$sensu_reference){
153
        drupal_set_message("Problem fetching sensu reference with uuid " . $sensu_uuid, 'error');
154
      }
155
      $footnote_key = FootnoteManager::addNewFootnote($footnote_list_key, $sensu_reference->titleCache);
156
      $footnote_key = theme('cdm_footnote_key', array('footnoteKey' => $footnote_key));
148 157
    }
149
    $joinedAuthorTeams[$authorteam_str] = '<span class="sensu">' . $sensu . $footnoteKey .'</span>';
158
    $joined_sensu_refs[$sensu_uuid]['markup'] = '<span class="sensu">' . $sensu_strings['markup'] . $footnote_key . '</span>';
150 159
  }
151 160

  
152 161
  // ---- Generate output ---- //
153

  
154 162
  $out = '<div class="taxon-relationships">';
155 163
  if (is_array($misapplied) && count($misapplied) > 0) {
164
    ksort($misapplied); // order the misapplied by scientific name
156 165
    $out .= '<ul class="misapplied">';
166

  
157 167
    foreach ($misapplied as $misapplied_name) {
168
      $misapplied_name_markup = $misapplied_name['out'];
158 169

  
159
      $out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name['out'] . ' </span>';
170
      if (isset($misapplied_name['sensu_uuids'])) {
171
        $sensu_refs_with_fkey = array();
172
        foreach ($misapplied_name['sensu_uuids'] as $sensu_uuid) {
173
          $sensu_refs_with_fkey[$joined_sensu_refs[$sensu_uuid]['short_citation']] = $joined_sensu_refs[$sensu_uuid]['markup'];
174
        }
175
        ksort($sensu_refs_with_fkey);
176
        $sensu_refs_with_fkey_markup = join('; ', $sensu_refs_with_fkey);
177
        $misapplied_name_markup = str_replace('{PLACEHOLDER_secReference}', ' sensu ' . $sensu_refs_with_fkey_markup, $misapplied_name_markup);
178
      }
160 179

  
161
      if (isset($misapplied_name['authorteam'])) {
162
        // Fill authors with the renderedFootnoteKey and sorting 'em.
163
        foreach ($misapplied_name['authorteam'] as $authorteam_str => &$renderedFootnoteKey) {
164
          $renderedFootnoteKey = $joinedAuthorTeams[$authorteam_str];
180
      if (isset($misapplied_name['relsec_uuids'])) {
181
        $relsec_refs_with_fkey = array();
182
        foreach ($misapplied_name['relsec_uuids'] as $relsec_uuid) {
183
          $relsec_refs_with_fkey[$joined_sensu_refs[$relsec_uuid]['short_citation']] = $joined_sensu_refs[$relsec_uuid]['markup'];
165 184
        }
166
        ksort($misapplied_name['authorteam']);
167
        $out .= join('; ', $misapplied_name['authorteam']);
185
        ksort($relsec_refs_with_fkey);
186
        $relsec_refs_with_fkey_markup = join('; ', $relsec_refs_with_fkey);
187
        $misapplied_name_markup = str_replace('{PLACEHOLDER_relSecReference}', ', err. sec. ' . $relsec_refs_with_fkey_markup, $misapplied_name_markup);
168 188
      }
189

  
190
      $out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name_markup . ' </span>';
169 191
      $out .= '</li>';
170 192
    }
171 193
    $out .= '</ul>';
......
179 201
    $out .= '</ul>';
180 202
  }
181 203

  
182
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => $footnoteListKey, 'enclosingTag' => 'li'));
183
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnoteListKey, 'enclosingTag' => 'li'));
184

  
185
// AK: why splitting footnotes at the sensu string ??? this is weired and hacky
186
//     TODO remove below dead code
187
//   $tr_footnotes_exploded = explode('sensu', $tr_footnotes);
188
//   $tr_footnotes_aux = '';
189
//   foreach ($tr_footnotes_exploded as $element) {
190
//     $tr_footnotes_aux .= $element;
191
//   }
204
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
205
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
192 206

  
193 207
  $out .= '<ul class="footnotes">' . $footnotes . '</ul>';
194

  
195 208
  $out .= '</div>';
196 209

  
197 210
  RenderHints::popFromRenderStack();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)