tripal_organism_stocks.tpl.php

  1. 2.x tripal_stock/theme/templates/tripal_organism_stocks.tpl.php
  2. 3.x legacy/tripal_stock/theme/templates/tripal_organism_stocks.tpl.php
1 theme call to tripal_organism_stocks.tpl.php
tripal_stock_node_view in tripal_stock/includes/tripal_stock.chado_node.inc
Implements hook_node_view(). Acts on all content types.

File

tripal_stock/theme/templates/tripal_organism_stocks.tpl.php
View source
  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 = 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 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 (property_exists($stock, 'nid')) {
  42. $name = l($name, "node/$stock->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. 'class' => 'tripal-data-table'
  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. // We remove the 'pane' parameter from the original query parameters because
  75. // Drupal won't reset the parameter if it already exists.
  76. $get = $_GET;
  77. unset($_GET['pane']);
  78. $pager = array(
  79. 'tags' => array(),
  80. 'element' => $pager_id,
  81. 'parameters' => array(
  82. 'pane' => 'stocks'
  83. ),
  84. 'quantity' => $num_results_per_page,
  85. );
  86. print theme_pager($pager);
  87. $_GET = $get;
  88. }