tripal_library_features.tpl.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 = [
  11. 'library_id' => $library->library_id,
  12. ];
  13. $columns = ['feature_id'];
  14. $options = [
  15. 'pager' => [
  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 = [];
  25. foreach ($results as $library_feature) {
  26. $values = ['feature_id' => $library_feature->feature_id];
  27. $options = [
  28. 'include_fk' => [
  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
  36. following browser provides a quick view for new visitors. Use the
  37. searching mechanism to find specific features.
  38. </div> <?php
  39. // the $headers array is an array of fields to use as the colum headers.
  40. // additional documentation can be found here
  41. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  42. $headers = ['Feature Name', 'Unique Name', 'Type'];
  43. // the $rows array contains an array of rows where each row is an array
  44. // of values for each column of the table in that row. Additional documentation
  45. // can be found here:
  46. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  47. $rows = [];
  48. foreach ($features as $feature) {
  49. $fname = $feature->name;
  50. if (property_exists($feature, 'nid')) {
  51. $fname = l($fname, "node/$feature->nid", ['attributes' => ['target' => '_blank']]);
  52. }
  53. $rows[] = [
  54. $fname,
  55. $feature->uniquename,
  56. $feature->type_id->name,
  57. ];
  58. }
  59. // the $table array contains the headers and rows array as well as other
  60. // options for controlling the display of the table. Additional
  61. // documentation can be found here:
  62. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  63. $table = [
  64. 'header' => $headers,
  65. 'rows' => $rows,
  66. 'attributes' => [
  67. 'id' => 'tripal_library-table-features',
  68. 'class' => 'tripal-data-table',
  69. ],
  70. 'sticky' => FALSE,
  71. 'caption' => '',
  72. 'colgroups' => [],
  73. 'empty' => '',
  74. ];
  75. // once we have our table array structure defined, we call Drupal's theme_table()
  76. // function to generate the table.
  77. print theme_table($table);
  78. // the $pager array values that control the behavior of the pager. For
  79. // documentation on the values allows in this array see:
  80. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  81. // here we add the paramter 'block' => 'feature_browser'. This is because
  82. // the pager is not on the default block that appears. When the user clicks a
  83. // page number we want the browser to re-appear with the page is loaded.
  84. // We remove the 'pane' parameter from the original query parameters because
  85. // Drupal won't reset the parameter if it already exists.
  86. $get = $_GET;
  87. unset($_GET['pane']);
  88. $pager = [
  89. 'tags' => [],
  90. 'element' => $element,
  91. 'parameters' => [
  92. 'pane' => 'features',
  93. ],
  94. 'quantity' => $num_per_page,
  95. ];
  96. print theme_pager($pager);
  97. $_GET = $get;
  98. }