tripal_organism_references.tpl.php 2.8 KB

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