Project

General

Profile

« Previous | Next » 

Revision 44d445c0

Added by Andreas Kohlbecker over 9 years ago

refactoring the handling of annotations, sources and name in source information. cleaner and simpler code, less complex statements and preserving at the same time existing output, except that the ticket #2288 (Cyprus: ChromosomeNumbers: formating nameInSource) has been solved

View differences:

7.x/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
312 312
          }
313 313
        }
314 314
        ksort($distributionElements);
315
        $dto_out_array[] = theme('cdm_descriptionElement_Distribution', array(
316
          'descriptionElements' => $distributionElements,
317
        ));
315
        $distribution_element_render_array = compose_cdm_descriptionElement_Distribution($distributionElements);
316
        $dto_out_array[] = drupal_render($distribution_element_render_array);
318 317

  
319 318
      }
320 319
      //
......
421 420

  
422 421
  //TODO it would be nice if any element would get "feature-block-element" as additional class attribute
423 422
  //     this will become possible once all $elemets are real Drupal render arrays
424
  $out .= join($elements, $glue) ;
423
  $out .= join($glue, $elements) ;
425 424

  
426 425
  $out .= '</' . $enclosing_tag . '>';
427 426
  return markup_to_render_array($out);
......
592 591
}
593 592

  
594 593
/**
595
 * Returns HTML for citations textdata elements.
596
 *
597
 * TODO: assign a new name to the function? Because it is used for the citations
598
 * Textdata elements and not for all text data description elements.
594
 * Composes a drupal render array for CDM TextData description elements.
599 595
 *
600 596
 * @param $element
601 597
 *    The CDM TextData description element which contains the textual  information.
......
619 615

  
620 616
  $footnote_list_key_suggestion = $feature_uuid;
621 617

  
622
  $sourceRefs = '';
623
  $name_used_in_source = '';
624

  
625 618
  // FIXME $feature_block_settings should be passed as parameter!!!!!
626 619
  $feature_block_settings = get_feature_block_settings($feature_uuid);
627 620
  $do_references_inline = $feature_block_settings['sources_as_content'];
......
645 638
    '#value_suffix' => NULL
646 639
  );
647 640

  
648
  // TODO this should be configurable
649
  $description = '';
641
  $element_text = '';
650 642
  if (isset($element->multilanguageText_L10n->text)) {
651
    $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
643
    // TODO replacement of \n by <br> should be configurable
644
    $element_text = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
652 645
  }
653 646

  
654
  // original sources
655
  if($do_references_inline) {
656
    foreach ($element->sources as $source) {
647
  $annotations_and_sources = handle_annotations_and_sources($element, $do_references_inline, $feature_block_settings, $element_text, $footnote_list_key_suggestion);
657 648

  
658
      $referenceCitation = theme('cdm_OriginalSource',
659
        array(
660
          'source' => $source,
661
          'doLink' => $feature_block_settings['link_to_reference']
662
        )
663
      );
649
  $names_used_in_source_markup = '';
650
  if (!empty($annotations_and_sources['names_used_in_source']) && empty($element_text)) {
651
    // $element_text ==  NULL  usually occurs only in the case of CITATIONS!!!
652
    $names_used_in_source_markup = join(', ', $annotations_and_sources['names_used_in_source']) . ': ';
653
  }
664 654

  
665
      if ($description && strlen($description) > 0 && $referenceCitation) {
666
        $sourceRefs .= ' (' . $referenceCitation . ')';
667
      }
668
      elseif ($referenceCitation) {
669
        $sourceRefs = $referenceCitation;
670
      }
655
  $source_references_markup = '';
656
  if(!empty($annotations_and_sources['source_references'])){
657
    $source_references_markup = '<span class="sources">'. join(' ', $annotations_and_sources['source_references']) . '<span>';
658
  }
671 659

  
672
      if (strlen($sourceRefs) > 0) {
673
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
674
      }
660
  $render_array['#value'] = $names_used_in_source_markup . $element_text . $source_references_markup;
661
  $render_array['#value-suffix'] = $annotations_and_sources['foot_note_keys'];
675 662

  
676
      // link the nameUsedInSource to the according name page
677
      // Do a link to name page.
678
      if (isset($source->nameUsedInSource->uuid) && isset($source->nameUsedInSource->titleCache)) {
679
        // it is a DescriptionElementSource
680
        if($feature_block_settings['link_to_name_used_in_source']){
681
          $name_used_in_source = l(
682
            $source->nameUsedInSource->titleCache,
683
            path_to_name($source->nameUsedInSource->uuid),
684
            array(
685
              'attributes' => array(),
686
              'absolute' => TRUE,
687
              'html' => TRUE,
688
            ));
663
  return $render_array;
664
}
689 665

  
690
        } else {
691
          $name_used_in_source = $source->nameUsedInSource->titleCache;
692
        }
693
      }
694
      else if (isset($source->nameUsedInSource->originalNameString) && strlen($source->nameUsedInSource->originalNameString) > 0) {
695
        // TODO does this make sense? is $source->nameUsedInSource->originalNameString different from $source->nameUsedInSource->titleCache ?
696
        // it is NOT a DescriptionElementSource
697
        // Show a text without link.
698
        $name_used_in_source = $source->nameUsedInSource->originalNameString;
699
      }
700
    } // END of loop over sources
701

  
702
    // annotations footnotes separate.
703
    $render_array['#value-suffix'] = theme('cdm_annotations_as_footnotekeys',
704
      array(
705
        'cdmBase_list' => $element,
706
        'footnote_list_key' => $footnote_list_key_suggestion,
707
      )
666
  /**
667
   * @param $element
668
   * @param $do_references_inline
669
   * @param $feature_block_settings
670
   * @param $element_text
671
   * @param $footnote_list_key_suggestion
672
   * @return array
673
   *   an associative array with the following elements:
674
   *   - foot_note_keys: all footnote keys as markup
675
   *   - source_references: an array of the source references citations
676
   *   - names used in source: an associative array of the names in source,
677
   *        the name in source string are deduplicated
678
   *        !!!NOTE!!!!: this field will most probably be removed soon (TODO)
679
   *
680
   * 
681
   */
682
  function handle_annotations_and_sources($element, $do_references_inline, $feature_block_settings, $element_text, $footnote_list_key_suggestion) {
683
    $annotations_and_sources = array(
684
      'foot_note_keys' => NULL,
685
      'source_references' => array(),
686
      'names_used_in_source' => array()
708 687
    );
709 688

  
710
  } // END of references inline
689
    if ($do_references_inline) {
690
      foreach ($element->sources as $source) {
711 691

  
712
  if(!$do_references_inline || $feature_block_settings['sources_as_content_to_bibliography']) {
713
    $render_array['#value-suffix'] = cdm_create_description_element_footnotes($element, ',', $footnote_list_key_suggestion);
714
  }
692
        $referenceCitation = theme('cdm_OriginalSource',
693
          array(
694
            'source' => $source,
695
            'doLink' => $feature_block_settings['link_to_reference']
696
          )
697
        );
715 698

  
699
        if ($referenceCitation) {
700
          if (empty($element_text)) {
701
            $annotations_and_sources['source_references'][] = $referenceCitation;
702
          }
703
          else {
704
            $annotations_and_sources['source_references'][] = ' (' . $referenceCitation . ')';
705
          }
706
        }
716 707

  
717
  // FIXME the only distinction between $asListElement = TRUE and FLASE is the different display of the
718
  // nameInSource which is prepended with "name in source:" in case of the 'not as list' case:
719
  if ($asListElement) {
720
    // Adding ":" if necessary.
721
    if (!empty($name_used_in_source)) {
722
      if ( (!empty($description)|| !empty($sourceRefs)) && $feature_uuid != UUID_CHROMOSOMES_NUMBERS) {
723
        $render_array['#value'] = $name_used_in_source . ': ';
724
      } else {
725
        $render_array['#value'] .= $name_used_in_source . ' ';
726
      }
727
    }
728
    $render_array['#value'] .= $description . $sourceRefs;
729
  }
730
  else {
731
    if ($name_used_in_source) {
732
      $name_used_in_source = ' (name in source: ' . $name_used_in_source . ')';
708
        if (isset($source->nameUsedInSource->uuid) && isset($source->nameUsedInSource->titleCache)) {
709
          // it is a DescriptionElementSource
710
          if ($feature_block_settings['link_to_name_used_in_source']) {
711
            // using the titleCache as key to avoid duplicate entries
712
            $annotations_and_sources['names_used_in_source'][$source->nameUsedInSource->titleCache] = l(
713
              $source->nameUsedInSource->titleCache,
714
              path_to_name($source->nameUsedInSource->uuid),
715
              array(
716
                'attributes' => array(),
717
                'absolute' => TRUE,
718
                'html' => TRUE,
719
              ));
720
          }
721
          else {
722
            // using the titleCache as key to avoid duplicate entries
723
            $annotations_and_sources['names_used_in_source'][$source->nameUsedInSource->titleCache] = $source->nameUsedInSource->titleCache;
724
          }
725
        }
726
        else if (isset($source->originalNameString) && !empty($source->originalNameString)) {
727
          // the name used in source can not be expressed as valid taxon name,
728
          // so the editor has chosen to put the freetext name into ReferencedEntityBase.originalNameString
729
          // field
730
          // using the originalNameString as key to avoid duplicate entries
731
          $annotations_and_sources['names_used_in_source'][$source->originalNameString] = $source->originalNameString;
732
        }
733
      } // END of loop over sources
734

  
735
      // annotations footnotes separate.
736
      $annotations_and_sources['foot_note_keys'] = theme('cdm_annotations_as_footnotekeys',
737
        array(
738
          'cdmBase_list' => $element,
739
          'footnote_list_key' => $footnote_list_key_suggestion,
740
        )
741
      );
742

  
743
    } // END of references inline
744

  
745
    if (!$do_references_inline || $feature_block_settings['sources_as_content_to_bibliography']) {
746
      $annotations_and_sources['foot_note_keys'] = cdm_create_description_element_footnotes($element, ',', $footnote_list_key_suggestion);
747
      return $annotations_and_sources;
733 748
    }
734
    $render_array['#value'] = $description . $sourceRefs . $name_used_in_source;
749
    return $annotations_and_sources;
735 750
  }
736 751

  
737
  return $render_array;
738
}
739

  
740
/**
752
  /**
741 753
 * Composes block of common names for the given DescriptionElements $elements which must be of the feature CommonName
742 754
 *
743 755
 * @parameter $elements
......
1029 1041
}
1030 1042

  
1031 1043
/**
1032
 * @todo Please document this function.
1033
 * @see http://drupal.org/node/1354
1044
 * Composes the render array for a CDM Distribution element
1045
 *
1046
 * @param $descriptionElements
1047
 *   The CDM Distribution element
1048
 * @param $enclosingTag
1049
 *   The html tag to be use for the enclosing element
1050
 *
1051
 * @return array
1052
 *   A Drupal render array
1053
 *
1054
 * @ingroup compose
1034 1055
 */
1035
function theme_cdm_descriptionElement_Distribution($variables) {
1036
  $descriptionElements = $variables['descriptionElements'];
1037
  $enclosingTag = $variables['enclosingTag'];
1038
  if (!$enclosingTag) {
1039
    $enclosingTag = "span";
1040
  }
1056
function compose_cdm_descriptionElement_Distribution($descriptionElements, $enclosingTag = "span"){
1041 1057

  
1042 1058
  $out = '';
1043 1059
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1044 1060
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1045 1061

  
1046 1062
  foreach ($descriptionElements as $descriptionElement) {
1047

  
1048 1063
    $footnote_key_list_str = cdm_create_description_element_footnotes($descriptionElement);
1049 1064

  
1050 1065
    $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $descriptionElement->uuid . '">'
......
1053 1068
  }
1054 1069

  
1055 1070
  RenderHints::popFromRenderStack();
1056
  return $out;
1071
  return markup_to_render_array($out);
1057 1072
}
1058 1073

  
1059 1074

  
......
1212 1227
  return $out;
1213 1228
}
1214 1229

  
1215

  
1216
/*
1217
function theme_cdm_descriptionElement_Distribution($descriptionElements){ $out
1218
  = ''; $separator = ',';
1219
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1220
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1221
  foreach($descriptionElements as $descriptionElement){ // annotations as
1222
  footnotes $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys',
1223
  $descriptionElement); // source references as footnotes
1224
  $sourcesFootnoteKeyList = ''; foreach($descriptionElement->sources as
1225
  $source){ if(_is_original_source_type($source)){ $_fkey =
1226
  FootnoteManager::addNewFootnote(UUID_DISTRIBUTION,
1227
  theme('cdm_OriginalSource', $source, FALSE));
1228
  $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey,
1229
  UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : '')); } }
1230
  if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
1231
  $annotationFootnoteKeys .= $separator; } $out .=
1232
  $descriptionElement->area->representation_L10n . $annotationFootnoteKeys .
1233
  $sourcesFootnoteKeyList . ' '; } $out = substr($out, 0,
1234
  strlen($out)-strlen($separator) ); RenderHints::popFromRenderStack(); return
1235
  $out; }
1236
*/
1237

  
1238 1230
/**
1239 1231
 * Returns a list of a specific type of IdentificationKeys.
1240 1232
 *

Also available in: Unified diff