tripal_library_references.tpl.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. $library = $variables['node']->library;
  3. $references = array();
  4. // Second, expand the library object to include the records from the library_dbxref table
  5. $options = array('return_array' => 1);
  6. $library = chado_expand_var($library, 'table', 'library_dbxref', $options);
  7. $library_dbxrefs = $library->library_dbxref;
  8. if (count($library_dbxrefs) > 0 ) {
  9. foreach ($library_dbxrefs as $library_dbxref) {
  10. $references[] = $library_dbxref->dbxref_id;
  11. }
  12. }
  13. if(count($references) > 0){ ?>
  14. <div class="tripal_library-data-block-desc tripal-data-block-desc">External references for this <?php print $library->type_id->name ?></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. $dbname = $dbxref->db_id->name;
  26. if ($dbxref->db_id->url) {
  27. $dbname = l($dbname, $dbxref->db_id->url, array('attributes' => array('target' => '_blank')));
  28. }
  29. $accession = $dbxref->accession;
  30. if ($dbxref->db_id->urlprefix) {
  31. $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
  32. }
  33. $rows[] = array(
  34. $dbname,
  35. $accession
  36. );
  37. }
  38. // the $table array contains the headers and rows array as well as other
  39. // options for controlling the display of the table. Additional
  40. // documentation can be found here:
  41. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  42. $table = array(
  43. 'header' => $headers,
  44. 'rows' => $rows,
  45. 'attributes' => array(
  46. 'id' => 'tripal_library-table-references',
  47. 'class' => 'tripal-data-table'
  48. ),
  49. 'sticky' => FALSE,
  50. 'caption' => '',
  51. 'colgroups' => array(),
  52. 'empty' => '',
  53. );
  54. // once we have our table array structure defined, we call Drupal's theme_table()
  55. // function to generate the table.
  56. print theme_table($table);
  57. }