Project

General

Profile

Revision 7212f0bc

ID7212f0bc72696c2077b6a17cb886e70d541d5067
Parent f8283d8a
Child 26b8a1bc

Added by Andreas Kohlbecker almost 3 years ago

moving methods regarding registrations to name.inc

View differences:

modules/cdm_dataportal/cdm_dataportal.module
1957 1957
  return $render_array ;
1958 1958
}
1959 1959

  
1960
/**
1961
 * Composes information for a registration from a dto object
1962
 *
1963
 * @param $registration_dto
1964
 * @param $with_citation
1965
 *   Whether to show the citation.
1966
 * @param $with_identifier
1967
 *   Whether to add the identifier to the summary (in enabled)
1968
 * @param $with_compact_summary
1969
 *   Whether to display the name and type designations as compact summary or in extended form.
1970
 *
1971
 * @return array
1972
 *    A drupal render array with the elements:
1973
 *    - 'publication_date_and_office'
1974
 *    - 'citation'
1975
 *    - 'summary' OR  'name', 'name-relations', 'name_type_designations', 'specimen_table' (depending on parameter $with_compact_summary)
1976
 * @ingroup compose
1977
 */
1978
function compose_registration_dto($registration_dto, $with_citation = true, $with_identifier = false, $with_compact_summary = true)
1979
{
1980
  $render_array = array();
1981
  $media_link_map = array();
1982

  
1983

  
1984

  
1985
  if($with_compact_summary){
1986
    // summary
1987
    $taggged_text_expanded = cdm_tagged_text_expand_entity_references($registration_dto->summaryTaggedText);
1988
    foreach ($taggged_text_expanded  as $tagged_text){
1989
      if(isset($tagged_text->entityReference->type) && $tagged_text->entityReference->type == 'SpecimenTypeDesignation') {
1990
        $mediaDTOs = cdm_ws_get('typedesignation/$0/media', array($tagged_text->entityReference->uuid));
1991
        if(isset($mediaDTOs[0]->uri)){
1992
            $media_url_key = '{link-' . $mediaDTOs[0]->uuid . '}';
1993
            $tagged_text->text = str_replace('[icon]', '[icon]' . $media_url_key, $tagged_text->text);
1994
            $media_link_map[$media_url_key] =  cdm_external_uri($mediaDTOs[0]->uri, true);
1995
        }
1996
      }
1997
    }
1998
    $registation_markup = cdm_tagged_text_to_markup($taggged_text_expanded);
1999
    foreach($media_link_map as $media_url_key => $link){
2000
      $registation_markup = str_replace($media_url_key, $link, $registation_markup);
2001
    }
2002
    if($with_identifier){
2003
      $registation_markup .= " " . l ($registration_dto->identifier, $registration_dto->identifier);
2004
    }
2005
    $render_array['summary'] = markup_to_render_array('<p class="registration-summary">' . $registation_markup . "</p>", 0);
2006
  } else {
2007
    // name and typedesignation in detail
2008
    if($registration_dto->nameRef){
2009
      $name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->nameRef->uuid);
2010
      $render_array['name'] = markup_to_render_array('<p class="name">' . render_taxon_or_name($name) . '</p>', 0);
2011
      $name_relations = cdm_ws_fetch_all(str_replace("$0", $registration_dto->nameRef->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
2012
      $render_array['name_relations'] = markup_to_render_array(render_name_relationships_of($name_relations, $registration_dto->nameRef->uuid, null, false));
2013
      $render_array['name_relations']['#weight'] = 10;
2014
    }
2015
    if(is_object($registration_dto->orderdTypeDesignationWorkingSets)) {
2016
      $field_unit_uuids = array();
2017
      $specimen_type_designation_refs = array();
2018
      $name_type_designation_refs = array();
2019
      foreach ((array)$registration_dto->orderdTypeDesignationWorkingSets as $field_unit_ref => $obj) {
2020
        $tokens = explode("#", $field_unit_ref);
2021
        foreach ($obj as $type_status => $entity_reference_list) {
2022
          // NOTE: there is always only one element, since we use the foreach to extract the objects field name and value
2023
          $entity_reference = $entity_reference_list[0];
2024
        }
2025
        if ($tokens[0] == 'NameTypeDesignation') {
2026
          foreach ($obj as $type_status => $entity_reference_list) {
2027
            $name_type_designation_refs[$type_status] = $entity_reference;
2028
          }
2029
        } else if ($tokens[0] == 'FieldUnit'){
2030
          $field_unit_uuids[] = $tokens[1];
2031
          $specimen_type_designation_refs[$type_status] = $entity_reference;
2032
        } else {
2033
          drupal_set_message("Unimplemented type: " . $tokens[0], 'error');
2034
        }
2035
      }
2036
      if (count($name_type_designation_refs) > 0) {
2037
        $render_array['name_type_designations'] = compose_name_type_designations($name_type_designation_refs);
2038
        $render_array['name_type_designations']['#prefix'] = '<p class="name_type_designations">';
2039
        $render_array['name_type_designations']['#suffix'] = '</p>';
2040
        $render_array['name_type_designations']['#weight'] = 20;
2041
      }
2042
      if (count($field_unit_uuids) > 0) {
2043
        $render_array['specimen_type_designations'] = compose_specimen_type_designations($specimen_type_designation_refs);
2044
        // $render_array['specimen_table'] = compose_specimen_table($field_unit_uuids);
2045
        // below citation (weight=20)
2046
        $render_array['specimen_table']['#weight'] = 21;
2047
      }
2048
    }
2049
  }
2050

  
2051
  // citation
2052
  if ($with_citation) {
2053
    $render_array['citation'] = markup_to_render_array(
2054
      "<p class=\"citation " . html_class_attribute_ref(new TypedEntityReference("Reference", $registration_dto->citationUuid)) . "\">"
2055
      . l($registration_dto->bibliographicInRefCitationString, path_to_reference($registration_dto->citationUuid))
2056
      . "</p>",
2057
      50);
2058
  }
2059

  
2060
  // registration date and office
2061
  if($registration_dto->registrationDate){
2062
    $date_string = format_datetime($registration_dto->registrationDate);
2063
    if(isset($registration_dto->institutionTitleCache) && $registration_dto->institutionTitleCache){
2064
      $registration_date_insitute_markup =
2065
        t("Registration on @date in @institution", array(
2066
          '@date' => $date_string,
2067
          '@institution' => $registration_dto->institutionTitleCache,
2068
        ));
2069
    } else {
2070
      $registration_date_insitute_markup =
2071
        t("Registration on @date", array(
2072
          '@date' => $date_string
2073
        ));
2074
    }
2075
    $render_array['publication_date_and_office'] = markup_to_render_array(
2076
      '<p class"date-and-institute">'.$registration_date_insitute_markup . '</p>',
2077
      100);
2078
  }
2079

  
2080
  return $render_array;
2081
}
2082

  
2083 1960

  
2084 1961
/**
2085 1962
 * Creates a page with the advance search form.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)