tripal_organism_stocks.tpl.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 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
  26. // the $headers array is an array of fields to use as the colum headers.
  27. // additional documentation can be found here
  28. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  29. // This table for the analysis has a vertical header (down the first column)
  30. // so we do not provide headers here, but specify them in the $rows array below.
  31. $headers = array('Name', 'Type');
  32. // the $rows array contains an array of rows where each row is an array
  33. // of values for each column of the table in that row. Additional documentation
  34. // can be found here:
  35. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  36. $rows = array();
  37. foreach ($stocks as $stock){
  38. $name = $stock->name;
  39. if (!$name) {
  40. $name = $stock->uniquename;
  41. }
  42. if ($stock->nid) {
  43. $name = l($name, "node/$stock->nid", array('attributes' => array('target' => '_blank')));
  44. }
  45. $rows[] = array(
  46. $name,
  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_organism-table-stocks',
  59. ),
  60. 'sticky' => FALSE,
  61. 'caption' => '',
  62. 'colgroups' => array(),
  63. 'empty' => '',
  64. );
  65. // once we have our table array structure defined, we call Drupal's theme_table()
  66. // function to generate the table.
  67. print theme_table($table);
  68. // the $pager array values that control the behavior of the pager. For
  69. // documentation on the values allows in this array see:
  70. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  71. // here we add the paramter 'block' => 'features'. This is because
  72. // the pager is not on the default block that appears. When the user clicks a
  73. // page number we want the browser to re-appear with the page is loaded.
  74. $pager = array(
  75. 'tags' => array(),
  76. 'element' => $pager_id,
  77. 'parameters' => array(
  78. 'block' => 'stocks'
  79. ),
  80. 'quantity' => $num_results_per_page,
  81. );
  82. print theme_pager($pager);
  83. }