tripal_organism_feature_browser.tpl.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. $organism = $variables['node']->organism;
  3. // get the list of available sequence ontology terms for which
  4. // we will build drupal pages from features in chado. If a feature
  5. // is not one of the specified typse we won't build a node for it.
  6. $allowed_types = variable_get('chado_browser_feature_types');
  7. $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
  8. $so_terms = explode(' ', $allowed_types);
  9. // Don't show the browser if there are no terms
  10. if (count($so_terms) > 0) {
  11. // get the feature_id's of the feature that belong to this organism. But we only
  12. // want 25 and we want a pager to let the user cycle between pages of features.
  13. // so we, use the chado_select_record API function to get the results and
  14. // generate the pager. The function is smart enough to know which page the user is
  15. // on and retrieves the proper set of features
  16. $element = 0; // an index to specify the pager if more than one is on the page
  17. $num_per_page = 25; // the number of features to show per page
  18. $values = [
  19. 'organism_id' => $organism->organism_id,
  20. 'type_id' => [
  21. 'name' => $so_terms,
  22. ],
  23. ];
  24. $columns = ['feature_id'];
  25. $options = [
  26. 'pager' => [
  27. 'limit' => $num_per_page,
  28. 'element' => $element,
  29. ],
  30. 'order_by' => ['name' => 'ASC'],
  31. ];
  32. $results = chado_select_record('feature', $columns, $values, $options);
  33. // now that we have all of the feature IDs, we want to expand each one so that we
  34. // have all of the neccessary values, including the node ID, if one exists, and the
  35. // cvterm type name.
  36. $features = [];
  37. foreach ($results as $result) {
  38. $values = ['feature_id' => $result->feature_id];
  39. $options = [
  40. 'include_fk' => [
  41. 'type_id' => 1,
  42. ],
  43. ];
  44. $features[] = chado_generate_var('feature', $values, $options);
  45. }
  46. if (count($features) > 0) { ?>
  47. <div class="tripal_organism-data-block-desc tripal-data-block-desc">The
  48. following browser provides a quick view for new visitors. Use the
  49. searching mechanism to find specific features.
  50. </div> <?php
  51. // the $headers array is an array of fields to use as the colum headers.
  52. // additional documentation can be found here
  53. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  54. $headers = ['Feature Name', 'Unique Name', 'Type'];
  55. // the $rows array contains an array of rows where each row is an array
  56. // of values for each column of the table in that row. Additional documentation
  57. // can be found here:
  58. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  59. $rows = [];
  60. // let admins know they can customize the terms that appear in the list
  61. print tripal_set_message("Administrators, you can specify the feature types " .
  62. "that should appear in this browser or remove it from the list of resources " .
  63. "by navigating to the " .
  64. l("Tripal feature settings page", "admin/tripal/legacy/tripal_feature/configuration", ['attributes' => ['target' => '_blank']]),
  65. TRIPAL_INFO,
  66. ['return_html' => 1]
  67. );
  68. foreach ($features as $feature) {
  69. $fname = $feature->name;
  70. if (property_exists($feature, 'nid')) {
  71. $fname = l($fname, "node/$feature->nid", ['attributes' => ['target' => '_blank']]);
  72. }
  73. $rows[] = [
  74. $fname,
  75. $feature->uniquename,
  76. $feature->type_id->name,
  77. ];
  78. }
  79. // the $table array contains the headers and rows array as well as other
  80. // options for controlling the display of the table. Additional
  81. // documentation can be found here:
  82. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  83. $table = [
  84. 'header' => $headers,
  85. 'rows' => $rows,
  86. 'attributes' => [
  87. 'id' => 'tripal_organism-table-features',
  88. 'class' => 'tripal-data-table',
  89. ],
  90. 'sticky' => FALSE,
  91. 'caption' => '',
  92. 'colgroups' => [],
  93. 'empty' => '',
  94. ];
  95. // once we have our table array structure defined, we call Drupal's theme_table()
  96. // function to generate the table.
  97. print theme_table($table);
  98. // the $pager array values that control the behavior of the pager. For
  99. // documentation on the values allows in this array see:
  100. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  101. // here we add the paramter 'block' => 'feature_browser'. This is because
  102. // the pager is not on the default block that appears. When the user clicks a
  103. // page number we want the browser to re-appear with the page is loaded.
  104. // We remove the 'pane' parameter from the original query parameters because
  105. // Drupal won't reset the parameter if it already exists.
  106. $get = $_GET;
  107. unset($_GET['pane']);
  108. $pager = [
  109. 'tags' => [],
  110. 'element' => $element,
  111. 'parameters' => [
  112. 'pane' => 'feature_browser',
  113. ],
  114. 'quantity' => $num_per_page,
  115. ];
  116. print theme_pager($pager);
  117. $_GET = $get;
  118. print tripal_set_message("
  119. Administrators, please note that the feature browser will be retired in
  120. a future version of Tripal.",
  121. TRIPAL_INFO,
  122. ['return_html' => 1]);
  123. }
  124. }