tripal_feature_references.tpl.php 3.1 KB

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