Project

General

Profile

Revision 26b8a1bc

ID26b8a1bcd81a577d5852fc97dde4bca88b9566b0
Parent 7212f0bc
Child 12466422

Added by Andreas Kohlbecker 6 months ago

ref #8051 harmonizing registrationDTO composition and splitting full and compact style into separate methods

View differences:

modules/cdm_dataportal/includes/name.inc
550 550

  
551 551

  
552 552
/**
553
 * Composes information for a registration from a dto object
553
 * Composes information for a registration from a dto object.
554
 *
555
 * Registrations which are not yet published are suppressed.
554 556
 *
555 557
 * @param $registration_dto
556 558
 * @param $with_citation
557 559
 *   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 560
 *
563 561
 * @return array
564 562
 *    A drupal render array with the elements:
565
 *    - 'publication_date_and_office'
563
 *    - 'name'
564
 *    - 'name-relations'
565
 *    - 'specimen_type_designations'
566
 *    - 'name_type_designations'
566 567
 *    - 'citation'
567
 *    - 'summary' OR  'name', 'name-relations', 'name_type_designations', 'specimen_table' (depending on parameter $with_compact_summary)
568
 *    - 'registration_date_and_institute'
568 569
 * @ingroup compose
569 570
 */
570
function compose_registration_dto($registration_dto, $with_citation = true, $with_identifier = false, $with_compact_summary = true)
571
function compose_registration_dto_full($registration_dto, $with_citation = true)
571 572
{
572 573
  $render_array = array();
573
  $media_link_map = array();
574 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
        }
575
  if(!(isset($registration_dto->identifier) && $registration_dto->status == 'PUBLISHED')){
576
    return $render_array;
577
  }
578

  
579
  // name and typedesignation in detail
580
  if($registration_dto->nameRef){
581
    $name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->nameRef->uuid);
582
    $render_array['name'] = markup_to_render_array('<p class="name">' . render_taxon_or_name($name) . '</p>', 0);
583
    $name_relations = cdm_ws_fetch_all(str_replace("$0", $registration_dto->nameRef->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
584
    $render_array['name_relations'] = markup_to_render_array(render_name_relationships_of($name_relations, $registration_dto->nameRef->uuid, null, false));
585
    $render_array['name_relations']['#weight'] = 10;
586
  }
587
  if(is_object($registration_dto->orderdTypeDesignationWorkingSets)) {
588
    $field_unit_uuids = array();
589
    $specimen_type_designation_refs = array();
590
    $name_type_designation_refs = array();
591
    foreach ((array)$registration_dto->orderdTypeDesignationWorkingSets as $field_unit_ref => $obj) {
592
      $tokens = explode("#", $field_unit_ref);
593
      foreach ($obj as $type_status => $entity_reference_list) {
594
        // NOTE: there is always only one element, since we use the foreach to extract the objects field name and value
595
        $entity_reference = $entity_reference_list[0];
586 596
      }
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);
597
      if ($tokens[0] == 'NameTypeDesignation') {
611 598
        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');
599
          $name_type_designation_refs[$type_status] = $entity_reference;
624 600
        }
601
      } else if ($tokens[0] == 'FieldUnit'){
602
        $field_unit_uuids[] = $tokens[1];
603
        $specimen_type_designation_refs[$type_status] = $entity_reference;
604
      } else {
605
        drupal_set_message("Unimplemented type: " . $tokens[0], 'error');
625 606
      }
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
      }
607
    }
608
    if (count($name_type_designation_refs) > 0) {
609
      $render_array['name_type_designations'] = compose_name_type_designations($name_type_designation_refs);
610
      $render_array['name_type_designations']['#prefix'] = '<p class="name_type_designations">';
611
      $render_array['name_type_designations']['#suffix'] = '</p>';
612
      $render_array['name_type_designations']['#weight'] = 20;
613
    }
614
    if (count($field_unit_uuids) > 0) {
615
      $render_array['specimen_type_designations'] = compose_specimen_type_designations($specimen_type_designation_refs);
638 616
    }
639 617
  }
640 618

  
......
648 626
  }
649 627

  
650 628
  // registration date and office
651
  if($registration_dto->registrationDate){
629
  $registration_date_insitute_markup = render_registration_date_and_intitute($registration_dto);
630
  if($registration_date_insitute_markup){
631
    $render_array['registration_date_and_institute'] = markup_to_render_array(
632
      $registration_date_insitute_markup . '</p>',
633
      100);
634
  }
635

  
636
  return $render_array;
637
}
638

  
639

  
640
/**
641
 * Composes a compact representation for a registrationDTO object
642
 *
643
 * Registrations which are not yet published are suppressed.
644
 *
645
 * @param $registration_dto
646
 * @param $style string
647
 *   The style of how to compose the 'identifier' and 'registration_date_and_institute' part with the summary
648
 *   - 'citation': Similar to the arrearance of nomenclatural acts in print media
649
 *   - 'list-item' : style suitable for result lists etc
650
 *
651
 * @return array
652
 *    A drupal render array with the elements:
653
 *    - 'registration-metadata' when $style == 'list-item'
654
 *    - 'summary'
655
 * @ingroup compose
656
 */
657
function compose_registration_dto_compact($registration_dto, $style = 'citation', $tag_enclosing_summary = 'p')
658
{
659
  $render_array = array();
660
  $media_link_map = array();
661

  
662
  if(!(isset($registration_dto->identifier) && $registration_dto->status == 'PUBLISHED')){
663
    return $render_array;
664
  }
665

  
666
  $registration_date_insitute_markup = render_registration_date_and_intitute($registration_dto, 'span');
667
  $itentifier_markup = l($registration_dto->identifier, $registration_dto->identifier, array('attributes' => array('class' => array('identifier'))));
668

  
669
  $taggged_text_expanded = cdm_tagged_text_expand_entity_references($registration_dto->summaryTaggedText);
670
  foreach ($taggged_text_expanded  as $tagged_text){
671
    if(isset($tagged_text->entityReference->type) && $tagged_text->entityReference->type == 'SpecimenTypeDesignation') {
672
      $mediaDTOs = cdm_ws_get('typedesignation/$0/media', array($tagged_text->entityReference->uuid));
673
      if(isset($mediaDTOs[0]->uri)){
674
        $media_url_key = '{link-' . $mediaDTOs[0]->uuid . '}';
675
        $tagged_text->text = str_replace('[icon]', '[icon]' . $media_url_key, $tagged_text->text);
676
        $media_link_map[$media_url_key] =  cdm_external_uri($mediaDTOs[0]->uri, true);
677
      }
678
    }
679
  }
680
  $registation_markup = cdm_tagged_text_to_markup($taggged_text_expanded);
681
  foreach($media_link_map as $media_url_key => $link){
682
    $registation_markup = str_replace($media_url_key, $link, $registation_markup);
683
  }
684
  if($style == 'citation') {
685
    $registation_markup = $registation_markup . ' ' . $itentifier_markup . ' ' . $registration_date_insitute_markup;
686
  } else {
687
    $render_array['registration-metadata'] = markup_to_render_array('<div class="registration-metadata">' . $itentifier_markup . ' ' . $registration_date_insitute_markup. "</div>", -10);
688
  }
689
  $render_array['summary'] = markup_to_render_array('<' . $tag_enclosing_summary . 'class="registration-summary">' . $registation_markup . "</' . $tag_enclosing_summary . '>", 0);
690

  
691
  return $render_array;
692
}
693

  
694

  
695
/**
696
 * Renders the registrationDate and institutionTitleCache of the $registration_dto as markup.
697
 *
698
 * @param $registration_dto
699
 * @return string
700
 *    The markup or an empty string
701
 */
702
function render_registration_date_and_intitute($registration_dto, $enclosing_tag = 'p') {
703
  $registration_date_insitute_markup = '';
704
  if ($registration_dto->registrationDate) {
652 705
    $date_string = format_datetime($registration_dto->registrationDate);
653
    if(isset($registration_dto->institutionTitleCache) && $registration_dto->institutionTitleCache){
706
    if (isset($registration_dto->institutionTitleCache) && $registration_dto->institutionTitleCache) {
654 707
      $registration_date_insitute_markup =
655 708
        t("Registration on @date in @institution", array(
656 709
          '@date' => $date_string,
......
662 715
          '@date' => $date_string
663 716
        ));
664 717
    }
665
    $render_array['publication_date_and_office'] = markup_to_render_array(
666
      '<p class"date-and-institute">'.$registration_date_insitute_markup . '</p>',
667
      100);
718
    $registration_date_insitute_markup = '<' .$enclosing_tag . ' class="registration-date-and-institute">'. $registration_date_insitute_markup . '</' .$enclosing_tag . '>';
668 719
  }
669

  
670
  return $render_array;
720
  return $registration_date_insitute_markup;
671 721
}
672 722

  
673 723

  
......
693 743
/**
694 744
 * Renders a registration
695 745
 *
746
 * TODO replace by compose_registration_dto_compact
696 747
 * @param $registration
697 748
 */
698 749
function render_registration($registration){
......
701 752
  if(isset($registration->identifier) && $registration->status == 'PUBLISHED'){
702 753
    $office_class_attribute = '';
703 754
    if(isset($registration->institution->titleCache)){
704
      $office_class_attribute = 'registration-' . strtolower(preg_replace('/[^a-zA-Z0-9]/', '-', $registration->institution->titleCache));
755
      $office_class_attribute = registration_intitute_class_attribute($registration);
705 756
    }
706 757
    $markup = "<span class=\"registration $office_class_attribute\">" . l($registration->identifier, $registration->identifier) . ', '
707 758
      .  preg_replace('/^([^T]*)(.*)$/', '${1}', $registration->registrationDate)
......
710 761
  return $markup;
711 762
}
712 763

  
764
/**
765
 * @param $registration
766
 * @return string
767
 */
768
function registration_intitute_class_attribute($registration_dto)
769
{
770
  if(isset($registration_dto->institutionTitleCache)){
771
    $institutionTitleCache = $registration_dto->institutionTitleCache;
772
  } else {
773
    // fall back option to also support cdm entities
774
    $institutionTitleCache = @$registration_dto->institution->titleCache;
775
  }
776
  return $institutionTitleCache ? 'registration-' . strtolower(preg_replace('/[^a-zA-Z0-9]/', '-', $institutionTitleCache)) : '';
777
}
778

  
713 779

  
714 780
/**
715 781
 * Composes the TypedEntityReference to name type designations passed as associatve array.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)