tripal_feature_terms.tpl.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. $feature = $variables['node']->feature;
  3. $options = array('return_array' => 1);
  4. $feature = chado_expand_var($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. array('data' => $accession, 'width' => '15%'),
  37. $term->cvterm_id->name
  38. );
  39. }
  40. // generate the link to configure a database, b ut only if the user is
  41. // a tripal administrator
  42. $configure_link = '';
  43. if (user_access('view ids')) {
  44. $db_id = $term->cvterm_id->dbxref_id->db_id->db_id;
  45. $configure_link = l('[configure term links]', "admin/tripal/legacy/tripal_db/edit/$db_id", array('attributes' => array("target" => '_blank')));
  46. }
  47. // the $table array contains the headers and rows array as well as other
  48. // options for controlling the display of the table. Additional
  49. // documentation can be found here:
  50. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  51. $table = array(
  52. 'header' => $headers,
  53. 'rows' => $rows,
  54. 'attributes' => array(
  55. 'id' => "tripal_feature-table-terms-$i",
  56. 'class' => 'tripal-data-table'
  57. ),
  58. 'sticky' => FALSE,
  59. 'caption' => 'Vocabulary: <b>' . ucwords(preg_replace('/_/', ' ', $cv)) . '</b> ' . $configure_link,
  60. 'colgroups' => array(),
  61. 'empty' => '',
  62. );
  63. // once we have our table array structure defined, we call Drupal's theme_table()
  64. // function to generate the table.
  65. print theme_table($table);
  66. $i++;
  67. }
  68. }