tripal_feature_terms.tpl.php 2.5 KB

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