Project

General

Profile

« Previous | Next » 

Revision 4a236db6

Added by Andreas Kohlbecker about 8 years ago

renaming functions and code organisation

View differences:

modules/cdm_dataportal/includes/descriptions.inc
553 553
            if(isset($taxon) ) {
554 554
              $taxon_uuid = $taxon->uuid;
555 555
            }
556
            $elements_render_array = compose_cdm_descriptionElements($node->descriptionElements, $node->feature, $taxon_uuid);
556
            $elements_render_array = compose_description_elements($node->descriptionElements, $node->feature, $taxon_uuid);
557 557
            $block_content_is_empty = empty($elements_render_array);
558 558
            $block->content[] = $elements_render_array;
559 559
          }
......
573 573
              if (isset($child->descriptionElements) && is_array($child->descriptionElements)) {
574 574
                foreach ($child->descriptionElements as $element) {
575 575

  
576
                  //TODO it woud be better if we could use compose_cdm_descriptionElements() directly instead of the below stuff
576
                  //TODO it woud be better if we could use compose_description_elements() directly instead of the below stuff
577 577

  
578 578
                  if (is_array($element->media)) {
579 579
                    // Append media of subordinate elements to list of main
......
583 583

  
584 584
                  switch ($element->class) {
585 585
                    case 'TextData':
586
                      // FIXME use compose_cdm_descriptionElementTextData()
586
                      // FIXME use compose_description_element_textdata()
587 587
                      if(isset($element->multilanguageText_L10n->text)){
588 588
                        $out_child_elements = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
589 589
                      }
......
664 664
  }
665 665

  
666 666
  /**
667
   * Composes the distribution feature block for a taxon
668
   *
667 669
   * @param $taxon
668 670
   * @param $descriptionElements
669 671
   *   an associative array with two elements:
......
712 714
      // --- TextData
713 715
      foreach ($descriptionElements['TextData'] as $text_data_element) {
714 716
        $asListElement = FALSE;
715
        $text_data_render_array = compose_cdm_descriptionElementTextData($text_data_element, $asListElement, $text_data_element->feature->uuid);
717
        $text_data_render_array = compose_description_element_textdata($text_data_element, $asListElement, $text_data_element->feature->uuid);
716 718
        $repr = drupal_render($text_data_render_array);
717 719

  
718 720
        if (!array_search($repr, $text_data_out_array)) { // de-duplication !!
......
815 817
          }
816 818
        }
817 819
        ksort($distributionElements);
818
        $distribution_element_render_array = compose_cdm_descriptionElement_Distribution($distributionElements);
820
        $distribution_element_render_array = compose_description_element_distribution($distributionElements);
819 821
        $dto_out_array[] = drupal_render($distribution_element_render_array);
820 822

  
821 823
      }
......
869 871
   *
870 872
   * @ingroup compose
871 873
   */
872
  function compose_cdm_descriptionElementTextData($element, $asListElement, $feature_uuid) {
874
  function compose_description_element_textdata($element, $asListElement, $feature_uuid) {
873 875

  
874 876
    $footnote_list_key_suggestion = $feature_uuid;
875 877

  
......
923 925

  
924 926

  
925 927
  /**
926
   * Returns HTML for the texts in a description $elements.
927
   *
928
   * Joins the texts in $elements and encloses with a HTML tag.
928
   * Creates a render array for string representations of description elements for the given feature.
929 929
   *
930
   * @param  $elements
930
   * @param array $elements
931
   *   An array of strings. Can be plaintext or markup.
931 932
   * @param  feature:
932 933
   *  The feature to which the elements given in $elements are belonging to.
933 934
   * @param  glue:
......
938 939
   *
939 940
   * @ingroup compose
940 941
   */
941
  function compose_cdm_feature_block_elements($elements, $feature, $glue = '', $sort = FALSE, $enclosing_tag = 'ul') {
942
  function compose_cdm_feature_block_elements(array $elements, $feature, $glue = '', $sort = FALSE, $enclosing_tag = 'ul') {
942 943

  
943 944
    $feature_block_settings = get_feature_block_settings($feature->uuid);
944 945
    if($feature_block_settings['as_list']){
......
1026 1027
    return $name_in_source_render_array;
1027 1028
  }
1028 1029

  
1029
  /**
1030
   * Composes block of common names for the given DescriptionElements $elements which must be of the feature CommonName
1031
   *
1032
   * @parameter $elements
1033
   *  an array of CDM DescriptionElements either of type CommonName or TextData
1034
   * @parameter $feature
1035
   *  the common feature of all $elements, must be CommonName
1036
   *
1037
   * @return
1038
   *   A drupal render array
1039
   *
1040
   * @ingroup compose
1041
   */
1042
  function compose_cdm_common_names($elements, $feature, $weight = FALSE) {
1043

  
1044
    $common_name_out = '';
1045
    $common_name_feature_elements = array();
1046
    $textData_commonNames = array();
1047

  
1048
    $footnote_key_suggestion = 'common-names-feature-block';
1049 1030

  
1050
    $feature_block_settings = get_feature_block_settings(UUID_COMMON_NAME);
1051

  
1052
    $element_tag_name = cdm_feature_block_element_tag_name($feature_block_settings);
1053

  
1054
    if (is_array($elements)) {
1055
      foreach ($elements as $element) {
1056

  
1057
        if ($element->class == 'CommonTaxonName') {
1058

  
1059
          // common name without a language or area, should not happen but is possible
1060
          $language_area_key = '';
1061
          if (isset($element->language->representation_L10n)) {
1062
            $language_area_key .= '<b>' . $element->language->representation_L10n . '</b>';
1063
          }
1064
          if(isset($element->area->titleCache) && strlen($element->area->titleCache) > 0){
1065
            $language_area_key .= ($language_area_key ? ' '  : '') . '(' . $element->area->titleCache . ')';
1066
          }
1067

  
1068
          if(isset($common_names[$language_area_key][$element->name])) {
1069
            // same name already exists for language and areae combination, se we merge the description elements
1070
            cdm_merge_description_elements($common_names[$language_area_key][$element->name], $element);
1071
          } else{
1072
            // otherwise add as new entry
1073
            $common_names[$language_area_key][$element->name] = $element;
1074
          }
1075

  
1076
        }
1077
        elseif ($element->class == 'TextData') {
1078
          $textData_commonNames[] = $element;
1079
        }
1080
      }
1081
    }
1082
    // Handling common names.
1083
    if (isset($common_names) && count($common_names) > 0) {
1084
      // Sorting the array based on the key (language, + area if set).
1085
      // Comment @WA there are common names without a language, so this sorting
1086
      // can give strange results.
1087
      ksort($common_names);
1088

  
1089
      // loop over set of elements per language area
1090
      foreach ($common_names as $language_area_key => $elements) {
1091
        ksort($elements); // sort names alphabetically
1092
        $per_language_area_out = array();
1093
        // loop over set of individual elements
1094
        foreach ($elements as $element) {
1095
          if ($element->name) {
1096
            $annotations_and_sources = handle_annotations_and_sources($element, $feature_block_settings, $element->name, $footnote_key_suggestion);
1097
            $source_references_markup = '';
1098
            if(!empty($annotations_and_sources['source_references'])){
1099
              $source_references_markup = ' ' . join(', ', $annotations_and_sources['source_references']);
1100
            }
1101
            $per_language_area_out[] = '<' . $element_tag_name. ' class="' . html_class_attribute_ref($element) . '">'
1102
              . $element->name . $source_references_markup . $annotations_and_sources['foot_note_keys'] . '</' . $element_tag_name. '>';
1103
          }
1104
        } // End of loop over set of individual elements
1105
        $common_name_feature_elements[] = ($language_area_key ? $language_area_key . ': ' : '' ) . join(', ', $per_language_area_out);
1106
      } // End of loop over set of elements per language area
1107

  
1108

  
1109
      $common_name_feature_elements_render_array = compose_cdm_feature_block_elements(
1110
        $common_name_feature_elements,
1111
        $feature,
1112
        '; ',
1113
        FALSE,
1114
        $feature_block_settings['as_list']
1115
      );
1116
      $common_name_out .= $common_name_feature_elements_render_array['#markup'];
1117

  
1118
    }
1119

  
1120
    // Handling commons names as text data.
1121
    $text_data_out = array();
1122

  
1123
    foreach ($textData_commonNames as $text_data_element) {
1124
      /* footnotes are not handled correctly in compose_cdm_descriptionElementTextData,
1125
         need to set 'common-names-feature-block' as $footnote_key_suggestion */
1126
      RenderHints::setFootnoteListKey($footnote_key_suggestion);
1127
      $text_data_render_array = compose_cdm_descriptionElementTextData($text_data_element, TRUE, $text_data_element->feature->uuid);
1128
      $text_data_out[] = drupal_render($text_data_render_array);
1129
    }
1130

  
1131
    $common_name_out_text_data = compose_cdm_feature_block_elements(
1132
      $text_data_out,
1133
      $feature
1134
    );
1135

  
1136
    $footnotes = theme('cdm_footnotes', array('footnoteListKey' => 'BIBLIOGRAPHY-' . $footnote_key_suggestion));
1137
    $footnotes .= theme('cdm_footnotes', array('footnoteListKey' => $footnote_key_suggestion)); // FIXME is this needed at all?
1138
    $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_key_suggestion));
1139

  
1140
    return  markup_to_render_array(
1141
      '<div class="common_names_as_common_names">' . $common_name_out . '</div>'
1142
      .'<div class="common_names_as_text_data">' . $common_name_out_text_data['#markup'] . '</div>'
1143
      .$footnotes,
1144
      $weight
1145
    );
1146
  }
1147 1031

  
1148 1032
  /**
1149 1033
   * Return HTML for a list of description elements.
......
1164 1048
   *
1165 1049
   * @ingroup compose
1166 1050
   */
1167
  function compose_cdm_descriptionElements($descriptionElements, $feature) {
1051
  function compose_description_elements($descriptionElements, $feature) {
1168 1052

  
1169 1053
    $render_array = array();
1170 1054
    $elements_out_array = array();
......
1204 1088
          $asListElement  = $feature_block_settings['as_list'] == 'ul';
1205 1089
          switch ($descriptionElement->class) {
1206 1090
            case 'TextData':
1207
              $text_data_render_array = compose_cdm_descriptionElementTextData($descriptionElement, $asListElement, $descriptionElement->feature->uuid);
1091
              $text_data_render_array = compose_description_element_textdata($descriptionElement, $asListElement, $descriptionElement->feature->uuid);
1208 1092
              $feature_block_has_content = $feature_block_has_content || !empty($text_data_render_array['#value']);
1209 1093
              $elements_out_array[] = drupal_render($text_data_render_array);
1210 1094
              break;
......
1257 1141
    return $render_array;
1258 1142
  }
1259 1143

  
1144
/**
1145
 * Composes block of common names for the given DescriptionElements $elements which must be of the feature CommonName
1146
 *
1147
 * @parameter $elements
1148
 *  an array of CDM DescriptionElements either of type CommonName or TextData
1149
 * @parameter $feature
1150
 *  the common feature of all $elements, must be CommonName
1151
 *
1152
 * @return
1153
 *   A drupal render array
1154
 *
1155
 * @ingroup compose
1156
 */
1157
function compose_cdm_common_names($elements, $feature, $weight = FALSE) {
1158

  
1159
  $common_name_out = '';
1160
  $common_name_feature_elements = array();
1161
  $textData_commonNames = array();
1162

  
1163
  $footnote_key_suggestion = 'common-names-feature-block';
1164

  
1165
  $feature_block_settings = get_feature_block_settings(UUID_COMMON_NAME);
1166

  
1167
  $element_tag_name = cdm_feature_block_element_tag_name($feature_block_settings);
1168

  
1169
  if (is_array($elements)) {
1170
    foreach ($elements as $element) {
1171

  
1172
      if ($element->class == 'CommonTaxonName') {
1173

  
1174
        // common name without a language or area, should not happen but is possible
1175
        $language_area_key = '';
1176
        if (isset($element->language->representation_L10n)) {
1177
          $language_area_key .= '<b>' . $element->language->representation_L10n . '</b>';
1178
        }
1179
        if(isset($element->area->titleCache) && strlen($element->area->titleCache) > 0){
1180
          $language_area_key .= ($language_area_key ? ' '  : '') . '(' . $element->area->titleCache . ')';
1181
        }
1182

  
1183
        if(isset($common_names[$language_area_key][$element->name])) {
1184
          // same name already exists for language and areae combination, se we merge the description elements
1185
          cdm_merge_description_elements($common_names[$language_area_key][$element->name], $element);
1186
        } else{
1187
          // otherwise add as new entry
1188
          $common_names[$language_area_key][$element->name] = $element;
1189
        }
1190

  
1191
      }
1192
      elseif ($element->class == 'TextData') {
1193
        $textData_commonNames[] = $element;
1194
      }
1195
    }
1196
  }
1197
  // Handling common names.
1198
  if (isset($common_names) && count($common_names) > 0) {
1199
    // Sorting the array based on the key (language, + area if set).
1200
    // Comment @WA there are common names without a language, so this sorting
1201
    // can give strange results.
1202
    ksort($common_names);
1203

  
1204
    // loop over set of elements per language area
1205
    foreach ($common_names as $language_area_key => $elements) {
1206
      ksort($elements); // sort names alphabetically
1207
      $per_language_area_out = array();
1208
      // loop over set of individual elements
1209
      foreach ($elements as $element) {
1210
        if ($element->name) {
1211
          $annotations_and_sources = handle_annotations_and_sources($element, $feature_block_settings, $element->name, $footnote_key_suggestion);
1212
          $source_references_markup = '';
1213
          if(!empty($annotations_and_sources['source_references'])){
1214
            $source_references_markup = ' ' . join(', ', $annotations_and_sources['source_references']);
1215
          }
1216
          $per_language_area_out[] = '<' . $element_tag_name. ' class="' . html_class_attribute_ref($element) . '">'
1217
            . $element->name . $source_references_markup . $annotations_and_sources['foot_note_keys'] . '</' . $element_tag_name. '>';
1218
        }
1219
      } // End of loop over set of individual elements
1220
      $common_name_feature_elements[] = ($language_area_key ? $language_area_key . ': ' : '' ) . join(', ', $per_language_area_out);
1221
    } // End of loop over set of elements per language area
1222

  
1223

  
1224
    $common_name_feature_elements_render_array = compose_cdm_feature_block_elements(
1225
      $common_name_feature_elements,
1226
      $feature,
1227
      '; ',
1228
      FALSE,
1229
      $feature_block_settings['as_list']
1230
    );
1231
    $common_name_out .= $common_name_feature_elements_render_array['#markup'];
1232

  
1233
  }
1234

  
1235
  // Handling commons names as text data.
1236
  $text_data_out = array();
1237

  
1238
  foreach ($textData_commonNames as $text_data_element) {
1239
    /* footnotes are not handled correctly in compose_description_element_textdata,
1240
       need to set 'common-names-feature-block' as $footnote_key_suggestion */
1241
    RenderHints::setFootnoteListKey($footnote_key_suggestion);
1242
    $text_data_render_array = compose_description_element_textdata($text_data_element, TRUE, $text_data_element->feature->uuid);
1243
    $text_data_out[] = drupal_render($text_data_render_array);
1244
  }
1245

  
1246
  $common_name_out_text_data = compose_cdm_feature_block_elements(
1247
    $text_data_out,
1248
    $feature
1249
  );
1250

  
1251
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => 'BIBLIOGRAPHY-' . $footnote_key_suggestion));
1252
  $footnotes .= theme('cdm_footnotes', array('footnoteListKey' => $footnote_key_suggestion)); // FIXME is this needed at all?
1253
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_key_suggestion));
1254

  
1255
  return  markup_to_render_array(
1256
    '<div class="common_names_as_common_names">' . $common_name_out . '</div>'
1257
    .'<div class="common_names_as_text_data">' . $common_name_out_text_data['#markup'] . '</div>'
1258
    .$footnotes,
1259
    $weight
1260
  );
1261
}
1260 1262

  
1261 1263
  /**
1262 1264
   * Composes the render array for a CDM Distribution element
......
1271 1273
   *
1272 1274
   * @ingroup compose
1273 1275
   */
1274
  function compose_cdm_descriptionElement_Distribution($descriptionElements, $enclosingTag = "span"){
1276
  function compose_description_element_distribution($descriptionElements, $enclosingTag = "span"){
1275 1277

  
1276 1278
    $out = '';
1277 1279
    RenderHints::pushToRenderStack('descriptionElementDistribution');
......
1462 1464
  }
1463 1465

  
1464 1466
  /**
1465
   * this function should produce markup as the compose_cdm_descriptionElement_Distribution()
1467
   * this function should produce markup as the compose_description_element_distribution()
1466 1468
   * function.
1467 1469
   *
1468
   * @see compose_cdm_descriptionElement_Distribution()
1470
   * @see compose_description_element_distribution()
1469 1471
   *
1470 1472
   * @param $distribution_tree
1471 1473
   * @param $feature_block_settings

Also available in: Unified diff