Project

General

Profile

« Previous | Next » 

Revision dfc49afb

Added by Andreas Kohlbecker about 8 years ago

compose metod for IndividualsAssociations and further refactoring

View differences:

modules/cdm_dataportal/includes/descriptions.inc
355 355
}
356 356

  
357 357

  
358

  
359
/**
360
 * @param $render_array
361
 * @param $element
362
 * @param $feature_block_settings
363
 * @param $element_markup
364
 * @param $footnote_list_key_suggestion
365
 */
366
function cdm_description_element_render_array_add_annotations_and_sources(&$render_array, $element, $feature_block_settings, $element_markup, $footnote_list_key_suggestion)
367
{
368
  $annotations_and_sources = handle_annotations_and_sources($element, $feature_block_settings, $element_markup, $footnote_list_key_suggestion);
369

  
370
  $names_used_in_source_markup = '';
371
  if (!empty($annotations_and_sources['names_used_in_source']) && empty($element_markup)) {
372
    // $element_text ==  NULL  usually occurs only in the case of CITATIONS!!!
373
    $names_used_in_source_markup = join(', ', $annotations_and_sources['names_used_in_source']) . ': ';
374
  }
375

  
376
  $source_references_markup = '';
377
  if (!empty($annotations_and_sources['source_references'])) {
378
    $source_references_markup = '<span class="sources">' . join(' ', $annotations_and_sources['source_references']) . '<span>';
379
  }
380

  
381
  $render_array['#value'] = $names_used_in_source_markup . $element_markup . $source_references_markup;
382
  $render_array['#value_suffix'] = $annotations_and_sources['foot_note_keys'];
383
}
384

  
385

  
358 386
  /**
359 387
   * @param $element
360 388
   * @param $feature_block_settings
......
573 601
              if (isset($child->descriptionElements) && is_array($child->descriptionElements)) {
574 602
                foreach ($child->descriptionElements as $element) {
575 603

  
576
                  //TODO it woud be better if we could use compose_feature_block_items_generic() directly instead of the below stuff
604
                  //TODO it would be better if we could use compose_feature_block_items_generic() directly instead of the below stuff
577 605

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

  
734 762
    if ($text_data_out_array && variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
735 763
      $block->content[] = compose_feature_block_elements(
736
        $text_data_out_array,
737
        $feature,
738
        $text_data_glue,
739
        $text_data_sortOutArray,
740
        $text_data_enclosingTag
764
        $text_data_out_array, $feature, $text_data_glue, $text_data_sortOutArray
741 765
      );
742 766
    }
743 767

  
......
823 847
      }
824 848
      //
825 849
      $block->content[] = compose_feature_block_elements(
826
        $dto_out_array,
827
        $feature,
828
        $distribution_glue,
829
        $distribution_sortOutArray,
830
        $distribution_enclosingTag
850
        $dto_out_array, $feature, $distribution_glue, $distribution_sortOutArray
831 851
      );
832 852
    }
833 853

  
834 854
    // --- TextData at the bottom
835 855
    if ($text_data_out_array && !variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
836 856
      $block->content[] = compose_feature_block_elements(
837
        $text_data_out_array,
838
        $feature,
839
        $text_data_glue,
840
        $text_data_sortOutArray,
841
        $text_data_enclosingTag
857
        $text_data_out_array, $feature, $text_data_glue, $text_data_sortOutArray
842 858
      );
843 859
    }
844 860

  
......
903 919
      $element_text = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
904 920
    }
905 921

  
906
    $annotations_and_sources = handle_annotations_and_sources($element, $feature_block_settings, $element_text, $footnote_list_key_suggestion);
922
    cdm_description_element_render_array_add_annotations_and_sources($render_array, $element, $feature_block_settings, $element_text, $footnote_list_key_suggestion);
907 923

  
908
    $names_used_in_source_markup = '';
909
    if (!empty($annotations_and_sources['names_used_in_source']) && empty($element_text)) {
910
      // $element_text ==  NULL  usually occurs only in the case of CITATIONS!!!
911
      $names_used_in_source_markup = join(', ', $annotations_and_sources['names_used_in_source']) . ': ';
912
    }
924
    return $render_array;
925
  }
913 926

  
914
    $source_references_markup = '';
915
    if(!empty($annotations_and_sources['source_references'])){
916
      $source_references_markup = '<span class="sources">'. join(' ', $annotations_and_sources['source_references']) . '<span>';
917
    }
918 927

  
919
    $render_array['#value'] = $names_used_in_source_markup . $element_text . $source_references_markup;
920
    $render_array['#value_suffix'] = $annotations_and_sources['foot_note_keys'];
928
/**
929
 * Renders a single instance of the type IndividualsAssociations.
930
 *
931
 * @param $element
932
 *   The CDM IndividualsAssociations entity.
933
 * @param $feature_block_settings
934
 *
935
 * @return array
936
 *   Drupal render array
937
 *
938
 * @ingroup compose
939
 */
940
function compose_description_element_individuals_association($element, $feature_block_settings) {
941

  
942
  $out = '';
943
  $enclosing_tag = cdm_feature_block_element_tag_name($feature_block_settings);
921 944

  
922
    return $render_array;
945
  $render_array = compose_cdm_specimenOrObservation($element->associatedSpecimenOrObservation);
946

  
947
  if (isset($element->description_L10n)) {
948
    $out .=  ' ' . $element->description_L10n;
923 949
  }
924 950

  
951
  $out .= drupal_render($render_array);
925 952

  
953
  $annotations_and_sources = handle_annotations_and_sources(
954
    $element,
955
    $feature_block_settings,
956
    $out, // the description element text
957
    $element->feature->uuid
958
  );
959

  
960
  if(!empty($annotations_and_sources['source_references'])){
961
    $out .= ' ' . join(' ', $annotations_and_sources['source_references'] );
962
  }
963
  return '<' . $enclosing_tag . '>' . $out . $annotations_and_sources['foot_note_keys'] . '</' . $enclosing_tag . '>';
926 964

  
927
  /**
928
   * Creates a render array for string representations of description elements for the given feature.
929
   *
930
   * @param array $elements
931
   *   An array of strings. Can be plaintext or markup.
932
   * @param  feature:
933
   *  The feature to which the elements given in $elements are belonging to.
934
   * @param  glue:
935
   *  Defaults to empty string.
936
   * @param $sort
937
   *   Boolean Whether to sort the $elements alphabetically, default is FALSE
938
   * @param  $enclosing_tag
939
   *
940
   * @ingroup compose
941
   */
942
  function compose_feature_block_elements(array $elements, $feature, $glue = '', $sort = FALSE, $enclosing_tag = 'ul') {
965

  
966
}
967

  
968

  
969
/**
970
 * Creates a render array for string representations of description elements for the given feature.
971
 *
972
 * @param array $elements
973
 *   An array of strings. Can be plaintext or markup.
974
 * @param  $feature :
975
 *  The feature to which the elements given in $elements are belonging to.
976
 * @param string $glue :
977
 *  Defaults to empty string.
978
 * @param bool $sort
979
 *   Boolean Whether to sort the $elements alphabetically, default is FALSE
980
 *
981
 * @return array|void
982
 *
983
 * @ingroup compose
984
 */
985
  function compose_feature_block_elements(array $elements, $feature, $glue = '', $sort = FALSE)
986
  {
943 987

  
944 988
    $feature_block_settings = get_feature_block_settings($feature->uuid);
945 989
    if($feature_block_settings['as_list']){
946 990
      $enclosing_tag = $feature_block_settings['as_list'];
991
    } else {
992
      $out = "ERROR</body></html>";
993
      return;
947 994
    }
948 995

  
949 996
    $out = '<' . $enclosing_tag . ' class="feature-block-elements" id="' . $feature->representation_L10n . '">';
......
953 1000
    }
954 1001

  
955 1002
    //TODO it would be nice if any element would get "feature-block-element" as additional class attribute
956
    //     this will become possible once all $elemets are real Drupal render arrays
1003
    //     this will become possible once all $elements are real Drupal render arrays
957 1004
    $out .= join($glue, $elements) ;
958 1005

  
959 1006
    $out .= '</' . $enclosing_tag . '>';
......
1092 1139
              break;
1093 1140
            case 'IndividualsAssociation':
1094 1141
              $feature_block_has_content = true;
1095
              $elements_out_array[] = theme('cdm_descriptionElement_IndividualsAssociation', array('element' => $descriptionElement));
1142
              $elements_out_array[] = compose_description_element_individuals_association($descriptionElement, $feature_block_settings);
1096 1143
              break;
1097 1144
            case 'TaxonInteraction':
1098 1145
              $feature_block_has_content = true;
......
1116 1163

  
1117 1164
    if($feature_block_has_content){
1118 1165
      $render_array = compose_feature_block_elements(
1119
        $elements_out_array,
1120
        $feature
1166
        $elements_out_array, $feature
1121 1167
      );
1122 1168
    }
1123 1169

  
......
1206 1252

  
1207 1253

  
1208 1254
    $common_name_feature_elements_render_array = compose_feature_block_elements(
1209
      $common_name_feature_elements,
1210
      $feature,
1211
      '; ',
1212
      FALSE,
1213
      $feature_block_settings['as_list']
1255
      $common_name_feature_elements, $feature, '; ', FALSE
1214 1256
    );
1215 1257
    $common_name_out .= $common_name_feature_elements_render_array['#markup'];
1216 1258

  
......
1228 1270
  }
1229 1271

  
1230 1272
  $common_name_out_text_data = compose_feature_block_elements(
1231
    $text_data_out,
1232
    $feature
1273
    $text_data_out, $feature
1233 1274
  );
1234 1275

  
1235 1276
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => 'BIBLIOGRAPHY-' . $footnote_key_suggestion));
......
1247 1288
  /**
1248 1289
   * Composes the render array for a CDM Distribution description element
1249 1290
   *
1250
   * @param array $descriptionElements
1291
   * @param array $description_elements
1251 1292
   *   Array of CDM Distribution instances
1252 1293
   * @param $enclosingTag
1253 1294
   *   The html tag to be use for the enclosing element
......
1257 1298
   *
1258 1299
   * @ingroup compose
1259 1300
   */
1260
  function compose_description_elements_distribution($descriptionElements){
1301
  function compose_description_elements_distribution($description_elements){
1261 1302

  
1262 1303
    $out = '';
1263 1304
    RenderHints::pushToRenderStack('descriptionElementDistribution');
......
1266 1307
    $feature_block_settings = get_feature_block_settings(UUID_DISTRIBUTION);
1267 1308
    $enclosingTag = cdm_feature_block_element_tag_name($feature_block_settings);
1268 1309

  
1269
    foreach ($descriptionElements as $descriptionElement) {
1310
    foreach ($description_elements as $description_element) {
1270 1311
      $annotations_and_sources = handle_annotations_and_sources(
1271
        $descriptionElement,
1312
        $description_element,
1272 1313
        $feature_block_settings,
1273
        $descriptionElement->area->representation_L10n,
1314
        $description_element->area->representation_L10n,
1274 1315
        UUID_DISTRIBUTION
1275 1316
      );
1276 1317

  
1277 1318

  
1278
      list($status_label, $status_markup) = distribution_status_label_and_markup($descriptionElement);
1319
      list($status_label, $status_markup) = distribution_status_label_and_markup($description_element);
1279 1320

  
1280
      $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $descriptionElement->uuid
1321
      $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $description_element->uuid
1281 1322
        . ' " title="' . $status_label. '">'
1282
        . $descriptionElement->area->representation_L10n
1323
        . $description_element->area->representation_L10n
1283 1324
        . $status_markup;
1284 1325
      if(!empty($annotations_and_sources['source_references'])){
1285 1326
        $out .= ' ' . join(' ', $annotations_and_sources['source_references'] );

Also available in: Unified diff