tripal_feature_genotypes.tpl.php

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

File

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