Project

General

Profile

« Previous | Next » 

Revision ef686dd8

Added by Andreas Kohlbecker almost 5 years ago

fix #7975 fix #8196 name relationships list representation implemented

View differences:

modules/cdm_dataportal/includes/name.inc
581 581
    $name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->nameRef->uuid);
582 582
    $render_array['published_name'] = markup_to_render_array('<p class="published-name">' . render_taxon_or_name($name) . '</p>', 0);
583 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_inline($name_relations, $registration_dto->nameRef->uuid, null, false));
584
    $render_array['name_relations'] = compose_name_relationships_list($name_relations, $registration_dto->nameRef->uuid, null, false);
585 585
    $render_array['name_relations']['#weight'] = 10;
586 586
  } else {
587 587
    // in this case the registration must have a
......
907 907
}
908 908

  
909 909
/**
910
 * Renders an inline representation of the name relationships.
910
 * @param $name_rel
911
 * @param $current_name_uuid
912
 * @param $current_taxon_uuid
913
 * @param $suppress_if_current_name_is_source // FIXME UNUSED !!!!
914
 * @param $show_name_cache_only
915
 *    The nameCache will be shown instead of the titleCache if this parameter is true.
916
 * @return null|string
917
 */
918
function name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source, $show_name_cache_only = false){
919

  
920
  $relationship_markup = null;
921

  
922
  $current_name_is_toName = $current_name_uuid == $name_rel->toName->uuid;
923

  
924
  if($current_name_is_toName){
925
    $name = $name_rel->fromName;
926
  } else {
927
    $name = $name_rel->toName;
928
  }
929

  
930
  $highlited_synonym_uuid = isset ($name->taxonBases[0]->uuid) ? $name->taxonBases[0]->uuid : '';
931
  if(!$show_name_cache_only){
932
    $relationship_markup = render_taxon_or_name($name,
933
      url(path_to_name($name->uuid, $current_taxon_uuid, $highlited_synonym_uuid))
934
    );
935
  } else {
936
    $relationship_markup = l(
937
      '<span class="' . html_class_attribute_ref($name) . '"">' . $name->nameCache . '</span>',
938
      path_to_name($name->uuid, $current_taxon_uuid, $highlited_synonym_uuid),
939
      array('html' => true)
940
    );
941
  }
942

  
943
  return $relationship_markup;
944
}
945

  
946

  
947
/**
948
 * Renders an inline representation of selected name relationships
911 949
 *
912 950
 * The output of this function will be usually appended to taxon name representations.
951
 * Only the following types are displayed: LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR, ORTHOGRAPHIC_VARIANT
952
 *
953
 * LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR are displayed as
954
 * non {titleCache} nec {titleCache} nec {titleCache} whereas the related names
955
 * are ordered alphabetically.
956
 *
957
 * ORTHOGRAPHIC_VARIANT is displayed as 'ort. var. {nameCache}'
913 958
 *
914 959
 * Related issues:
915 960
 *   - https://dev.e-taxonomy.eu/redmine/issues/5697 "Show name conserved against as [non xxx]"
916 961
 *   - https://dev.e-taxonomy.eu/redmine/issues/6678 "How to correctly show name relationship "orth. var." in dataportal"
917 962
 *   - https://dev.e-taxonomy.eu/redmine/issues/5857
963
 *   - https://dev.e-taxonomy.eu/redmine/issues/2001 "[Cichorieae Portal] Name Relationship -> blocking name are not shown"
918 964
 *
919 965
 * @param $name_relations
920 966
 *    The list of CDM NameRelationsips
......
933 979
 */
934 980
function render_name_relationships_inline($name_relations, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source = true) {
935 981

  
936
  static $inverse_name_rels_uuids = array(UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR);
937

  
938 982
  RenderHints::pushToRenderStack('homonym');
939 983
  // the render stack element homonyms is being used in the default render templates !!!, see CDM_NAME_RENDER_TEMPLATES_DEFAULT
940 984

  
941
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT));
985
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT));
942 986

  
943 987
  $relations_array = array();
944 988

  
......
948 992
        // skip if not selected in the settings
949 993
        continue;
950 994
      }
951
      $is_inverse_relation = array_search($name_rel->type->uuid, $inverse_name_rels_uuids) !== false;
952
      $is_current_name_to_name = $current_name_uuid == $name_rel->toName->uuid;
953
      $is_current_name_from_name = $current_name_uuid == $name_rel->fromName->uuid;
954
      $relationship_markup = null;
955

  
956
      if($is_current_name_to_name && ($suppress_if_current_name_is_source && $is_inverse_relation || !$suppress_if_current_name_is_source)){
957
        $highlited_synonym_uuid = isset ($name_rel->fromName->taxonBases[0]->uuid) ? $name_rel->fromName->taxonBases[0]->uuid : '';
958
        $relationship_markup = render_taxon_or_name($name_rel->fromName,
959
          url(path_to_name($name_rel->fromName->uuid, $current_taxon_uuid, $highlited_synonym_uuid))
960
        );
961
      } else if($is_current_name_from_name && ($suppress_if_current_name_is_source && !$is_inverse_relation || !$suppress_if_current_name_is_source)){
962
        $highlited_synonym_uuid = isset ($name_rel->toName->taxonBases[0]->uuid) ? $name_rel->toName->taxonBases[0]->uuid : '';
963
        $relationship_markup = render_taxon_or_name($name_rel->toName,
964
          url(path_to_name($name_rel->toName->uuid, $current_taxon_uuid, $highlited_synonym_uuid))
965
        );
966
      }
995

  
996
      $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source);
967 997
        
968 998
      if($relationship_markup){
969 999
        if($name_rel->type->uuid == UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT){
......
986 1016
  return (count($relations_array) ?'<div class="name-relationships">[' . trim(join(" ", $relations_array)) . ']</div>' : '');
987 1017
}
988 1018

  
1019
/**
1020
 * Composes an list representation of the name relationships.
1021
 *
1022
 * The output of this function will be usually appended to taxon name representations.
1023
 *
1024
 * Related issues:
1025
 *   - https://dev.e-taxonomy.eu/redmine/issues/5697 "Show name conserved against as [non xxx]"
1026
 *   - https://dev.e-taxonomy.eu/redmine/issues/6678 "How to correctly show name relationship "orth. var." in dataportal"
1027
 *   - https://dev.e-taxonomy.eu/redmine/issues/5857
1028
 *
1029
 * @param $name_relations
1030
 *    The list of CDM NameRelationsips
1031
 * @param $current_name_uuid
1032
 *    The Uuid of the name for which the relations are to be rendered, the current name will be hidden when
1033
 *    rendering the relation an only the other name is shown. Parameter is REQUIRED.
1034
 * @param $suppress_if_current_name_is_source
1035
 *    The display of the relation will be
1036
 *    suppressed is the current name is on the source of the relation edge.
1037
 *    That is if it is on the from side of the relation. Except for 'blocking name for' which is
1038
 *    an inverse relation. For this relation type the toName is taken in to account.
1039
 * @param $current_taxon_uuid
1040
 *    The taxon to be omitted from related taxa. This is only used to create links, see path_to_name()
1041
 * @return array
1042
 *    A drupal render array
1043
 *
1044
 * @ingroup Compose
1045
 */
1046
function compose_name_relationships_list($name_relations, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source = true) {
1047

  
1048
  $non_nec_name_reltype_uuids = array(UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
1049
    UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
1050
    UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR);
1051
  // $ordered_name_relation_type_uuids = array_keys(cdm_terms_by_type_as_option('NameRelationshipType', CDM_ORDER_BY_ORDER_INDEX_ASC));
1052

  
1053
  RenderHints::pushToRenderStack('name_relationships');
1054
  RenderHints::setFootnoteListKey('name_relationships');
1055
  // the render stack element homonyms is being used in the default render templates !!!, see CDM_NAME_RENDER_TEMPLATES_DEFAULT
1056

  
1057
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, unserialize(CDM_NAME_RELATIONSHIP_LIST_TYPES_DEFAULT));
1058

  
1059
  $render_array = array(
1060
    'list' => array(
1061
      '#prefix' => '<div class="relationships_list name_relationships">',
1062
      '#suffix' => '</div>',
1063
      'items' => array()
1064
    ),
1065
    'footnotes' => array()
1066
  );
1067

  
1068
  if($name_relations) {
1069

  
1070
    // remove all relations which are not selected in the settings and
1071
    // sepearate all LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR relations and ORTHOGRAPHIC_VARIANTs
1072
    // for special handling
1073
    $filtered_name_rels = array();
1074
    $non_nec_name_rels = array();
1075
    $orthographic_variants = array();
1076
    foreach($name_relations as $name_rel) {
1077
      if (isset($selected_name_rel_uuids[$name_rel->type->uuid]) && $selected_name_rel_uuids[$name_rel->type->uuid]) {
1078
        if(array_search($name_rel->type->uuid, $non_nec_name_reltype_uuids) !== false){
1079
          $non_nec_name_rels[] = $name_rel;
1080
        } else if(UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT == $name_rel->type->uuid) {
1081
          $orthographic_variants[] = $name_rel;
1082
        } else {
1083
          $filtered_name_rels[] = $name_rel;
1084
        }
1085
      }
1086
    }
1087
    $name_relations = $filtered_name_rels;
1088

  
1089
    usort($name_relations, 'compare_name_relations_by_term_order_index');
1090

  
1091
    foreach($name_relations as $name_rel) {
1092

  
1093
      $current_name_is_toName = $current_name_uuid == $name_rel->toName->uuid;
1094

  
1095
      $footnote_key_markup = name_relationship_footnote_markup($name_rel);
1096
      $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source);
1097
      $is_inverse_relation = $current_name_is_toName;
1098

  
1099
      $label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
1100
      $symbol = cdm_relationship_type_term_symbol($name_rel->type, $is_inverse_relation);
1101

  
1102
      $relationship_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span> ' . $relationship_markup . $footnote_key_markup;
1103
      if($relationship_markup){
1104
        $render_array['list']['items'][] = markup_to_render_array($relationship_markup,
1105
          null,
1106
          '<div class="item">',
1107
          '</div>');
1108
      }
1109
    }
1110

  
1111
    // name relationships to be displayed as non nec
1112
    if(count($non_nec_name_rels) > 0){
1113
      $non_nec_markup = '';
1114
      foreach($non_nec_name_rels as $name_rel){
1115
        $footnote_key_markup = name_relationship_footnote_markup($name_rel);
1116
        $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source);
1117
        $symbol = $non_nec_markup ? ' nec ' : 'non';
1118
        $non_nec_markup .= '<span class="symbol" title="' . $label . '">' . $symbol . '</span> ' . $relationship_markup . $footnote_key_markup;
1119
      }
1120
       if($non_nec_markup){
1121
         $render_array['list']['items'][] = markup_to_render_array($non_nec_markup,
1122
           null,
1123
           '<div class="item">',
1124
           '</div>');
1125
       }
1126
    }
1127

  
1128
    // orthographic variants
1129
    if(count($orthographic_variants) > 0){
1130
      foreach($orthographic_variants as $name_rel){
1131
        $footnote_key_markup = name_relationship_footnote_markup($name_rel);
1132
        $footnote_key_markup .= ($footnote_key_markup ? ', ' : '') . nomenclatural_reference_footnote_markup($name_rel->toName);
1133
        $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source, TRUE);
1134
        $symbol = cdm_relationship_type_term_symbol($name_rel->type, $is_inverse_relation);
1135
        $relationship_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span> ' . $relationship_markup . $footnote_key_markup;
1136
      }
1137
      if($relationship_markup){
1138
        $render_array['list']['items'][] = markup_to_render_array($relationship_markup,
1139
          null,
1140
          '<div class="item">',
1141
          '</div>');
1142
      }
1143
    }
1144
  }
1145

  
1146
  RenderHints::popFromRenderStack();
1147
  $render_array['footnotes'] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey())));
1148
  RenderHints::clearFootnoteListKey();
1149

  
1150
  return $render_array;
1151
}
1152

  
1153
/**
1154
 * @param $name_rel
1155
 * @return string
1156
 */
1157
function name_relationship_footnote_markup($name_rel)
1158
{
1159
  $footnote_markup = '';
1160
  $footnote_key_markup = '';
1161
  if (isset($name_rel->ruleConsidered) && $name_rel) {
1162
    $footnote_markup = '<span class="rule_considered">' . $name_rel->ruleConsidered . '</span> ';
1163
  }
1164
  if (isset($name_rel->citation)) {
1165
    $footnote_markup .= '<span class="reference">' . $name_rel->citation->abbrevTitleCache . '</span>';
1166
  }
1167
  if (isset($name_rel->citationMicroReference)) {
1168
    $footnote_markup .= (isset($name_rel->citation) ? ':' : '') . '<span class="reference_detail">' . $name_rel->citationMicroReference . '</span>';
1169
  }
1170
  if ($footnote_markup) {
1171
    $fnkey = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $footnote_markup);
1172
    $footnote_key_markup = theme('cdm_footnote_key', array(
1173
      'footnoteKey' => $fnkey,
1174
      'separator' => ',',
1175
      'highlightable' => TRUE,
1176
      'separator_off' => TRUE,
1177
    ));
1178
  }
1179
  return $footnote_key_markup;
1180
}
1181

  
1182
/**
1183
 * @param $name
1184
 * @return string
1185
 */
1186
function nomenclatural_reference_footnote_markup($name)
1187
{
1188
  $footnote_markup = '';
1189
  $footnote_key_markup = '';
1190
  if (isset($name->nomenclaturalReference) && $name->nomenclaturalReference) {
1191
    $footnote_markup .= '<span class="reference">' . $name->nomenclaturalReference->titleCache . '</span>';
1192
  }
1193
  if (isset($name->nomenclaturalMicroReference)) {
1194
    $footnote_markup .= ($footnote_key_markup ? ':' : '') . '<span class="reference_detail">' . $name->nomenclaturalMicroReference . '</span>';
1195
  }
1196
  if ($footnote_markup) {
1197
    $fnkey = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $footnote_markup);
1198
    $footnote_key_markup = theme('cdm_footnote_key', array(
1199
      'footnoteKey' => $fnkey,
1200
      'separator' => ',',
1201
      'highlightable' => TRUE,
1202
      'separator_off' => TRUE,
1203
    ));
1204
  }
1205
  return $footnote_key_markup;
1206
}
1207

  
989 1208
/**
990 1209
 * @param $taxon
991 1210
 * @return array
......
1085 1304
  return $nameTypeLabelMap[$dtype];
1086 1305

  
1087 1306
}
1307

  
1308

  
1309
function compare_name_relations_by_term_order_index($name_rel1, $name_rel2){
1310
  return compare_terms_by_order_index($name_rel1->type, $name_rel2->type);
1311
}

Also available in: Unified diff