Project

General

Profile

« Previous | Next » 

Revision 23ebb91f

Added by Andreas Kohlbecker over 5 years ago

ref #7658 fixing final problems in MAN display related to appendedPhrase, citationDetail, footnotes

View differences:

modules/cdm_dataportal/cdm_api/tagged_text.inc
116 116
    }
117 117
    $i++;
118 118
  }
119
  if($tag) {
120
    $out .= '</' . $tag . '>';
121
  }
119 122
  return $out;
120 123
}
121 124

  
......
138 141
 */
139 142
function cdm_tagged_text_to_string(array $taggedtxt, $skiptags = array()) {
140 143

  
141
//  $out = '';
142
//  $was_separator = false;
143
//  $i = 0;
144
//  foreach ($taggedtxt as $tt) {
145
//    if (!in_array($tt->type, $skiptags) && $tt->text) {
146
//      $is_last = $i + 1 == count($taggedtxt);
147
//      $is_separator = is_tagged_text_sepatator_type($tt->type);
148
//      $glue = !$is_separator && !$was_separator && !$is_last ? ' ' : '';
149
//      $out .= t('@text', array('@text' => $tt->text)) . $glue;
150
//      $was_separator = $is_separator;
151
//    }
152
//    $i++;
153
//  }
154 144
  return cdm_tagged_text_to_markup($taggedtxt, $skiptags, null);
155 145
}
156 146

  
......
265 255
        }
266 256
        unset($tagged_text[$i + 1]);
267 257
        // also get the microreference which could be in $tagged_text[$i + 3]
268
        if(isset($tagged_text[$i + 3])  && $tagged_text[$i + 2]->type == "separator" && $tagged_text[$i + 3]->type == $ref_tag_type){
258
        if(isset($tagged_text[$i + 3])  && $tagged_text[$i + 2]->type == "separator" && $tagged_text[$i + 3]->type == "secMicroReference"){
269 259
          $extracted_tt[2] = $tagged_text[$i + 2];
270 260
          $extracted_tt[3] = $tagged_text[$i + 3];
271 261
          unset($tagged_text[$i + 2]);
......
299 289
      }
300 290
    }
301 291
  }
292
  $tagged_text = array_values($tagged_text); // re-index array to make it continuous again
302 293
  return $extracted_tt;
303 294
}
304 295

  
305
function find_tagged_text_elements($taggedTextList, $type){
296
function tagged_text_extract(&$tagged_text, $type) {
306 297
  $matching_elements = array();
307
  if (is_array($taggedTextList)) {
308
    for ($i = 0; $i < count($taggedTextList) - 1; $i++) {
309
      if($taggedTextList[$i]->type == $type){
310
        $matching_elements[] = $taggedTextList[$i];
298
  if (is_array($tagged_text)) {
299
    for ($i = 0; $i < count($tagged_text) - 1; $i++) {
300
      if($tagged_text[$i]->type == $type){
301
        $matching_elements[] = $tagged_text[$i];
302
        unset($tagged_text[$i]);
303
      }
304
    }
305
  }
306
  $tagged_text = array_values($tagged_text); // re-index array to make it continuous again
307
  return $matching_elements;
308
}
309

  
310
function find_tagged_text_elements(&$tagged_text, $type){
311
  $matching_elements = array();
312
  if (is_array($tagged_text)) {
313
    for ($i = 0; $i < count($tagged_text) - 1; $i++) {
314
      if($tagged_text[$i]->type == $type){
315
        $matching_elements[] = $tagged_text[$i];
311 316
      }
312 317
    }
313 318
  }
modules/cdm_dataportal/includes/taxon.inc
82 82

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

  
85
          // full name with relation symbol, rel sec as deduplication key
85
          // full name with relation symbol, rel sec as de-dublication key
86 86
          // the sensu part will be removed from the key below in case it is present
87 87
          $symbol_text = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('symbol')));
88 88
          $name_text = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('name')));
89
          // remove quotes surrounding the name
90
          $name_text = str_replace('"', '', $name_text);
91
          $name_text = str_replace('&quot;', '', $name_text);
92
          $full_name_key = $name_text . ' ' . cdm_tagged_text_to_string($taxon_relation->taggedText, array('name', 'symbol')) . " " . $symbol_text;
89
          $appended_phrase_text = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('appendedPhrase')));
93 90

  
94
          // Render the first name found as representative for all others.
95
          //###OLD: $misapplied[$name]['out'] = cdm_related_taxon($taxon_relation->fromTaxon, UUID_MISAPPLIED_NAME_FOR);
91
          $full_name_key = cdm_tagged_text_to_string($taxon_relation->taggedText, array('symbol', 'appendedPhrase'));
92
          $full_name_key = $name_text . ' ' . str_replace($name_text, '', $full_name_key) . ' ' . $symbol_text;
93

  
94
          // remove/extract appendedPhrase, secReference, relSecReference and add placeholders if needed
95
          tagged_text_extract($taxon_relation->taggedText, 'appendedPhrase');
96 96
          $sensu_tagged_text = tagged_text_extract_secref($taxon_relation->taggedText, "secReference", true);
97 97
          $relsec_tagged_text = tagged_text_extract_secref($taxon_relation->taggedText, "relSecReference", true);
98 98

  
99

  
100 99
          if (isset($sensu_tagged_text[1])) {
101
            // everything else needs to be equal except for MAN.sec and MAN.secDetail. see #7658#note-21
100
            // for de-dublicationeverything else needs to be equal except for appendedPhrase + MAN.sec + MAN.secDetail. see #7658#note-21
102 101
            $full_name_key = str_replace(cdm_tagged_text_to_string($sensu_tagged_text), ' ', $full_name_key);
103
            array_shift($sensu_tagged_text); // remove first element which contains the "sensu", this will be added later in this code
102
            $appended_phrase_text = $appended_phrase_text . array_shift($sensu_tagged_text)->text; // remove first element which contains the "sensu", this will be added later in this code
103
            $sensu_citation_detail = trim(join(' ', cdm_tagged_text_values($sensu_tagged_text, array('secMicroReference'))));
104 104
            $sensu_citation_short_markup = cdm_tagged_text_to_markup($sensu_tagged_text);
105 105
            $sensu_citation_short = cdm_tagged_text_to_string($sensu_tagged_text);
106 106
            $sensu_uuid = $sensu_tagged_text[0]->entityReference->uuid;
107
            $misapplied[$full_name_key]['sensu_uuids'][] = $sensu_uuid;
108
            if (!isset($joined_refs[$sensu_uuid])) {
109
              $joined_refs[$sensu_uuid] = array(
107
            $full_name_key = preg_replace('/\s+/', ' ', $full_name_key); // sanitize multiple whitespace characters
108
            $misapplied[$full_name_key]['sensu_uuids'][] = array('uuid' => $sensu_uuid, 'prefix' => $appended_phrase_text, 'citation_detail' => $sensu_citation_detail);
109
            $ref_key = $sensu_uuid .($sensu_citation_detail ? '#' . $sensu_citation_detail : '');
110
            if (!isset($joined_refs[$ref_key])) {
111
              $joined_refs[$ref_key] = array(
110 112
                'order_by_key' => $sensu_citation_short,
111 113
                'markup' => $sensu_citation_short_markup // the footnote key will be appended later
112 114
              );
113 115
            }
116
          } else if($appended_phrase_text) {
117
            // appended phrase without reference
118
            $full_name_key = preg_replace('/\s+/', ' ', $full_name_key); // sanitize multiple whitespace characters
119
            $misapplied[$full_name_key]['sensu_uuids'][] = array('uuid' => null, 'prefix' => $appended_phrase_text);
120
          }
114 121

  
115
            if (isset($relsec_tagged_text[1])) {
116
              array_shift($relsec_tagged_text); // remove first element which contains the "err. sec", this will be added later in this code
117
              $relsec_citation_short_markup = cdm_tagged_text_to_markup($relsec_tagged_text);
118
              $relsec_citation_short = cdm_tagged_text_to_string($relsec_tagged_text);
119
              $relsec_uuid = $relsec_tagged_text[0]->entityReference->uuid;
120
              $misapplied[$full_name_key]['relsec_uuids'][] = $relsec_uuid;
121
              if (!isset($joined_refs[$relsec_uuid])) {
122
                $joined_refs[$relsec_uuid] = array(
123
                  'order_by_key' => $relsec_citation_short,
124
                  'markup' => $relsec_citation_short_markup // the footnote key will be appended later
125
                );
126
              }
122
          if (isset($relsec_tagged_text[1])) {
123
            array_shift($relsec_tagged_text); // remove first element which contains the "err. sec", this will be added later in this code
124
            $relsec_citation_detail = trim(join(' ', cdm_tagged_text_values($relsec_tagged_text, array('secMicroReference'))));
125
            $relsec_citation_short_markup = cdm_tagged_text_to_markup($relsec_tagged_text);
126
            $relsec_citation_short = cdm_tagged_text_to_string($relsec_tagged_text);
127
            $relsec_uuid = $relsec_tagged_text[0]->entityReference->uuid;
128
            $misapplied[$full_name_key]['relsec_uuids'][] = $relsec_uuid;
129
            $ref_key = $relsec_uuid . ($relsec_citation_detail ? '#' . $relsec_citation_detail : '');
130
            if (!isset($joined_refs[$ref_key])) {
131
              $joined_refs[$ref_key] = array(
132
                'order_by_key' => $relsec_citation_short,
133
                'markup' => $relsec_citation_short_markup // the footnote key will be appended later
134
              );
127 135
            }
136
          }
128 137

  
129
            if (!isset($misapplied[$full_name_key]['out'])) {
130
              $misapplied[$full_name_key]['out'] = cdm_tagged_text_to_markup($taxon_relation->taggedText);
131
            } else {
132
              // We need to add the anchors for all of the other misapplied names not
133
              // being rendered explicitly.
134
              $misapplied[$full_name_key]['out'] = uuid_anchor($taxon_relation->taxonUuid, $misapplied[$full_name_key]['out']);
135
            }
138
          if (!isset($misapplied[$full_name_key]['out'])) {
139
            $misapplied[$full_name_key]['out'] = cdm_tagged_text_to_markup($taxon_relation->taggedText);
136 140
          } else {
137
            RenderHints::pushToRenderStack('other_taxon_relationship');
138
            // All relationship types except misapplied_name_for and invalid_designation_for.
139
            $taxon_relationships_lines[] = cdm_taxonRelationship($taxon_relation, TRUE, _is_invers_taxonRelationship($taxon_relation, $focusedTaxon));
141
            // We need to add the anchors for all of the other misapplied names not
142
            // being rendered explicitly.
143
            $misapplied[$full_name_key]['out'] = uuid_anchor($taxon_relation->taxonUuid, $misapplied[$full_name_key]['out']);
140 144
          }
141

  
142
          RenderHints::popFromRenderStack();
145
        } else {
146
          RenderHints::pushToRenderStack('other_taxon_relationship');
147
          // All relationship types except misapplied_name_for and invalid_designation_for.
148
          $taxon_relationships_lines[] = cdm_taxonRelationship($taxon_relation, TRUE, _is_invers_taxonRelationship($taxon_relation, $focusedTaxon));
143 149
        }
150
        RenderHints::popFromRenderStack();
144 151
      }
145 152
    } // END loop over $taxonRelationshipsDTO->relations
146 153
  }
......
154 161
  });
155 162

  
156 163

  
157
  foreach ($joined_refs as $sensu_uuid => $sensu_strings) {
158
    $footnote_key = '';
164
  foreach ($joined_refs as $ref_key => $sensu_strings) {
159 165
    if(!empty($sensu_strings)) {
166
      $ref_key_tokens = explode('#', $ref_key);
167
      $sensu_uuid = $ref_key_tokens[0];
160 168
      $sensu_reference = cdm_ws_get(CDM_WS_REFERENCE, $sensu_uuid);
161 169
      if(!$sensu_reference){
162 170
        drupal_set_message("Problem fetching sensu reference with uuid " . $sensu_uuid, 'error');
......
164 172
      if($sensu_strings['order_by_key'] != $sensu_reference->titleCache){
165 173
        $footnote_key = FootnoteManager::addNewFootnote($footnote_list_key, $sensu_reference->titleCache);
166 174
        $footnote_key = theme('cdm_footnote_key', array('footnoteKey' => $footnote_key));
167

  
168
        $joined_refs[$sensu_uuid]['markup'] = '<span class="sensu">' . $sensu_strings['markup'] . $footnote_key . '</span>';
175
        $joined_refs[$ref_key]['markup'] = '<span class="sensu">' . $sensu_strings['markup'] . $footnote_key . '</span>';
169 176
      }
170 177
    }
171 178
  }
172 179

  
173 180
  // ---- Generate output ---- //
174 181
  $out = '<div class="taxon-relationships">';
175
  if (is_array($misapplied) && count($misapplied) > 0) {
182
  if (count($misapplied) > 0) {
176 183
    ksort($misapplied); // order the misapplied by scientific name
177 184
    $out .= '<ul class="misapplied">';
178 185

  
186
    // create the list entries per misapplied name
179 187
    foreach ($misapplied as $misapplied_name) {
180 188
      $misapplied_name_markup = $misapplied_name['out'];
181

  
189
      // all sensu and auct. for this MAN
182 190
      if (isset($misapplied_name['sensu_uuids'])) {
183 191
        $sensu_refs_with_fkey = array();
184
        foreach ($misapplied_name['sensu_uuids'] as $sensu_uuid) {
185
          $sensu_refs_with_fkey[$joined_refs[$sensu_uuid]['order_by_key']] = $joined_refs[$sensu_uuid]['markup'];
192
        foreach ($misapplied_name['sensu_uuids'] as $sensu_data) {
193
          if($sensu_data['uuid']){
194
            $joined_ref_key = $sensu_data['uuid'] . ($sensu_data['citation_detail'] ? '#' .  $sensu_data['citation_detail'] : '');
195
            $sensu_refs_with_fkey[$sensu_data['prefix'] . $joined_refs[$joined_ref_key]['order_by_key']] = $sensu_data['prefix'] . $joined_refs[$joined_ref_key]['markup'];
196
          } else {
197
            $sensu_refs_with_fkey[$sensu_data['prefix']] = $sensu_data['prefix'];
198
          }
186 199
        }
187 200
        ksort($sensu_refs_with_fkey);
188 201
        $sensu_refs_with_fkey_markup = join('; ', $sensu_refs_with_fkey);
189
        $misapplied_name_markup = str_replace('{PLACEHOLDER_secReference}', ' sensu ' . $sensu_refs_with_fkey_markup, $misapplied_name_markup);
202
        $misapplied_name_markup = str_replace('{PLACEHOLDER_secReference}', $sensu_refs_with_fkey_markup, $misapplied_name_markup);
190 203
      }
191 204

  
205
      // append the err. sec. if there is any for this MAN
192 206
      if (isset($misapplied_name['relsec_uuids'])) {
193 207
        $relsec_refs_with_fkey = array();
194 208
        foreach ($misapplied_name['relsec_uuids'] as $relsec_uuid) {
......
198 212
        $relsec_refs_with_fkey_markup = join('; ', $relsec_refs_with_fkey);
199 213
        $misapplied_name_markup = str_replace('{PLACEHOLDER_relSecReference}', ', err. sec. ' . $relsec_refs_with_fkey_markup, $misapplied_name_markup);
200 214
      }
201

  
202
      $out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name_markup . ' </span>';
203
      $out .= '</li>';
215
      // final line
216
      $out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name_markup . ' </span></li>';
204 217
    }
205 218
    $out .= '</ul>';
206 219
  }
src/test/java/eu/etaxonomy/dataportal/selenium/tests/reference/MisappliedNamesTest.java
66 66
        TaxonSynonymyPage p = new TaxonSynonymyPage(driver, getContext(), miconia_cubacinerea_Uuid);
67 67

  
68 68

  
69
        assertEquals("–\n\"Ossaea glomerata\" sensu A&S1; Lem2; Species solaris", p.getMisappliedName(1).getText());
70
        // with appended phrase
71
        assertEquals("–\n\"Ossaea glomerata\" appended_phrase sensu A&S1", p.getMisappliedName(2).getText());
69
        assertEquals("–\n\"Ossaea glomerata\" sensu A&S1; sensu A&S: 221; sensu A&S: 331; sensu Lem2; sensu Species solaris; auct.; auct. sensu A&S1; auctrs. afr.", p.getMisappliedName(1).getText());
72 70
        // with doubtful flag
73
        assertEquals("–\n" + StringConstants.DOUBTFULMARKER_SPACE +"\"Ossaea glomerata\" sensu A&S1", p.getMisappliedName(3).getText());
71
        assertEquals("–\n" + StringConstants.DOUBTFULMARKER_SPACE +"\"Ossaea glomerata\" sensu A&S1", p.getMisappliedName(2).getText());
74 72
        // Test also invalid designation which is rendered with the misapplied names
75
        assertEquals("–\nOssaea maculata sensu Lem2, err. sec. A&S1", p.getMisappliedName(4).getText());
73
        assertEquals("–\nOssaea maculata sec. Lem2, err. sec. A&S1", p.getMisappliedName(3).getText());
76 74

  
77 75
        List<BaseElement> footnotes = ElementUtils.findFootNotes(p.getTaxonRelationships());
78 76
        assertEquals(2, footnotes.size());
79 77
        assertEquals("1. A&S, Plantas vasculares de Oz", footnotes.get(0).getText());
80 78
        assertEquals("2. Lem, New Species in the solar system", footnotes.get(1).getText());
79
        // "Species solaris" must not be in the footnotes as it has the same title as the short citation
81 80

  
82 81
    }
83 82

  

Also available in: Unified diff