tripal_library_terms.tpl.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. $library = $variables['node']->library;
  3. $options = array('return_array' => 1);
  4. $library = tripal_core_expand_chado_vars($library, 'table', 'library_cvterm', $options);
  5. $terms = $library->library_cvterm;
  6. // order the terms by CV
  7. $s_terms = array();
  8. foreach ($terms as $term) {
  9. $s_terms[$term->cvterm_id->cv_id->name][] = $term;
  10. }
  11. if (count($s_terms) > 0) { ?>
  12. <div class="tripal_library-data-block-desc tripal-data-block-desc">The following terms have been associated with this <?php print $node->library->type_id->name ?>:</div> <?php
  13. // iterate through each term
  14. $i = 0;
  15. foreach ($s_terms as $cv => $terms) {
  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 = array('Term', 'Definition');
  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 = array();
  25. foreach ($terms as $term) {
  26. $accession = $term->cvterm_id->dbxref_id->accession;
  27. if (is_numeric($term->cvterm_id->dbxref_id->accession)) {
  28. $accession = $term->cvterm_id->dbxref_id->db_id->name . ":" . $term->cvterm_id->dbxref_id->accession;
  29. }
  30. if ($term->cvterm_id->dbxref_id->db_id->urlprefix) {
  31. $accession = l($accession, $term->cvterm_id->dbxref_id->db_id->urlprefix . $accession, array('attributes' => array("target" => '_blank')));
  32. }
  33. $rows[] = array(
  34. $accession,
  35. $term->cvterm_id->name
  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-terms-$i",
  47. ),
  48. 'sticky' => FALSE,
  49. 'caption' => '<b>Vocabulary: ' . ucwords(preg_replace('/_/', ' ', $cv)) . '</b>',
  50. 'colgroups' => array(),
  51. 'empty' => '',
  52. );
  53. // once we have our table array structure defined, we call Drupal's theme_table()
  54. // function to generate the table.
  55. print theme_table($table);
  56. $i++;
  57. }
  58. } ?>