tripal_featuremap_references.tpl.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. $featuremap = $variables['node']->featuremap;
  3. $references = [];
  4. // expand the featuremap object to include the records from the featuremap_dbxref table
  5. $options = ['return_array' => 1];
  6. $featuremap = chado_expand_var($featuremap, 'table', 'featuremap_dbxref', $options);
  7. $featuremap_dbxrefs = $featuremap->featuremap_dbxref;
  8. if (count($featuremap_dbxrefs) > 0) {
  9. foreach ($featuremap_dbxrefs as $featuremap_dbxref) {
  10. $references[] = $featuremap_dbxref->dbxref_id;
  11. }
  12. }
  13. if (count($references) > 0) { ?>
  14. <div class="tripal_featuremap-data-block-desc tripal-data-block-desc">
  15. External references for this map
  16. </div><?php
  17. // the $headers array is an array of fields to use as the colum headers.
  18. // additional documentation can be found here
  19. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  20. $headers = ['Database', 'Accession'];
  21. // the $rows array contains an array of rows where each row is an array
  22. // of values for each column of the table in that row. Additional documentation
  23. // can be found here:
  24. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  25. $rows = [];
  26. foreach ($references as $dbxref) {
  27. $dbname = $dbxref->db_id->name;
  28. if ($dbxref->db_id->url) {
  29. $dbname = l($dbname, $dbxref->db_id->url, ['attributes' => ['target' => '_blank']]);
  30. }
  31. $accession = $dbxref->accession;
  32. if ($dbxref->db_id->urlprefix) {
  33. $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, ['attributes' => ['target' => '_blank']]);
  34. }
  35. $rows[] = [
  36. $dbname,
  37. $accession,
  38. ];
  39. }
  40. // the $table array contains the headers and rows array as well as other
  41. // options for controlling the display of the table. Additional
  42. // documentation can be found here:
  43. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  44. $table = [
  45. 'header' => $headers,
  46. 'rows' => $rows,
  47. 'attributes' => [
  48. 'id' => 'tripal_featuremap-table-references',
  49. 'class' => 'tripal-data-table',
  50. ],
  51. 'sticky' => FALSE,
  52. 'caption' => '',
  53. 'colgroups' => [],
  54. 'empty' => '',
  55. ];
  56. // once we have our table array structure defined, we call Drupal's theme_table()
  57. // function to generate the table.
  58. print theme_table($table);
  59. }