tripal_featuremap_featurepos.tpl.php

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

File

tripal_featuremap/theme/templates/tripal_featuremap_featurepos.tpl.php
View source
  1. <?php
  2. $featuremap = $variables['node']->featuremap;
  3. $feature_positions = array();
  4. // expand the featuremap object to include the records from the featurepos table
  5. // specify the number of features to show by default and the unique pager ID
  6. $num_results_per_page = 25;
  7. $featurepos_pager_id = 0;
  8. // get the features aligned on this map
  9. $options = array(
  10. 'return_array' => 1,
  11. 'order_by' => array('map_feature_id' => 'ASC'),
  12. 'pager' => array(
  13. 'limit' => $num_results_per_page,
  14. 'element' => $featurepos_pager_id
  15. ),
  16. 'include_fk' => array(
  17. 'map_feature_id' => array(
  18. 'type_id' => 1,
  19. 'organism_id' => 1,
  20. ),
  21. 'feature_id' => array(
  22. 'type_id' => 1,
  23. ),
  24. 'featuremap_id' => array(
  25. 'unittype_id' => 1,
  26. ),
  27. ),
  28. );
  29. $featuremap = chado_expand_var($featuremap, 'table', 'featurepos', $options);
  30. $feature_positions = $featuremap->featurepos;
  31. // get the total number of records
  32. $total_features = chado_pager_get_count($featurepos_pager_id);
  33. if(count($feature_positions) > 0){ ?>
  34. <div class="tripal_featuremap-data-block-desc tripal-data-block-desc">This map contains <?php print number_format($total_features) ?> features:</div> <?php
  35. // the $headers array is an array of fields to use as the colum headers.
  36. // additional documentation can be found here
  37. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  38. $headers = array('Landmark', 'Type', 'Organism', 'Feature Name', 'Type', 'Position');
  39. // the $rows array contains an array of rows where each row is an array
  40. // of values for each column of the table in that row. Additional documentation
  41. // can be found here:
  42. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  43. $rows = array();
  44. foreach ($feature_positions as $position){
  45. $map_feature = $position->map_feature_id;
  46. $feature = $position->feature_id;
  47. $organism = $map_feature->organism_id;
  48. // check if there are any values in the featureposprop table for the start and stop
  49. $mappos = $position->mappos;
  50. $options = array(
  51. 'return_array' => 1,
  52. 'include_fk' => array(
  53. 'type_id' => 1,
  54. ),
  55. );
  56. $position = chado_expand_var($position, 'table', 'featureposprop', $options);
  57. $featureposprop = $position->featureposprop;
  58. $start = 0;
  59. $stop = 0;
  60. if (is_array($featureposprop)) {
  61. foreach ($featureposprop as $index => $property) {
  62. if ($property->type_id->name == 'start') {
  63. $start = $property->value;
  64. }
  65. if ($property->type_id->name == 'stop') {
  66. $stop = $property->value;
  67. }
  68. }
  69. }
  70. if ($start and $stop and $start != $stop) {
  71. $mappos = "$start-$stop";
  72. }
  73. if ($start and !$stop) {
  74. $mappos = $start;
  75. }
  76. if ($start and $stop and $start == $stop) {
  77. $mappos = $start;
  78. }
  79. $mfname = $map_feature->name;
  80. if (property_exists($map_feature, 'nid')) {
  81. $mfname = l($mfname, 'node/' . $map_feature->nid, array('attributes' => array('target' => '_blank')));
  82. }
  83. $orgname = $organism->genus ." " . $organism->species ." (" . $organism->common_name .")";
  84. if (property_exists($organism, 'nid')) {
  85. $orgname = l(
  86. "<i>" . $organism->genus . " " . $organism->species . "</i> (" . $organism->common_name .")",
  87. "node/". $organism->nid,
  88. array('html' => TRUE, 'attributes' => array('target' => '_blank'))
  89. );
  90. }
  91. $organism = $organism->genus . ' ' . $organism->species;
  92. $fname = $feature->name;
  93. if (property_exists($feature, 'nid')) {
  94. $fname = l($fname, 'node/' . $feature->nid, array('attributes' => array('target' => '_blank')));
  95. }
  96. $rows[] = array(
  97. $mfname,
  98. $map_feature->type_id->name,
  99. $orgname,
  100. $fname,
  101. $feature->type_id->name,
  102. $mappos . ' ' . $position->featuremap_id->unittype_id->name
  103. );
  104. }
  105. // the $table array contains the headers and rows array as well as other
  106. // options for controlling the display of the table. Additional
  107. // documentation can be found here:
  108. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  109. $table = array(
  110. 'header' => $headers,
  111. 'rows' => $rows,
  112. 'attributes' => array(
  113. 'id' => 'tripal_featuremap-table-featurepos',
  114. 'class' => 'tripal-data-table'
  115. ),
  116. 'sticky' => FALSE,
  117. 'caption' => '',
  118. 'colgroups' => array(),
  119. 'empty' => '',
  120. );
  121. // once we have our table array structure defined, we call Drupal's theme_table()
  122. // function to generate the table.
  123. print theme_table($table);
  124. // the $pager array values that control the behavior of the pager. For
  125. // documentation on the values allows in this array see:
  126. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  127. // here we add the paramter 'block' => 'features'. This is because
  128. // the pager is not on the default block that appears. When the user clicks a
  129. // page number we want the browser to re-appear with the page is loaded.
  130. // We remove the 'pane' parameter from the original query parameters because
  131. // Drupal won't reset the parameter if it already exists.
  132. $get = $_GET;
  133. unset($_GET['pane']);
  134. $pager = array(
  135. 'tags' => array(),
  136. 'element' => $featurepos_pager_id,
  137. 'parameters' => array(
  138. 'pane' => 'featurepos'
  139. ),
  140. 'quantity' => $num_results_per_page,
  141. );
  142. print theme_pager($pager);
  143. $_GET = $get;
  144. }