tripal_pub_references.tpl.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. $pub = $variables['node']->pub;
  3. // expand the pub object to include the records from the pub_dbxref table
  4. $options = array('return_array' => 1);
  5. $pub = chado_expand_var($pub, 'table', 'pub_dbxref', $options);
  6. $pub_dbxrefs = $pub->pub_dbxref;
  7. $references = array();
  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 publication is also available in the following databases:</div><?php
  15. // the $headers array is an array of fields to use as the colum headers.
  16. // additional documentation can be found here
  17. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  18. $headers = array('Database', 'Accession');
  19. // the $rows array contains an array of rows where each row is an array
  20. // of values for each column of the table in that row. Additional documentation
  21. // can be found here:
  22. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  23. $rows = array();
  24. foreach ($references as $dbxref){
  25. $database = $dbxref->db_id->name . ': ' . $dbxref->db_id->description;
  26. if ($dbxref->db_id->url) {
  27. $database = l($dbxref->db_id->name, $dbxref->db_id->url, array('attributes' => array('target' => '_blank'))) . ': ' . $dbxref->db_id->description;
  28. }
  29. $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
  30. if ($dbxref->db_id->urlprefix) {
  31. $accession = l($accession, tripal_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
  32. }
  33. if (property_exists($dbxref, 'is_primary')) {
  34. $accession .= " <i>(primary cross-reference)</i>";
  35. }
  36. $rows[] = array(
  37. $database,
  38. $accession
  39. );
  40. }
  41. // the $table array contains the headers and rows array as well as other
  42. // options for controlling the display of the table. Additional
  43. // documentation can be found here:
  44. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  45. $table = array(
  46. 'header' => $headers,
  47. 'rows' => $rows,
  48. 'attributes' => array(
  49. 'id' => 'tripal_pub-table-references',
  50. 'class' => 'tripal-data-table'
  51. ),
  52. 'sticky' => FALSE,
  53. 'caption' => '',
  54. 'colgroups' => array(),
  55. 'empty' => '',
  56. );
  57. // once we have our table array structure defined, we call Drupal's theme_table()
  58. // function to generate the table.
  59. print theme_table($table);
  60. }