tripal_feature_references.tpl.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. $feature = $variables['node']->feature;
  3. $references = [];
  4. // First, get the dbxref record from feature record itself if one exists
  5. if ($feature->dbxref_id) {
  6. $feature->dbxref_id->is_primary = 1; // add this new property so we know it's the primary reference
  7. $references[] = $feature->dbxref_id;
  8. }
  9. // Second, expand the feature object to include the records from the feature_dbxref table
  10. $options = ['return_array' => 1];
  11. $feature = chado_expand_var($feature, 'table', 'feature_dbxref', $options);
  12. $feature_dbxrefs = $feature->feature_dbxref;
  13. if (count($feature_dbxrefs) > 0) {
  14. foreach ($feature_dbxrefs as $feature_dbxref) {
  15. if ($feature_dbxref->dbxref_id->db_id->name == 'GFF_source') {
  16. // check to see if the reference 'GFF_source' is there. This reference is
  17. // used to if the Chado Perl GFF loader was used to load the features
  18. }
  19. else {
  20. $references[] = $feature_dbxref->dbxref_id;
  21. }
  22. }
  23. }
  24. if (count($references) > 0) { ?>
  25. <div class="tripal_feature-data-block-desc tripal-data-block-desc">External
  26. references for this <?php print $feature->type_id->name ?></div><?php
  27. // the $headers array is an array of fields to use as the colum headers.
  28. // additional documentation can be found here
  29. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  30. $headers = ['Database', 'Accession'];
  31. // the $rows array contains an array of rows where each row is an array
  32. // of values for each column of the table in that row. Additional documentation
  33. // can be found here:
  34. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  35. $rows = [];
  36. foreach ($references as $dbxref) {
  37. // skip the GFF_source entry as this is just needed for the GBrowse chado adapter
  38. if ($dbxref->db_id->name == 'GFF_source') {
  39. continue;
  40. }
  41. $dbname = $dbxref->db_id->name;
  42. if ($dbxref->db_id->url) {
  43. $dbname = l($dbname, $dbxref->db_id->url, ['attributes' => ['target' => '_blank']]);
  44. }
  45. $accession = $dbxref->accession;
  46. if ($dbxref->db_id->urlprefix) {
  47. $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, ['attributes' => ['target' => '_blank']]);
  48. }
  49. if (property_exists($dbxref, 'is_primary')) {
  50. $accession .= " <i>(primary cross-reference)</i>";
  51. }
  52. $rows[] = [
  53. $dbname,
  54. $accession,
  55. ];
  56. }
  57. // the $table array contains the headers and rows array as well as other
  58. // options for controlling the display of the table. Additional
  59. // documentation can be found here:
  60. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  61. $table = [
  62. 'header' => $headers,
  63. 'rows' => $rows,
  64. 'attributes' => [
  65. 'id' => 'tripal_feature-table-references',
  66. 'class' => 'tripal-data-table',
  67. ],
  68. 'sticky' => FALSE,
  69. 'caption' => '',
  70. 'colgroups' => [],
  71. 'empty' => '',
  72. ];
  73. // once we have our table array structure defined, we call Drupal's theme_table()
  74. // function to generate the table.
  75. print theme_table($table);
  76. } ?>