tripal_feature_terms.tpl.php 2.9 KB

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