Project

General

Profile

« Previous | Next » 

Revision 79904336

Added by Andreas Kohlbecker almost 4 years ago

ref #8134 moving render_type_designations() to include file

View differences:

modules/cdm_dataportal/includes/name.inc
861 861
}
862 862

  
863 863

  
864
/**
865
 * Renders and array of CDM TypeDesignations
866
 *
867
 * @param object $type_designations an array of cdm TypeDesignation entities
868
 *  to render
869
 * @param string $enclosing_tag the tag element type to enclose the whole list
870
 *  of type designation with. By default this DOM element is <ul>
871
 * @param string $element_tag the tag element type to be used for each
872
 *  type designation item.
873
 * @param bool $link_to_specimen_page whether a specimen in type designation element
874
 *  should be a link or not.
875
 *
876
 * @return string The markup.
877
 *
878
 * @InGroup Render
879
 */
880
function render_type_designations($type_designations, $enclosing_tag = 'ul', $element_tag =  'li', $link_to_specimen_page = true) {
881

  
882
  // need to add element to render path since type designations
883
  // need other name render template
884
  RenderHints::pushToRenderStack('typedesignations');
885

  
886
  $out = '<' . $enclosing_tag .' class="typeDesignations">';
887
  $typeDesignation_footnotes = FALSE;
888
  $is_lectotype = FALSE;
889
  $specimen_type_designations = array();
890
  $name_type_designations = array();
891
  $textual_type_designations = array();
892
  $separator = ',';
893

  
894
  foreach ($type_designations as $type_designation) {
895
    switch ($type_designation->class) {
896
      case 'SpecimenTypeDesignation':
897
        $specimen_type_designations[] = $type_designation;
898
        break;
899
      case 'NameTypeDesignation':
900
        $name_type_designations[] = $type_designation;
901
        break;
902
      case 'TextualTypeDesignation':
903
        $textual_type_designations[] = $type_designation;
904
        break;
905
      default:  throw new Exception('Unknown type designation class: ' . $type_designation->class);
906
    }
907
  }
908

  
909
  // NameTypeDesignation ..................................
910
  if(!empty($name_type_designations)){
911
    uksort($name_type_designations, "compare_type_designation_status");
912
    foreach($name_type_designations as $name_type_designation){
913
      if ($name_type_designation->notDesignated) {
914
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation)  . ': '
915
          . t('not designated') . '</'. $element_tag .'>';
916
      }
917
      elseif (isset($name_type_designation->typeName)) {
918
        $link_to_name_page = url(path_to_name($name_type_designation->typeName->uuid));
919
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation) ;
920

  
921
        if (!empty($name_type_designation->citation)) {
922
          $out .= type_designation_citation_layout($name_type_designation, $separator); // TODO type_designation_citation_layout() needs most probably to be replaced
923

  
924
        }
925
        $referenceUri = '';
926
        if (isset($name_type_designation->typeName->nomenclaturalReference)) {
927
          $referenceUri = url(path_to_reference($name_type_designation->typeName->nomenclaturalReference->uuid));
928
        }
929
        $out .= ': ' . render_taxon_or_name($name_type_designation->typeName, $link_to_name_page, $referenceUri, TRUE, TRUE);
930
      }
931
    }
932
  } // END NameTypeDesignation
933

  
934
  // SpecimenTypeDesignation ...................................
935
  if (!empty($specimen_type_designations)) {
936
    usort($specimen_type_designations, "compare_specimen_type_designation");
937
    foreach ($specimen_type_designations as $specimen_type_designation) {
938
      $type_citation_markup = '';
939

  
940
      if (!empty($specimen_type_designation->citation)) {
941

  
942
        $citation_footnote_str = theme('cdm_reference', array('reference' => $specimen_type_designation->citation, 'doIconLink' => true));
943
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $specimen_type_designation->citation->uuid);
944

  
945
        if (!empty($author_team->titleCache)) {
946
          $year = @timePeriodToString($specimen_type_designation->citation->datePublished, true, 'YYYY');
947
          $authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
948
          if ($authorteam_str == $specimen_type_designation->citation->titleCache) {
949
            $citation_footnote_str = '';
950
          }
951
        } else {
952
          $authorteam_str = $citation_footnote_str;
953
          // no need for a footnote in case in case it is used as replacement for missing author teams
954
          $citation_footnote_str = '';
955
        }
956

  
957
        // for being registered a typedesignation MUST HAVE a citation, so it is save to handle the
958
        // Registration output in if condition checking if the citation is present
959
        $registration_markup = render_registrations($specimen_type_designation->registrations);
960
        $citation_footnote_str .= ($citation_footnote_str ? ' ' : '') . $registration_markup;
961

  
962
        $footnote_key_markup = '';
963
        if ($citation_footnote_str) {
964
          // footnotes should be rendered in the parent element so we
965
          // are relying on the FootnoteListKey set there
966
          $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
967
          $footnote_key_markup = theme('cdm_footnote_key', array(
968
            'footnoteKey' => $_fkey2,
969
            'separator' => $separator,
970
            'highlightable' => TRUE,
971
            'separator_off' => TRUE,
972
          ));
973

  
974
        }
975

  
976
        $type_citation_markup .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">' . $authorteam_str . '</span>';
977
        if (!empty($specimen_type_designation->citationMicroReference)) {
978
          $type_citation_markup .= ': ' . trim($specimen_type_designation->citationMicroReference);
979
        }
980
        $type_citation_markup .= $footnote_key_markup . ')';
981

  
982
      }
983

  
984
      $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($specimen_type_designation) . '">';
985
      $out .= type_designation_status_label_markup($specimen_type_designation) . $type_citation_markup;
986

  
987

  
988
      $derivedUnitFacadeInstance = null;
989
      if (isset($specimen_type_designation->typeSpecimen)) {
990
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $specimen_type_designation->typeSpecimen->uuid);
991
      }
992

  
993
      if (!empty($derivedUnitFacadeInstance->titleCache)) {
994
        $specimen_markup = $derivedUnitFacadeInstance->titleCache;
995
        if($link_to_specimen_page && isset($derivedUnitFacadeInstance->specimenLabel) && $derivedUnitFacadeInstance->specimenLabel){
996
          $specimen_markup = str_replace($derivedUnitFacadeInstance->specimenLabel, l($derivedUnitFacadeInstance->specimenLabel, path_to_specimen($specimen_type_designation->typeSpecimen->uuid)), $specimen_markup);
997
        }
998
        $out .= ': <span class="' . html_class_attribute_ref($specimen_type_designation->typeSpecimen) . '">'
999
          . $specimen_markup
1000
          . '</span>'; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
1001
        if(!empty($derivedUnitFacadeInstance->preferredStableUri)){
1002
          $out .= ' ' . l($derivedUnitFacadeInstance->preferredStableUri, $derivedUnitFacadeInstance->preferredStableUri, array('absolute' => true));
1003
        }
1004
      }
1005

  
1006

  
1007
      $out .= '</'. $element_tag .'>';
1008

  
1009
    }
1010
  } // END Specimen type designations
1011

  
1012
  // TextualTypeDesignation .........................
1013
  if(!empty($textual_type_designations)) {
1014
    foreach ($textual_type_designations as $textual_type_designation) {
1015
      $encasement =  $textual_type_designation->verbatim ? '"' : '';
1016
      $out .= '<' . $element_tag . ' class="' . html_class_attribute_ref($textual_type_designation) . '">' . type_designation_status_label_markup(null)
1017
        . ': ' .  $encasement . $textual_type_designation->text_L10n->text . $encasement . '</' . $element_tag . '>';
1018
      $annotations_and_sources = handle_annotations_and_sources(
1019
        $textual_type_designation,
1020
        array(
1021
          'sources_as_content' => false, // as footnotes
1022
          'link_to_name_used_in_source' => false,
1023
          'link_to_reference' => true,
1024
          'add_footnote_keys' => false,
1025
          'bibliography_aware' => false),
1026
        '',
1027
        RenderHints::getFootnoteListKey() // passing a defined key to avoid separate annotation footnote key see https://dev.e-taxonomy.eu/redmine/issues/8543
1028
      );
1029
      $out .= $annotations_and_sources['foot_note_keys'];
1030
      if(is_array( $annotations_and_sources['source_references'])){
1031
        $citation_markup = join(', ', $annotations_and_sources['source_references']);
1032
      }
1033
    }
1034
  }
1035

  
1036
  // Footnotes for citations, collection acronym?s.
1037
  // footnotes should be rendered in the parent element so we
1038
  // are relying on the FootnoteListKey set there
1039
  $_fkey = FootnoteManager::addNewFootnote(
1040
    RenderHints::getFootnoteListKey(),
1041
    (isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
1042
  );
1043
  $out .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => $separator));
1044
  $out .= '</' . $enclosing_tag .'>';
1045

  
1046
  RenderHints::popFromRenderStack();
1047

  
1048
  return $out;
1049
}
1050

  
1051

  
864 1052
/**
865 1053
 * Composes the textual representation for the type designation of taxon name identified by the uuid in with a map for the location data.
866 1054
 *
modules/cdm_dataportal/theme/cdm_dataportal.name.theme
59 59
  return $res;
60 60
}
61 61

  
62

  
63
/**
64
 * Renders and array of CDM TypeDesignations
65
 *
66
 * @param object $type_designations an array of cdm TypeDesignation entities
67
 *  to render
68
 * @param string $enclosing_tag the tag element type to enclose the whole list
69
 *  of type designation with. By default this DOM element is <ul>
70
 * @param string $element_tag the tag element type to be used for each
71
 *  type designation item.
72
 * @param bool $link_to_specimen_page whether a specimen in type designation element
73
 *  should be a link or not.
74
 *
75
 * @return string The markup.
76
 *
77
 * @InGroup Render
78
 */
79
function render_type_designations($type_designations, $enclosing_tag = 'ul', $element_tag =  'li', $link_to_specimen_page = true) {
80

  
81
  // need to add element to render path since type designations
82
  // need other name render template
83
  RenderHints::pushToRenderStack('typedesignations');
84

  
85
  $out = '<' . $enclosing_tag .' class="typeDesignations">';
86
  $typeDesignation_footnotes = FALSE;
87
  $is_lectotype = FALSE;
88
  $specimen_type_designations = array();
89
  $name_type_designations = array();
90
  $textual_type_designations = array();
91
  $separator = ',';
92

  
93
  foreach ($type_designations as $type_designation) {
94
    switch ($type_designation->class) {
95
      case 'SpecimenTypeDesignation':
96
        $specimen_type_designations[] = $type_designation;
97
        break;
98
      case 'NameTypeDesignation':
99
        $name_type_designations[] = $type_designation;
100
        break;
101
      case 'TextualTypeDesignation':
102
        $textual_type_designations[] = $type_designation;
103
        break;
104
      default:  throw new Exception('Unknown type designation class: ' . $type_designation->class);
105
    }
106
  }
107

  
108
  // NameTypeDesignation ..................................
109
  if(!empty($name_type_designations)){
110
    uksort($name_type_designations, "compare_type_designation_status");
111
    foreach($name_type_designations as $name_type_designation){
112
      if ($name_type_designation->notDesignated) {
113
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation)  . ': '
114
          . t('not designated') . '</'. $element_tag .'>';
115
      }
116
      elseif (isset($name_type_designation->typeName)) {
117
        $link_to_name_page = url(path_to_name($name_type_designation->typeName->uuid));
118
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation) ;
119

  
120
        if (!empty($name_type_designation->citation)) {
121
          $out .= type_designation_citation_layout($name_type_designation, $separator); // TODO type_designation_citation_layout() needs most probably to be replaced
122

  
123
        }
124
        $referenceUri = '';
125
        if (isset($name_type_designation->typeName->nomenclaturalReference)) {
126
          $referenceUri = url(path_to_reference($name_type_designation->typeName->nomenclaturalReference->uuid));
127
        }
128
        $out .= ': ' . render_taxon_or_name($name_type_designation->typeName, $link_to_name_page, $referenceUri, TRUE, TRUE);
129
      }
130
    }
131
  } // END NameTypeDesignation
132

  
133
  // SpecimenTypeDesignation ...................................
134
  if (!empty($specimen_type_designations)) {
135
    usort($specimen_type_designations, "compare_specimen_type_designation");
136
    foreach ($specimen_type_designations as $specimen_type_designation) {
137
      $type_citation_markup = '';
138

  
139
      if (!empty($specimen_type_designation->citation)) {
140

  
141
        $citation_footnote_str = theme('cdm_reference', array('reference' => $specimen_type_designation->citation, 'doIconLink' => true));
142
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $specimen_type_designation->citation->uuid);
143

  
144
        if (!empty($author_team->titleCache)) {
145
          $year = @timePeriodToString($specimen_type_designation->citation->datePublished, true, 'YYYY');
146
          $authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
147
          if ($authorteam_str == $specimen_type_designation->citation->titleCache) {
148
            $citation_footnote_str = '';
149
          }
150
        } else {
151
          $authorteam_str = $citation_footnote_str;
152
          // no need for a footnote in case in case it is used as replacement for missing author teams
153
          $citation_footnote_str = '';
154
        }
155

  
156
        // for being registered a typedesignation MUST HAVE a citation, so it is save to handle the
157
        // Registration output in if condition checking if the citation is present
158
        $registration_markup = render_registrations($specimen_type_designation->registrations);
159
        $citation_footnote_str .= ($citation_footnote_str ? ' ' : '') . $registration_markup;
160

  
161
        $footnote_key_markup = '';
162
        if ($citation_footnote_str) {
163
          // footnotes should be rendered in the parent element so we
164
          // are relying on the FootnoteListKey set there
165
          $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
166
          $footnote_key_markup = theme('cdm_footnote_key', array(
167
            'footnoteKey' => $_fkey2,
168
            'separator' => $separator,
169
            'highlightable' => TRUE,
170
            'separator_off' => TRUE,
171
          ));
172

  
173
        }
174

  
175
        $type_citation_markup .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">' . $authorteam_str . '</span>';
176
        if (!empty($specimen_type_designation->citationMicroReference)) {
177
          $type_citation_markup .= ': ' . trim($specimen_type_designation->citationMicroReference);
178
        }
179
        $type_citation_markup .= $footnote_key_markup . ')';
180

  
181
      }
182

  
183
      $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($specimen_type_designation) . '">';
184
      $out .= type_designation_status_label_markup($specimen_type_designation) . $type_citation_markup;
185

  
186

  
187
      $derivedUnitFacadeInstance = null;
188
      if (isset($specimen_type_designation->typeSpecimen)) {
189
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $specimen_type_designation->typeSpecimen->uuid);
190
      }
191

  
192
      if (!empty($derivedUnitFacadeInstance->titleCache)) {
193
        $specimen_markup = $derivedUnitFacadeInstance->titleCache;
194
        if($link_to_specimen_page && isset($derivedUnitFacadeInstance->specimenLabel) && $derivedUnitFacadeInstance->specimenLabel){
195
          $specimen_markup = str_replace($derivedUnitFacadeInstance->specimenLabel, l($derivedUnitFacadeInstance->specimenLabel, path_to_specimen($specimen_type_designation->typeSpecimen->uuid)), $specimen_markup);
196
        }
197
        $out .= ': <span class="' . html_class_attribute_ref($specimen_type_designation->typeSpecimen) . '">'
198
           . $specimen_markup
199
           . '</span>'; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
200
        if(!empty($derivedUnitFacadeInstance->preferredStableUri)){
201
          $out .= ' ' . l($derivedUnitFacadeInstance->preferredStableUri, $derivedUnitFacadeInstance->preferredStableUri, array('absolute' => true));
202
        }
203
      }
204

  
205

  
206
      $out .= '</'. $element_tag .'>';
207

  
208
    }
209
  } // END Specimen type designations
210

  
211
  // TextualTypeDesignation .........................
212
  if(!empty($textual_type_designations)) {
213
    foreach ($textual_type_designations as $textual_type_designation) {
214
      $encasement =  $textual_type_designation->verbatim ? '"' : '';
215
      $out .= '<' . $element_tag . ' class="' . html_class_attribute_ref($textual_type_designation) . '">' . type_designation_status_label_markup(null)
216
        . ': ' .  $encasement . $textual_type_designation->text_L10n->text . $encasement . '</' . $element_tag . '>';
217
      $annotations_and_sources = handle_annotations_and_sources(
218
        $textual_type_designation,
219
        array(
220
          'sources_as_content' => false, // as footnotes
221
          'link_to_name_used_in_source' => false,
222
          'link_to_reference' => true,
223
          'add_footnote_keys' => false,
224
          'bibliography_aware' => false),
225
      '',
226
        RenderHints::getFootnoteListKey() // passing a defined key to avoid separate annotation footnote key see https://dev.e-taxonomy.eu/redmine/issues/8543
227
        );
228
      $out .= $annotations_and_sources['foot_note_keys'];
229
        if(is_array( $annotations_and_sources['source_references'])){
230
          $citation_markup = join(', ', $annotations_and_sources['source_references']);
231
        }
232
    }
233
  }
234

  
235
  // Footnotes for citations, collection acronym?s.
236
  // footnotes should be rendered in the parent element so we
237
  // are relying on the FootnoteListKey set there
238
  $_fkey = FootnoteManager::addNewFootnote(
239
    RenderHints::getFootnoteListKey(),
240
    (isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
241
  );
242
  $out .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => $separator));
243
  $out .= '</' . $enclosing_tag .'>';
244

  
245
  RenderHints::popFromRenderStack();
246

  
247
  return $out;
248
}
249

  
250 62
/**
251 63
 * Creates markup for the status of a type designation. In case the status or its representation is missing the label will be set to "Type"
252 64
 *

Also available in: Unified diff