tripal_feature_terms.tpl.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. $feature = $variables['node']->feature;
  3. $options = array('return_array' => 1);
  4. $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_cvterm', $options);
  5. $terms = $feature->feature_cvterm;
  6. // order the terms by CV
  7. $s_terms = array();
  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 id="tripal_feature-terms-box" class="tripal_feature-info-box tripal-info-box">
  15. <div class="tripal_feature-info-box-title tripal-info-box-title">Annotated Terms</div>
  16. <div class="tripal_feature-info-box-desc tripal-info-box-desc">The following terms have been associated with this <?php print $node->feature->type_id->name ?>:</div> <?php
  17. // iterate through each term
  18. $i = 0;
  19. foreach ($s_terms as $cv => $terms) {
  20. // the $headers array is an array of fields to use as the colum headers.
  21. // additional documentation can be found here
  22. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  23. $headers = array('Term', 'Definition');
  24. // the $rows array contains an array of rows where each row is an array
  25. // of values for each column of the table in that row. Additional documentation
  26. // can be found here:
  27. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  28. $rows = array();
  29. foreach ($terms as $term) {
  30. $accession = $term->cvterm_id->dbxref_id->accession;
  31. if (is_numeric($term->cvterm_id->dbxref_id->accession)) {
  32. $accession = $term->cvterm_id->dbxref_id->db_id->name . ":" . $term->cvterm_id->dbxref_id->accession;
  33. }
  34. if ($term->cvterm_id->dbxref_id->db_id->urlprefix) {
  35. $accession = l($accession, $term->cvterm_id->dbxref_id->db_id->urlprefix . $accession, array('attributes' => array("target" => '_blank')));
  36. }
  37. $rows[] = array(
  38. $accession,
  39. $term->cvterm_id->name
  40. );
  41. }
  42. // the $table array contains the headers and rows array as well as other
  43. // options for controlling the display of the table. Additional
  44. // documentation can be found here:
  45. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  46. $table = array(
  47. 'header' => $headers,
  48. 'rows' => $rows,
  49. 'attributes' => array(
  50. 'id' => "tripal_feature-table-terms-$i",
  51. ),
  52. 'sticky' => FALSE,
  53. 'caption' => '<b>Vocabulary: ' . ucwords(preg_replace('/_/', ' ', $cv)) . '</b>',
  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. $i++;
  61. } ?>
  62. </div> <?php
  63. } ?>