tripal_organism_stocks.tpl.php 3.1 KB

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