tripal_pub_references.tpl.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. $pub = $variables['node']->pub;
  3. // expand the pub object to include the records from the pub_dbxref table
  4. $options = ['return_array' => 1];
  5. $pub = chado_expand_var($pub, 'table', 'pub_dbxref', $options);
  6. $pub_dbxrefs = $pub->pub_dbxref;
  7. $references = [];
  8. if (count($pub_dbxrefs) > 0) {
  9. foreach ($pub_dbxrefs as $pub_dbxref) {
  10. $references[] = $pub_dbxref->dbxref_id;
  11. }
  12. }
  13. if (count($references) > 0) { ?>
  14. <div class="tripal_pub-data-block-desc tripal-data-block-desc">This
  15. publication is also available in the following databases:
  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. $database = $dbxref->db_id->name . ': ' . $dbxref->db_id->description;
  28. if ($dbxref->db_id->url) {
  29. $database = l($dbxref->db_id->name, $dbxref->db_id->url, ['attributes' => ['target' => '_blank']]) . ': ' . $dbxref->db_id->description;
  30. }
  31. $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
  32. if ($dbxref->db_id->urlprefix) {
  33. $accession = l($accession, tripal_get_dbxref_url($dbxref), ['attributes' => ['target' => '_blank']]);
  34. }
  35. if (property_exists($dbxref, 'is_primary')) {
  36. $accession .= " <i>(primary cross-reference)</i>";
  37. }
  38. $rows[] = [
  39. $database,
  40. $accession,
  41. ];
  42. }
  43. // the $table array contains the headers and rows array as well as other
  44. // options for controlling the display of the table. Additional
  45. // documentation can be found here:
  46. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  47. $table = [
  48. 'header' => $headers,
  49. 'rows' => $rows,
  50. 'attributes' => [
  51. 'id' => 'tripal_pub-table-references',
  52. 'class' => 'tripal-data-table',
  53. ],
  54. 'sticky' => FALSE,
  55. 'caption' => '',
  56. 'colgroups' => [],
  57. 'empty' => '',
  58. ];
  59. // once we have our table array structure defined, we call Drupal's theme_table()
  60. // function to generate the table.
  61. print theme_table($table);
  62. }