tripal_pub_featuremaps.tpl.php 3.6 KB

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