tripal_pub_stocks.tpl.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 tripal_core_chado_select 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 = tripal_core_expand_chado_vars($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. // the total number of records for the paged query is stored in a session variable
  27. $total_records = $_SESSION['chado_pager'][$element]['total_records'];
  28. if(count($stocks) > 0){ ?>
  29. <div id="tripal_pub-stocks-box" class="tripal_pub-info-box tripal-info-box">
  30. <div class="tripal_pub-info-box-title tripal-info-box-title">Stocks</div>
  31. <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_records) ?> stocks:</div> <?php
  32. // the $headers array is an array of fields to use as the colum headers.
  33. // additional documentation can be found here
  34. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  35. $headers = array('Stock Name', 'Uniquenaem', 'Type');
  36. // the $rows array contains an array of rows where each row is an array
  37. // of values for each column of the table in that row. Additional documentation
  38. // can be found here:
  39. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  40. $rows = array();
  41. foreach ($stocks as $stock){
  42. $stock_name = $stock->name;
  43. if (property_exists($stock, 'nid')) {
  44. $stock_name = l($stock_name, 'node/' . $stock->nid, array('attributes' => array('target' => '_blank')));
  45. }
  46. $rows[] = array(
  47. $stock_name,
  48. $stock->uniquename,
  49. $stock->type_id->name,
  50. );
  51. }
  52. // the $table array contains the headers and rows array as well as other
  53. // options for controlling the display of the table. Additional
  54. // documentation can be found here:
  55. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  56. $table = array(
  57. 'header' => $headers,
  58. 'rows' => $rows,
  59. 'attributes' => array(
  60. 'id' => 'tripal_pub-table-stocks',
  61. ),
  62. 'sticky' => FALSE,
  63. 'caption' => '',
  64. 'colgroups' => array(),
  65. 'empty' => '',
  66. );
  67. // once we have our table array structure defined, we call Drupal's theme_table()
  68. // function to generate the table.
  69. print theme_table($table);
  70. // the $pager array values that control the behavior of the pager. For
  71. // documentation on the values allows in this array see:
  72. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  73. // here we add the paramter 'block' => 'stocks'. This is because
  74. // the pager is not on the default block that appears. When the user clicks a
  75. // page number we want the browser to re-appear with the page is loaded.
  76. $pager = array(
  77. 'tags' => array(),
  78. 'element' => $element,
  79. 'parameters' => array(
  80. 'block' => 'stocks'
  81. ),
  82. 'quantity' => $num_per_page,
  83. );
  84. print theme_pager($pager); ?>
  85. </div><?php
  86. }?>