tripal_pub_features.tpl.php 3.6 KB

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