tripal_stock_genotypes.tpl.php

  1. 2.x tripal_genetic/theme/templates/tripal_stock_genotypes.tpl.php
  2. 3.x legacy/tripal_genetic/theme/templates/tripal_stock_genotypes.tpl.php
1 theme call to tripal_stock_genotypes.tpl.php
tripal_genetic_node_view in tripal_genetic/tripal_genetic.module
Implements hook_node_view(). Acts on all content types

File

tripal_genetic/theme/templates/tripal_stock_genotypes.tpl.php
View source
  1. <?php
  2. /*
  3. * Details about genotypes associated with stocks can be found in two ways by
  4. * traversing the the foreign key (FK) relationships in these ways:
  5. *
  6. * Simple Method: stock => stock_genotype => genotype
  7. * ND Method: stock => nd_experiment_stock => nd_experiment => nd_experiment_genotype => genotype
  8. *
  9. * The tripal_natural_diversity module handles display of genotypes when stored using the
  10. * ND method. This template handles display of genotype when stored using
  11. * the Simple Method. If the tripal_natural_diversity module is enabled then this template
  12. * will not show. You should instead see the tripal_stock.nd_genotypes.tpl.php template
  13. *
  14. */
  15. $stock = $variables['node']->stock;
  16. // specify the number of genotypes to show by default and the unique pager ID
  17. $num_results_per_page = 25;
  18. $stock_pager_id = 15;
  19. // get the genotypes from the stock_genotype table
  20. $options = array(
  21. 'return_array' => 1,
  22. 'pager' => array(
  23. 'limit' => $num_results_per_page,
  24. 'element' => $stock_pager_id
  25. ),
  26. 'fk_include' => array(
  27. 'genotype_id' => 1
  28. ),
  29. );
  30. $stock = chado_expand_var($stock, 'table', 'stock_genotype', $options);
  31. $stock_genotypes = $stock->stock_genotype;
  32. // get the total number of records
  33. $total_records = chado_pager_get_count($stock_pager_id);
  34. // now iterate through the stock genotypes and print a paged table.
  35. if (count($stock_genotypes) > 0) {?>
  36. <div class="tripal_stock-data-block-desc tripal-data-block-desc">The following <?php print number_format($total_records) ?> genotype(s) have been recorded for this stock.</div> <?php
  37. // the $headers array is an array of fields to use as the colum headers.
  38. // additional documentation can be found here
  39. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  40. $headers = array('Name', 'Type', 'Genotype', 'Details', 'Markers');
  41. // the $rows array contains an array of rows where each row is an array
  42. // of values for each column of the table in that row. Additional documentation
  43. // can be found here:
  44. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  45. $rows = array();
  46. foreach($stock_genotypes as $stock_genotype) {
  47. $genotype = $stock_genotype->genotype_id;
  48. // get the genotype properties
  49. $options = array('return_array' => 1);
  50. $genotype = chado_expand_var($genotype, 'table', 'genotypeprop', $options);
  51. $properties = $genotype->genotypeprop;
  52. // add in markers associated with this genotype if any
  53. $options = array(
  54. 'return_array' => 1,
  55. 'inlude_fk' => array(
  56. 'feature_id' => array(
  57. 'type_id' => 1
  58. )
  59. ),
  60. );
  61. $genotype = chado_expand_var($genotype, 'table', 'feature_genotype', $options);
  62. $feature_genotypes = $genotype->feature_genotype;
  63. // show the uniquename for the genotype unless a name exists
  64. $name = $genotype->uniquename;
  65. if ($genotype->name){
  66. $name = $genotype->name;
  67. }
  68. // get the genotype type
  69. $type = 'N/A';
  70. if ($genotype->type_id) {
  71. $type = ucwords(preg_replace('/_/', ' ', $genotype->type_id->name));
  72. }
  73. // get the genotype properties
  74. $details = '';
  75. if(count($properties) > 0) {
  76. foreach ($properties as $property){
  77. $details .= ucwords(preg_replace('/_/', ' ', $property->type_id->name)) . ': ' . $property->value . '<br>';
  78. }
  79. $details = substr($details, 0, -4); // remove trailing <br>
  80. }
  81. // build the list of marker features.
  82. $feature_names = 'N/A';
  83. if(count($feature_genotypes) > 0) {
  84. $feature_names = '';
  85. foreach ($feature_genotypes as $feature_genotype){
  86. $feature = $feature_genotype->feature_id;
  87. $feature_name = $feature->name . ' (' . $feature->uniquename . ')';
  88. if(property_exists($feature, 'nid')) {
  89. $feature_name = l($feature_name, 'node/' . $feature->nid, array('attributes' => array('target' => '_blank')));
  90. }
  91. $feature_names .= $feature_name . '<br>';
  92. }
  93. $feature_names = substr($feature_names, 0, -4); // remove trailing <br>
  94. }
  95. // add the fields to the table row
  96. $rows[] = array(
  97. $name,
  98. $type,
  99. $genotype->description,
  100. $details,
  101. $feature_names
  102. );
  103. }
  104. // the $table array contains the headers and rows array as well as other
  105. // options for controlling the display of the table. Additional
  106. // documentation can be found here:
  107. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  108. $table = array(
  109. 'header' => $headers,
  110. 'rows' => $rows,
  111. 'attributes' => array(
  112. 'id' => 'tripal_genetic-table-genotypes',
  113. 'class' => 'tripal-data-table'
  114. ),
  115. 'sticky' => FALSE,
  116. 'caption' => '',
  117. 'colgroups' => array(),
  118. 'empty' => '',
  119. );
  120. // once we have our table array structure defined, we call Drupal's theme_table()
  121. // function to generate the table.
  122. print theme_table($table);
  123. // the $pager array values that control the behavior of the pager. For
  124. // documentation on the values allows in this array see:
  125. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  126. // here we add the paramter 'block' => 'features'. This is because
  127. // the pager is not on the default block that appears. When the user clicks a
  128. // page number we want the browser to re-appear with the page is loaded.
  129. // We remove the 'pane' parameter from the original query parameters because
  130. // Drupal won't reset the parameter if it already exists.
  131. $get = $_GET;
  132. unset($_GET['pane']);
  133. $pager = array(
  134. 'tags' => array(),
  135. 'element' => $stock_pager_id,
  136. 'parameters' => array(
  137. 'pane' => 'genotypes'
  138. ),
  139. 'quantity' => $num_results_per_page,
  140. );
  141. print theme_pager($pager);
  142. $_GET = $get;
  143. }