tripal_library_terms.tpl.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. $library = $variables['node']->library;
  3. $options = ['return_array' => 1];
  4. $library = chado_expand_var($library, 'table', 'library_cvterm', $options);
  5. $terms = $library->library_cvterm;
  6. // order the terms by CV
  7. $s_terms = [];
  8. if ($terms) {
  9. foreach ($terms as $term) {
  10. $s_terms[$term->cvterm_id->cv_id->name][] = $term;
  11. }
  12. }
  13. if (count($s_terms) > 0) { ?>
  14. <div class="tripal_library-data-block-desc tripal-data-block-desc">The
  15. following terms have been associated with
  16. this <?php print $node->library->type_id->name ?>:
  17. </div> <?php
  18. // iterate through each term
  19. $i = 0;
  20. foreach ($s_terms as $cv => $terms) {
  21. // the $headers array is an array of fields to use as the colum headers.
  22. // additional documentation can be found here
  23. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  24. $headers = ['Term', 'Definition'];
  25. // the $rows array contains an array of rows where each row is an array
  26. // of values for each column of the table in that row. Additional documentation
  27. // can be found here:
  28. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  29. $rows = [];
  30. foreach ($terms as $term) {
  31. $accession = $term->cvterm_id->dbxref_id->accession;
  32. if (is_numeric($term->cvterm_id->dbxref_id->accession)) {
  33. $accession = $term->cvterm_id->dbxref_id->db_id->name . ":" . $term->cvterm_id->dbxref_id->accession;
  34. }
  35. if ($term->cvterm_id->dbxref_id->db_id->urlprefix) {
  36. $accession = l($accession, $term->cvterm_id->dbxref_id->db_id->urlprefix . $accession, ['attributes' => ["target" => '_blank']]);
  37. }
  38. $rows[] = [
  39. $accession,
  40. $term->cvterm_id->name,
  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_library-table-terms-$i",
  52. 'class' => 'tripal-data-table',
  53. ],
  54. 'sticky' => FALSE,
  55. 'caption' => '<b>Vocabulary: ' . ucwords(preg_replace('/_/', ' ', $cv)) . '</b>',
  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. $i++;
  63. }
  64. } ?>