Project

General

Profile

« Previous | Next » 

Revision a38c0718

Added by Patrick Plitzner over 4 years ago

ref #8657 Retain hierarchy information of description elements

  • remove web service for flat ordered list

View differences:

modules/cdm_dataportal/cdm_api/cdm_api.module
1743 1743
}
1744 1744

  
1745 1745
/**
1746
 * Fetches all descriptions elements of the given description sorted by the
1747
 * given term tree
1748
 *
1749
 * @param $description_uuid
1750
 *     The UUID of the description
1751
 * @param $term_tree_uuid
1752
 *     The UUID of the term tree
1753
 *
1754
 * @return list
1755
 *     A list of description elements sorted according to the term treee
1756
 */
1757
function cdm_ws_description_element_sorted_by_term_tree($description_uuid, $term_tree_uuid) {
1758

  
1759
  $description_elements = cdm_ws_fetch_all(CDM_WS_DESCRIPTIONELEMENT_SORTED_BY_TREE,
1760
      array(
1761
      'description' => $description_uuid,
1762
      'termTree' => $term_tree_uuid,
1763
      ),
1764
      'POST'
1765
  );
1766

  
1767
  return $description_elements;
1768
}
1769

  
1770
/**
1771 1746
 * Returns a filtered a list of annotations for the cdm entity given as parameter $cdmBase.
1772 1747
 * If the annotations are not yet already loded with the cdm entity the cdm REST service will
1773 1748
 * be requested for the annotations.
modules/cdm_dataportal/cdm_api/webservice_uris.php
87 87

  
88 88
define('CDM_WS_DESCRIPTIONELEMENT', 'descriptionElement/$0');
89 89
define('CDM_WS_DESCRIPTIONELEMENT_BY_TAXON', 'portal/descriptionElement/byTaxon');
90
define('CDM_WS_DESCRIPTIONELEMENT_SORTED_BY_TREE', 'portal/descriptionElement/elementsSortbyTree');
91 90
define('CDM_WS_PORTAL_DESCRIPTIONELEMENT', 'portal/descriptionElement/$0');
92 91

  
93 92
/**
modules/cdm_dataportal/includes/pages.inc
584 584
        $feature_description = make_pseudo_feature('Descriptions (aggregated)', 'AGGREGATION_DESCRIPTIONS');
585 585
        $description_item = "";
586 586
        foreach ($aggregatedDescriptions as $description) {
587
          $description_item .= render_cdm_description_link($description, '', TRUE);
587
          $description_item .= render_cdm_description($description, '', TRUE);
588 588
        }
589 589
        $description_block = feature_block(t('Descriptions (aggregated)'), $feature_description);
590 590
        $description_block->content = [];
......
619 619
}
620 620

  
621 621
/**
622
 * Renders the link which will lead to the description detail page
622
 * Renders the description and adds a link to the description detail page
623
 *
623 624
 * @param object $description
624 625
 *     the cdm description entity which will be linked to
625 626
 *
626
 * @return string
627
 *     the markup for the link
627
 * @param string $linkText an optional link text; default is the description titleCache
628
 * @param bool $renderDescriptionElements if True the description elements will be rendered
629
 *
630
 * @return string the markup for the description
628 631
 */
629
function render_cdm_description_link($description, $linkText = '', $renderDescriptionElements = False) {
632
function render_cdm_description($description, $linkText = '', $renderDescriptionElements = False) {
630 633
  if (empty($linkText)) {
631 634
    $linkText = $description->titleCache;
632 635
  }
633 636
  $pathToDescription = path_to_description($description->uuid);
634 637
  $attributes['class'][] = html_class_attribute_ref($description);
635 638
  $descriptionString = '';
636
  if ($renderDescriptionElements) {
637
    foreach ($description->elements as $element) {
638
      switch ($element->class) {
639
        case 'CategoricalData':
640
          $state_data = compose_state_data($element);
641
          $state_data = implode(', ', $state_data);
642
          if (!empty($state_data)) {
643
            $descriptionString .= '<i>' . $element->feature->representation_L10n . '</i>: ' . $state_data . "; ";
644
          }
645
          break;
646
        case 'QuantitativeData':
647
          $descriptionString .= '<i>' . $element->feature->representation_L10n . '</i>: ' . compose_quant_stats($element) . "; ";
648
          break;
649
      }
650
    }
639
  if($renderDescriptionElements){
640
    $descriptionString = render_description_string($description, get_root_nodes_for_dataset($description));
651 641
  }
652 642
  $detail_html = $descriptionString.l($linkText, $pathToDescription, array('attributes' => $attributes))."<br><br>";
653 643
  return $detail_html;
654 644
}
655 645

  
656 646
/**
647
 * @param $description
648
 * @param $root_nodes
649
 *
650
 * @return string
651
 */
652
function render_description_string($description, $root_nodes) {
653
  $descriptionString = '';
654
  if (!empty($root_nodes)) {
655
    foreach ($root_nodes as $root_node) {
656
      foreach ($root_node->descriptionElements as $element) {
657
        switch ($element->class) {
658
          case 'CategoricalData':
659
            $state_data = compose_state_data($element);
660
            $state_data = implode(', ', $state_data);
661
            if (!empty($state_data)) {
662
              $descriptionString .= '<i>' . $element->feature->representation_L10n . '</i>: ' . $state_data . "; ";
663
            }
664
            break;
665
          case 'QuantitativeData':
666
            $descriptionString .= '<i>' . $element->feature->representation_L10n . '</i>: ' . compose_quant_stats($element) . "; ";
667
            break;
668
        }
669
      }
670
      // recurse child nodes
671
      $descriptionString .= render_description_string($description, $root_node->childNodes);
672
    }
673
  }
674
  return $descriptionString;
675
}
676

  
677
/**
657 678
 * Renders the link which will lead to the specimen detail page
658 679
 * @param object $specimen
659 680
 *    the cdm specimen entity which will be linked to
......
1195 1216
    $render_array[] = markup_to_render_array(render_cdm_specimen_link($description->describedSpecimenOrObservation));
1196 1217
  }
1197 1218

  
1219
  $root_nodes = [];
1220
  $root_nodes = get_root_nodes_for_dataset($description);
1221

  
1198 1222
  $header = ['Feature/Character', 'State'];
1223

  
1199 1224
  $rows = [];
1200
  foreach ($description->elements as $element) {
1225
  $rows = compose_description_element_rows($root_nodes, $rows);
1201 1226

  
1202
    switch ($element->class) {
1203
      case 'CategoricalData':
1204
        $rows[] = [
1205
          $element->feature->representation_L10n,
1206
          compose_state_data_span($element),
1207
        ];
1208
        break;
1209
      case 'QuantitativeData':
1210
        $rows[] = [
1211
          $element->feature->representation_L10n,
1212
          compose_quant_stats($element),
1213
        ];
1214
        break;
1215
    }
1216
  }
1217 1227
  $render_array[] = markup_to_render_array(theme('table', [
1218 1228
    'header' => $header,
1219 1229
    'rows' => $rows,
......
1225 1235
      if ($source->type == 'Aggregation' and isset($source->cdmSource) and $source->cdmSource->class=='SpecimenDescription') {
1226 1236
        $specimendescription = $source->cdmSource;
1227 1237
        $items[] = [
1228
          'data' => render_cdm_description_link($specimendescription),
1238
          'data' => render_cdm_description($specimendescription),
1229 1239
        ];
1230 1240
      }
1231 1241
    }
......
1243 1253
}
1244 1254

  
1245 1255
/**
1256
 * For a given description returns the root nodes according to the
1257
 *corresponding term tree. The term tree is determined as follow:
1258
 * 1. If description is part of a descriptive data set the term tree of that
1259
 *    data set is used (FIXME handle multiple term trees)
1260
 * 2. Otherwise the portal taxon profile tree is used
1261
 * @param $description
1262
 *
1263
 * @return array
1264
 */
1265
function get_root_nodes_for_dataset($description) {
1266
  if (!empty($description->descriptiveDataSets)) {
1267
    foreach ($description->descriptiveDataSets as $dataSet) {
1268
      break;// FIXME handle multiple term trees
1269
    }
1270
    $tree = cdm_ws_get(CDM_WS_TERMTREE, $dataSet->descriptiveSystem->uuid);
1271
    $root_nodes = _mergeFeatureTreeDescriptions($tree->root->childNodes, $description->elements);
1272
  }
1273
  else {
1274
    $root_nodes = _mergeFeatureTreeDescriptions(get_profile_feature_tree()->root->childNodes, $description->elements);
1275
  }
1276
  return $root_nodes;
1277
}
1278

  
1279
/**
1280
 * @param $root_nodes
1281
 * @param $rows
1282
 *
1283
 * @return array
1284
 */
1285
function compose_description_element_rows($root_nodes, $rows) {
1286
  foreach ($root_nodes as $root_node) {
1287
    foreach ($root_node->descriptionElements as $element) {
1288
      switch ($element->class) {
1289
        case 'CategoricalData':
1290
          if (!empty($element->stateData)) {
1291
            $rows[] = [
1292
              $element->feature->representation_L10n,
1293
              compose_state_data_span($element),
1294
            ];
1295
          }
1296
          break;
1297
        case 'QuantitativeData':
1298
          $rows[] = [
1299
            $element->feature->representation_L10n,
1300
            compose_quant_stats($element),
1301
          ];
1302
          break;
1303
      }
1304
    }
1305
    // recurse child nodes
1306
    $rows = compose_description_element_rows($root_node->childNodes, $rows);
1307
  }
1308
  return $rows;
1309
}
1310

  
1311
/**
1246 1312
 * @param $named_area_uuid
1247 1313
 * @return array
1248 1314
 *    The drupal render array for the page

Also available in: Unified diff