Revision 7212f0bc
Added by Andreas Kohlbecker about 5 years ago
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. |
modules/cdm_dataportal/includes/common.inc | ||
---|---|---|
587 | 587 |
return $extensions_render_array; |
588 | 588 |
} |
589 | 589 |
|
590 |
function render_registration($registration){ |
|
591 |
$markup = ''; |
|
592 | 590 |
|
593 |
if(isset($registration->identifier) && $registration->status == 'PUBLISHED'){ |
|
594 |
$office_class_attribute = ''; |
|
595 |
if(isset($registration->institution->titleCache)){ |
|
596 |
$office_class_attribute = 'registration-' . strtolower(preg_replace('/[^a-zA-Z0-9]/', '-', $registration->institution->titleCache)); |
|
597 |
} |
|
598 |
$markup = "<span class=\"registration $office_class_attribute\">" . l($registration->identifier, $registration->identifier) . ', ' |
|
599 |
. preg_replace('/^([^T]*)(.*)$/', '${1}', $registration->registrationDate) |
|
600 |
. '</span>'; |
|
601 |
} |
|
602 |
return $markup; |
|
603 |
} |
modules/cdm_dataportal/includes/name.inc | ||
---|---|---|
547 | 547 |
return $out; |
548 | 548 |
} |
549 | 549 |
|
550 |
|
|
551 |
|
|
552 |
/** |
|
553 |
* Composes information for a registration from a dto object |
|
554 |
* |
|
555 |
* @param $registration_dto |
|
556 |
* @param $with_citation |
|
557 |
* Whether to show the citation. |
|
558 |
* @param $with_identifier |
|
559 |
* Whether to add the identifier to the summary (in enabled) |
|
560 |
* @param $with_compact_summary |
|
561 |
* Whether to display the name and type designations as compact summary or in extended form. |
|
562 |
* |
|
563 |
* @return array |
|
564 |
* A drupal render array with the elements: |
|
565 |
* - 'publication_date_and_office' |
|
566 |
* - 'citation' |
|
567 |
* - 'summary' OR 'name', 'name-relations', 'name_type_designations', 'specimen_table' (depending on parameter $with_compact_summary) |
|
568 |
* @ingroup compose |
|
569 |
*/ |
|
570 |
function compose_registration_dto($registration_dto, $with_citation = true, $with_identifier = false, $with_compact_summary = true) |
|
571 |
{ |
|
572 |
$render_array = array(); |
|
573 |
$media_link_map = array(); |
|
574 |
|
|
575 |
if($with_compact_summary){ |
|
576 |
// summary |
|
577 |
$taggged_text_expanded = cdm_tagged_text_expand_entity_references($registration_dto->summaryTaggedText); |
|
578 |
foreach ($taggged_text_expanded as $tagged_text){ |
|
579 |
if(isset($tagged_text->entityReference->type) && $tagged_text->entityReference->type == 'SpecimenTypeDesignation') { |
|
580 |
$mediaDTOs = cdm_ws_get('typedesignation/$0/media', array($tagged_text->entityReference->uuid)); |
|
581 |
if(isset($mediaDTOs[0]->uri)){ |
|
582 |
$media_url_key = '{link-' . $mediaDTOs[0]->uuid . '}'; |
|
583 |
$tagged_text->text = str_replace('[icon]', '[icon]' . $media_url_key, $tagged_text->text); |
|
584 |
$media_link_map[$media_url_key] = cdm_external_uri($mediaDTOs[0]->uri, true); |
|
585 |
} |
|
586 |
} |
|
587 |
} |
|
588 |
$registation_markup = cdm_tagged_text_to_markup($taggged_text_expanded); |
|
589 |
foreach($media_link_map as $media_url_key => $link){ |
|
590 |
$registation_markup = str_replace($media_url_key, $link, $registation_markup); |
|
591 |
} |
|
592 |
if($with_identifier){ |
|
593 |
$registation_markup .= " " . l ($registration_dto->identifier, $registration_dto->identifier); |
|
594 |
} |
|
595 |
$render_array['summary'] = markup_to_render_array('<p class="registration-summary">' . $registation_markup . "</p>", 0); |
|
596 |
} else { |
|
597 |
// name and typedesignation in detail |
|
598 |
if($registration_dto->nameRef){ |
|
599 |
$name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->nameRef->uuid); |
|
600 |
$render_array['name'] = markup_to_render_array('<p class="name">' . render_taxon_or_name($name) . '</p>', 0); |
|
601 |
$name_relations = cdm_ws_fetch_all(str_replace("$0", $registration_dto->nameRef->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS)); |
|
602 |
$render_array['name_relations'] = markup_to_render_array(render_name_relationships_of($name_relations, $registration_dto->nameRef->uuid, null, false)); |
|
603 |
$render_array['name_relations']['#weight'] = 10; |
|
604 |
} |
|
605 |
if(is_object($registration_dto->orderdTypeDesignationWorkingSets)) { |
|
606 |
$field_unit_uuids = array(); |
|
607 |
$specimen_type_designation_refs = array(); |
|
608 |
$name_type_designation_refs = array(); |
|
609 |
foreach ((array)$registration_dto->orderdTypeDesignationWorkingSets as $field_unit_ref => $obj) { |
|
610 |
$tokens = explode("#", $field_unit_ref); |
|
611 |
foreach ($obj as $type_status => $entity_reference_list) { |
|
612 |
// NOTE: there is always only one element, since we use the foreach to extract the objects field name and value |
|
613 |
$entity_reference = $entity_reference_list[0]; |
|
614 |
} |
|
615 |
if ($tokens[0] == 'NameTypeDesignation') { |
|
616 |
foreach ($obj as $type_status => $entity_reference_list) { |
|
617 |
$name_type_designation_refs[$type_status] = $entity_reference; |
|
618 |
} |
|
619 |
} else if ($tokens[0] == 'FieldUnit'){ |
|
620 |
$field_unit_uuids[] = $tokens[1]; |
|
621 |
$specimen_type_designation_refs[$type_status] = $entity_reference; |
|
622 |
} else { |
|
623 |
drupal_set_message("Unimplemented type: " . $tokens[0], 'error'); |
|
624 |
} |
|
625 |
} |
|
626 |
if (count($name_type_designation_refs) > 0) { |
|
627 |
$render_array['name_type_designations'] = compose_name_type_designations($name_type_designation_refs); |
|
628 |
$render_array['name_type_designations']['#prefix'] = '<p class="name_type_designations">'; |
|
629 |
$render_array['name_type_designations']['#suffix'] = '</p>'; |
|
630 |
$render_array['name_type_designations']['#weight'] = 20; |
|
631 |
} |
|
632 |
if (count($field_unit_uuids) > 0) { |
|
633 |
$render_array['specimen_type_designations'] = compose_specimen_type_designations($specimen_type_designation_refs); |
|
634 |
// $render_array['specimen_table'] = compose_specimen_table($field_unit_uuids); |
|
635 |
// below citation (weight=20) |
|
636 |
$render_array['specimen_table']['#weight'] = 21; |
|
637 |
} |
|
638 |
} |
|
639 |
} |
|
640 |
|
|
641 |
// citation |
|
642 |
if ($with_citation) { |
|
643 |
$render_array['citation'] = markup_to_render_array( |
|
644 |
"<p class=\"citation " . html_class_attribute_ref(new TypedEntityReference("Reference", $registration_dto->citationUuid)) . "\">" |
|
645 |
. l($registration_dto->bibliographicInRefCitationString, path_to_reference($registration_dto->citationUuid)) |
|
646 |
. "</p>", |
|
647 |
50); |
|
648 |
} |
|
649 |
|
|
650 |
// registration date and office |
|
651 |
if($registration_dto->registrationDate){ |
|
652 |
$date_string = format_datetime($registration_dto->registrationDate); |
|
653 |
if(isset($registration_dto->institutionTitleCache) && $registration_dto->institutionTitleCache){ |
|
654 |
$registration_date_insitute_markup = |
|
655 |
t("Registration on @date in @institution", array( |
|
656 |
'@date' => $date_string, |
|
657 |
'@institution' => $registration_dto->institutionTitleCache, |
|
658 |
)); |
|
659 |
} else { |
|
660 |
$registration_date_insitute_markup = |
|
661 |
t("Registration on @date", array( |
|
662 |
'@date' => $date_string |
|
663 |
)); |
|
664 |
} |
|
665 |
$render_array['publication_date_and_office'] = markup_to_render_array( |
|
666 |
'<p class"date-and-institute">'.$registration_date_insitute_markup . '</p>', |
|
667 |
100); |
|
668 |
} |
|
669 |
|
|
670 |
return $render_array; |
|
671 |
} |
|
672 |
|
|
673 |
|
|
550 | 674 |
/** |
551 | 675 |
* @param $registrations |
552 | 676 |
* @return string |
... | ... | |
566 | 690 |
} |
567 | 691 |
|
568 | 692 |
|
693 |
/** |
|
694 |
* Renders a registration |
|
695 |
* |
|
696 |
* @param $registration |
|
697 |
*/ |
|
698 |
function render_registration($registration){ |
|
699 |
$markup = ''; |
|
700 |
|
|
701 |
if(isset($registration->identifier) && $registration->status == 'PUBLISHED'){ |
|
702 |
$office_class_attribute = ''; |
|
703 |
if(isset($registration->institution->titleCache)){ |
|
704 |
$office_class_attribute = 'registration-' . strtolower(preg_replace('/[^a-zA-Z0-9]/', '-', $registration->institution->titleCache)); |
|
705 |
} |
|
706 |
$markup = "<span class=\"registration $office_class_attribute\">" . l($registration->identifier, $registration->identifier) . ', ' |
|
707 |
. preg_replace('/^([^T]*)(.*)$/', '${1}', $registration->registrationDate) |
|
708 |
. '</span>'; |
|
709 |
} |
|
710 |
return $markup; |
|
711 |
} |
|
712 |
|
|
713 |
|
|
569 | 714 |
/** |
570 | 715 |
* Composes the TypedEntityReference to name type designations passed as associatve array. |
571 | 716 |
* |
Also available in: Unified diff
moving methods regarding registrations to name.inc