tripal_organism_stocks.tpl.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 = [
  9. 'return_array' => 1,
  10. 'order_by' => ['name' => 'ASC'],
  11. 'pager' => [
  12. 'limit' => $num_results_per_page,
  13. 'element' => $pager_id,
  14. ],
  15. 'include_fk' => [
  16. 'type_id' => 1,
  17. ],
  18. ];
  19. $organism = chado_expand_var($organism, 'table', 'stock', $options);
  20. $stocks = $organism->stock;
  21. // get the total number of records
  22. $total_records = chado_pager_get_count($pager_id);
  23. if (count($stocks) > 0) { ?>
  24. <div class="tripal_organism-data-block-desc tripal-data-block-desc">This
  25. organism is associated with <?php print number_format($total_records) ?>
  26. stock(s):
  27. </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 = ['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 = [];
  39. foreach ($stocks as $stock) {
  40. $name = $stock->name;
  41. if (!$name) {
  42. $name = $stock->uniquename;
  43. }
  44. if (property_exists($stock, 'nid')) {
  45. $name = l($name, "node/$stock->nid", ['attributes' => ['target' => '_blank']]);
  46. }
  47. $rows[] = [
  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 = [
  57. 'header' => $headers,
  58. 'rows' => $rows,
  59. 'attributes' => [
  60. 'id' => 'tripal_organism-table-stocks',
  61. 'class' => 'tripal-data-table',
  62. ],
  63. 'sticky' => FALSE,
  64. 'caption' => '',
  65. 'colgroups' => [],
  66. 'empty' => '',
  67. ];
  68. // once we have our table array structure defined, we call Drupal's theme_table()
  69. // function to generate the table.
  70. print theme_table($table);
  71. // the $pager array values that control the behavior of the pager. For
  72. // documentation on the values allows in this array see:
  73. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  74. // here we add the paramter 'block' => 'features'. This is because
  75. // the pager is not on the default block that appears. When the user clicks a
  76. // page number we want the browser to re-appear with the page is loaded.
  77. // We remove the 'pane' parameter from the original query parameters because
  78. // Drupal won't reset the parameter if it already exists.
  79. $get = $_GET;
  80. unset($_GET['pane']);
  81. $pager = [
  82. 'tags' => [],
  83. 'element' => $pager_id,
  84. 'parameters' => [
  85. 'pane' => 'stocks',
  86. ],
  87. 'quantity' => $num_results_per_page,
  88. ];
  89. print theme_pager($pager);
  90. $_GET = $get;
  91. }