tripal_organism_feature_browser.tpl.php

  1. 2.x tripal_feature/theme/templates/tripal_organism_feature_browser.tpl.php
  2. 3.x legacy/tripal_feature/theme/templates/tripal_organism_feature_browser.tpl.php
1 theme call to tripal_organism_feature_browser.tpl.php
tripal_feature_node_view in tripal_feature/includes/tripal_feature.chado_node.inc
Implements hook_node_view(). Acts on all content types.

File

tripal_feature/theme/templates/tripal_organism_feature_browser.tpl.php
View source
  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 = array(
  19. 'organism_id' => $organism->organism_id,
  20. 'type_id' => array(
  21. 'name' => $so_terms
  22. ),
  23. );
  24. $columns = array('feature_id');
  25. $options = array(
  26. 'pager' => array(
  27. 'limit' => $num_per_page,
  28. 'element' => $element
  29. ),
  30. 'order_by' => array('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 = array();
  37. foreach ($results as $result) {
  38. $values = array('feature_id' => $result->feature_id);
  39. $options = array(
  40. 'include_fk' => array(
  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 following browser provides a quick view for new visitors. Use the searching mechanism to find specific features.</div> <?php
  48. // the $headers array is an array of fields to use as the colum headers.
  49. // additional documentation can be found here
  50. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  51. $headers = array('Feature Name' ,'Unique Name', 'Type');
  52. // the $rows array contains an array of rows where each row is an array
  53. // of values for each column of the table in that row. Additional documentation
  54. // can be found here:
  55. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  56. $rows = array();
  57. // let admins know they can customize the terms that appear in the list
  58. print tripal_set_message("Administrators, you can specify the feature types ".
  59. "that should appear in this browser or remove it from the list of resources ".
  60. "by navigating to the ".
  61. l("Tripal feature settings page", "admin/tripal/chado/tripal_feature/configuration", array('attributes' => array('target' => '_blank'))),
  62. TRIPAL_INFO,
  63. array('return_html' => 1)
  64. );
  65. foreach ($features as $feature){
  66. $fname = $feature->name;
  67. if (property_exists($feature, 'nid')) {
  68. $fname = l($fname, "node/$feature->nid", array('attributes' => array('target' => '_blank')));
  69. }
  70. $rows[] = array(
  71. $fname,
  72. $feature->uniquename,
  73. $feature->type_id->name
  74. );
  75. }
  76. // the $table array contains the headers and rows array as well as other
  77. // options for controlling the display of the table. Additional
  78. // documentation can be found here:
  79. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  80. $table = array(
  81. 'header' => $headers,
  82. 'rows' => $rows,
  83. 'attributes' => array(
  84. 'id' => 'tripal_organism-table-features',
  85. 'class' => 'tripal-data-table'
  86. ),
  87. 'sticky' => FALSE,
  88. 'caption' => '',
  89. 'colgroups' => array(),
  90. 'empty' => '',
  91. );
  92. // once we have our table array structure defined, we call Drupal's theme_table()
  93. // function to generate the table.
  94. print theme_table($table);
  95. // the $pager array values that control the behavior of the pager. For
  96. // documentation on the values allows in this array see:
  97. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  98. // here we add the paramter 'block' => 'feature_browser'. This is because
  99. // the pager is not on the default block that appears. When the user clicks a
  100. // page number we want the browser to re-appear with the page is loaded.
  101. // We remove the 'pane' parameter from the original query parameters because
  102. // Drupal won't reset the parameter if it already exists.
  103. $get = $_GET;
  104. unset($_GET['pane']);
  105. $pager = array(
  106. 'tags' => array(),
  107. 'element' => $element,
  108. 'parameters' => array(
  109. 'pane' => 'feature_browser'
  110. ),
  111. 'quantity' => $num_per_page,
  112. );
  113. print theme_pager($pager);
  114. $_GET = $get;
  115. print tripal_set_message("
  116. Administrators, please note that the feature browser will be retired in
  117. a future version of Tripal.",
  118. TRIPAL_INFO,
  119. array('return_html' => 1));
  120. }
  121. }