tripal_organism_stocks.tpl.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. $organism = $variables['node']->organism;
  3. // expand the featuremap object to include the records from the featurepos table
  4. // specify the number of features to show by default and the unique pager ID
  5. $num_results_per_page = 25;
  6. $pager_id = 3;
  7. // get the features aligned on this map
  8. $options = array(
  9. 'return_array' => 1,
  10. 'order_by' => array('name' => 'ASC'),
  11. 'pager' => array(
  12. 'limit' => $num_results_per_page,
  13. 'element' => $pager_id
  14. ),
  15. 'include_fk' => array(
  16. 'type_id' => 1
  17. ),
  18. );
  19. $organism = tripal_core_expand_chado_vars($organism, 'table', 'stock', $options);
  20. $stocks = $organism->stock;
  21. // create the pager.
  22. // the total number of records for the paged query is stored in a session variable
  23. $total_records = $_SESSION['chado_pager'][$pager_id]['total_records'];
  24. if (count($stocks) > 0) { ?>
  25. <div id="tripal_organism-stocks-box" class="tripal_organism-info-box tripal-info-box">
  26. <div class="tripal_organism-info-box-title tripal-info-box-title">Stocks</div>
  27. <div class="tripal_organism-info-box-desc tripal-info-box-desc">This organism is associated with <?php print number_format($total_records) ?> stock(s):</div> <?php
  28. // the $headers array is an array of fields to use as the colum headers.
  29. // additional documentation can be found here
  30. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  31. // This table for the analysis has a vertical header (down the first column)
  32. // so we do not provide headers here, but specify them in the $rows array below.
  33. $headers = array('Name', '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. $name = $stock->name;
  41. if (!$name) {
  42. $name = $stock->uniquename;
  43. }
  44. if ($stock->nid) {
  45. $name = l($name, "node/$stock->nid", array('attributes' => array('target' => '_blank')));
  46. }
  47. $rows[] = array(
  48. $name,
  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_organism-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' => 'features'. 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' => $pager_id,
  79. 'parameters' => array(
  80. 'block' => 'stocks'
  81. ),
  82. 'quantity' => $num_results_per_page,
  83. );
  84. print theme_pager($pager); ?>
  85. </div> <?php
  86. }