tripal_library_references.tpl.php 2.3 KB

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