tripal_organism_feature_browser.tpl.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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', 'gene mRNA');
  7. $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
  8. $so_terms = explode(' ', $allowed_types);
  9. // get the feature_id's of the feature that belong to this organism. But we only
  10. // want 25 and we want a pager to let the user cycle between pages of features.
  11. // so we, use the chado_select_record API function to get the results and
  12. // generate the pager. The function is smart enough to know which page the user is
  13. // on and retrieves the proper set of features
  14. $element = 0; // an index to specify the pager if more than one is on the page
  15. $num_per_page = 25; // the number of features to show per page
  16. $values = array(
  17. 'organism_id' => $organism->organism_id,
  18. 'type_id' => array(
  19. 'name' => $so_terms
  20. ),
  21. );
  22. $columns = array('feature_id');
  23. $options = array(
  24. 'pager' => array(
  25. 'limit' => $num_per_page,
  26. 'element' => $element
  27. ),
  28. 'order_by' => array('name' => 'ASC'),
  29. );
  30. $results = chado_select_record('feature', $columns, $values, $options);
  31. // now that we have all of the feature IDs, we want to expand each one so that we
  32. // have all of the neccessary values, including the node ID, if one exists, and the
  33. // cvterm type name.
  34. $features = array();
  35. foreach ($results as $result) {
  36. $values = array('feature_id' => $result->feature_id);
  37. $options = array(
  38. 'include_fk' => array(
  39. 'type_id' => 1
  40. )
  41. );
  42. $features[] = chado_generate_var('feature', $values, $options);
  43. }
  44. if (count($features) > 0) { ?>
  45. <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
  46. // the $headers array is an array of fields to use as the colum headers.
  47. // additional documentation can be found here
  48. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  49. $headers = array('Feature Name' ,'Unique Name', 'Type');
  50. // the $rows array contains an array of rows where each row is an array
  51. // of values for each column of the table in that row. Additional documentation
  52. // can be found here:
  53. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  54. $rows = array();
  55. // let admins know they can customize the terms that appear in the list
  56. print tripal_set_message("Administrators, you can specify the feature types ".
  57. "that should appear in this browser or remove it from the list of resources ".
  58. "by navigating to the ".
  59. l("Tripal feature settings page", "admin/tripal/chado/tripal_feature/configuration", array('attributes' => array('target' => '_blank'))),
  60. TRIPAL_INFO,
  61. array('return_html' => 1)
  62. );
  63. foreach ($features as $feature){
  64. $fname = $feature->name;
  65. if (property_exists($feature, 'nid')) {
  66. $fname = l($fname, "node/$feature->nid", array('attributes' => array('target' => '_blank')));
  67. }
  68. $rows[] = array(
  69. $fname,
  70. $feature->uniquename,
  71. $feature->type_id->name
  72. );
  73. }
  74. // the $table array contains the headers and rows array as well as other
  75. // options for controlling the display of the table. Additional
  76. // documentation can be found here:
  77. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  78. $table = array(
  79. 'header' => $headers,
  80. 'rows' => $rows,
  81. 'attributes' => array(
  82. 'id' => 'tripal_organism-table-features',
  83. 'class' => 'tripal-data-table'
  84. ),
  85. 'sticky' => FALSE,
  86. 'caption' => '',
  87. 'colgroups' => array(),
  88. 'empty' => '',
  89. );
  90. // once we have our table array structure defined, we call Drupal's theme_table()
  91. // function to generate the table.
  92. print theme_table($table);
  93. // the $pager array values that control the behavior of the pager. For
  94. // documentation on the values allows in this array see:
  95. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  96. // here we add the paramter 'block' => 'feature_browser'. This is because
  97. // the pager is not on the default block that appears. When the user clicks a
  98. // page number we want the browser to re-appear with the page is loaded.
  99. $pager = array(
  100. 'tags' => array(),
  101. 'element' => $element,
  102. 'parameters' => array(
  103. 'block' => 'feature_browser'
  104. ),
  105. 'quantity' => $num_per_page,
  106. );
  107. print theme_pager($pager);
  108. }
  109. else { ?>
  110. <p>There are no results.</p><?php
  111. print tripal_set_message("
  112. Administrators, perform the following to show features in this browser:
  113. <ul>
  114. <li>Load features for this organism using the " .
  115. l("FASTA loader", 'admin/tripal/loaders/fasta_loader') . ", ".
  116. l("GFF Loader", 'admin/tripal/loaders/gff3_load') . " or ".
  117. l("Bulk Loader", 'admin/tripal/loaders/bulk'). "</li>
  118. <li>Sync the features that should have pages using the ".
  119. l("Sync features page", 'admin/tripal/chado/tripal_feature/sync'). "</li>
  120. <li>Return to this page to browse features.</li>
  121. <li>Ensure the user " .
  122. l("has permission", 'admin/people/permissions') . " to view the feature content</li>
  123. </ul>
  124. <br>
  125. <br>
  126. You can specify the feature types
  127. that should appear in this browser or remove it from the list of resources by navigating to the " .
  128. l("Tripal feature settings page", "admin/tripal/chado/tripal_feature/configuration", array('attributes' => array('target' => '_blank'))) . "
  129. The feature browser will not appear to site visitors unless features are present. ",
  130. TRIPAL_INFO,
  131. array('return_html' => 1));
  132. }