tripal_library_features.tpl.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. $library = $variables['node']->library;
  3. // get the feature_id's of the features that belong to this library. But we only
  4. // want 25 and we want a pager to let the user cycle between pages of features.
  5. // so we, use the chado_select_record API function to get the results and
  6. // generate the pager. The function is smart enough to know which page the user is
  7. // on and retrieves the proper set of features
  8. $element = 0; // an index to specify the pager if more than one is on the page
  9. $num_per_page = 25; // the number of features to show per page
  10. $values = array(
  11. 'library_id' => $library->library_id,
  12. );
  13. $columns = array('feature_id');
  14. $options = array(
  15. 'pager' => array(
  16. 'limit' => $num_per_page,
  17. 'element' => $element
  18. ),
  19. );
  20. $results = chado_select_record('library_feature', $columns, $values, $options);
  21. // now that we have all of the feature IDs, we want to expand each one so that we
  22. // have all of the neccessary values, including the node ID, if one exists, and the
  23. // cvterm type name.
  24. $features = array();
  25. foreach ($results as $library_feature) {
  26. $values = array('feature_id' => $library_feature->feature_id);
  27. $options = array(
  28. 'include_fk' => array(
  29. 'type_id' => 1
  30. )
  31. );
  32. $features[] = chado_generate_var('feature', $values, $options);
  33. }
  34. if (count($features) > 0) { ?>
  35. <div class="tripal_library-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
  36. // the $headers array is an array of fields to use as the colum headers.
  37. // additional documentation can be found here
  38. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  39. $headers = array('Feature Name' ,'Unique Name', 'Type');
  40. // the $rows array contains an array of rows where each row is an array
  41. // of values for each column of the table in that row. Additional documentation
  42. // can be found here:
  43. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  44. $rows = array();
  45. foreach ($features as $feature){
  46. $fname = $feature->name;
  47. if (property_exists($feature, 'nid')) {
  48. $fname = l($fname, "node/$feature->nid", array('attributes' => array('target' => '_blank')));
  49. }
  50. $rows[] = array(
  51. $fname,
  52. $feature->uniquename,
  53. $feature->type_id->name
  54. );
  55. }
  56. // the $table array contains the headers and rows array as well as other
  57. // options for controlling the display of the table. Additional
  58. // documentation can be found here:
  59. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  60. $table = array(
  61. 'header' => $headers,
  62. 'rows' => $rows,
  63. 'attributes' => array(
  64. 'id' => 'tripal_library-table-features',
  65. 'class' => 'tripal-data-table'
  66. ),
  67. 'sticky' => FALSE,
  68. 'caption' => '',
  69. 'colgroups' => array(),
  70. 'empty' => '',
  71. );
  72. // once we have our table array structure defined, we call Drupal's theme_table()
  73. // function to generate the table.
  74. print theme_table($table);
  75. // the $pager array values that control the behavior of the pager. For
  76. // documentation on the values allows in this array see:
  77. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  78. // here we add the paramter 'block' => 'feature_browser'. This is because
  79. // the pager is not on the default block that appears. When the user clicks a
  80. // page number we want the browser to re-appear with the page is loaded.
  81. // We remove the 'pane' parameter from the original query parameters because
  82. // Drupal won't reset the parameter if it already exists.
  83. $get = $_GET;
  84. unset($_GET['pane']);
  85. $pager = array(
  86. 'tags' => array(),
  87. 'element' => $element,
  88. 'parameters' => array(
  89. 'pane' => 'features'
  90. ),
  91. 'quantity' => $num_per_page,
  92. );
  93. print theme_pager($pager);
  94. $_GET = $get;
  95. }