tripal_pub_stocks.tpl.php 3.6 KB

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