tripal_feature_references.tpl.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. $feature = $variables['node']->feature;
  3. $references = array();
  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 = array('return_array' => 1);
  11. $feature = tripal_core_expand_chado_vars($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 id="tripal_feature-references-box" class="tripal_feature-info-box tripal-info-box">
  26. <div class="tripal_feature-info-box-title tripal-info-box-title">Cross References</div>
  27. <div class="tripal_feature-info-box-desc tripal-info-box-desc">External references for this <?php print $feature->type_id->name ?></div><?php
  28. // the $headers array is an array of fields to use as the colum headers.
  29. // additional documentation can be found here
  30. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  31. $headers = array('Dababase', 'Accession');
  32. // the $rows array contains an array of rows where each row is an array
  33. // of values for each column of the table in that row. Additional documentation
  34. // can be found here:
  35. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  36. $rows = array();
  37. foreach ($references as $dbxref){
  38. // skip the GFF_source entry as this is just needed for the GBrowse chado adapter
  39. if ($dbxref->db_id->name == 'GFF_source'){
  40. continue;
  41. }
  42. $dbname = $dbxref->db_id->name;
  43. if ($dbxref->db_id->url) {
  44. $dbname = l($dbname, $dbxref->db_id->url, array('attributes' => array('target' => '_blank')));
  45. }
  46. $accession = $dbxref->accession;
  47. if ($dbxref->db_id->urlprefix) {
  48. $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
  49. }
  50. if (property_exists($dbxref, 'is_primary')) {
  51. $accession .= " <i>(primary cross-reference)</i>";
  52. }
  53. $rows[] = array(
  54. $dbname,
  55. $accession
  56. );
  57. }
  58. // the $table array contains the headers and rows array as well as other
  59. // options for controlling the display of the table. Additional
  60. // documentation can be found here:
  61. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  62. $table = array(
  63. 'header' => $headers,
  64. 'rows' => $rows,
  65. 'attributes' => array(
  66. 'id' => 'tripal_feature-table-references',
  67. ),
  68. 'sticky' => FALSE,
  69. 'caption' => '',
  70. 'colgroups' => array(),
  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. </div><?php
  77. }?>