tripal_feature_featurepos.tpl.php

  1. 2.x tripal_featuremap/theme/templates/tripal_feature_featurepos.tpl.php
  2. 3.x legacy/tripal_featuremap/theme/templates/tripal_feature_featurepos.tpl.php
1 theme call to tripal_feature_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_feature_featurepos.tpl.php
View source
  1. <?php
  2. // expand the feature object to include the records from the featurepos table
  3. // specify the number of features to show by default and the unique pager ID
  4. $num_results_per_page = 5;
  5. $featurepos_pager_id = 20;
  6. // get the maps associated with this feature
  7. $feature = $variables['node']->feature;
  8. $options = array(
  9. 'return_array' => 1,
  10. 'order_by' => array(
  11. 'map_feature_id' => 'ASC'
  12. ),
  13. 'pager' => array(
  14. 'limit' => $num_results_per_page,
  15. 'element' => $featurepos_pager_id
  16. ),
  17. 'include_fk' => array(
  18. 'map_feature_id' => array(
  19. 'type_id' => 1,
  20. 'organism_id' => 1,
  21. ),
  22. 'featuremap_id' => array(
  23. 'unittype_id' => 1,
  24. ),
  25. ),
  26. );
  27. $feature = chado_expand_var($feature, 'table', 'featurepos', $options);
  28. // because the featurepos table has FK relationships with map_feature_id and feature_id with the feature table
  29. // the function call above will try to expand both and will create an array of matches for each FK.
  30. // we only want to show the map that this feature belongs to
  31. $map_positions = $feature->featurepos->map_feature_id;
  32. // get the total number of records
  33. $total_records = chado_pager_get_count($featurepos_pager_id);
  34. if(count($map_positions) > 0){ ?>
  35. <div class="tripal_feature-data-block-desc tripal-data-block-desc">This feature is contained in the following <?php print number_format($total_records) ?> map(s):</div><?php
  36. // the $headers array is an array of fields to use as the colum headers.
  37. // additional documentation can be found here
  38. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  39. $headers = array('Map Name', 'Landmark', 'Type', 'Position');
  40. // the $rows array contains an array of rows where each row is an array
  41. // of values for each column of the table in that row. Additional documentation
  42. // can be found here:
  43. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  44. $rows = array();
  45. // iterate through our map positions
  46. foreach ($map_positions as $position){
  47. $map_feature = $position->map_feature_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 = '';
  59. $stop = '';
  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. // get the map name feature
  80. $map_name = $position->featuremap_id->name;
  81. if (property_exists($position->featuremap_id, 'nid')) {
  82. $map_name = l($map_name, 'node/' . $position->featuremap_id->nid, array('attributes' => array('target' => '_blank')));
  83. }
  84. // get the landmark
  85. $landmark = $map_feature->name;
  86. if (property_exists($map_feature, 'nid')) {
  87. $landmark = l($landmark, 'node/' . $map_feature->nid, array('attributes' => array('target' => '_blank')));
  88. }
  89. $rows[] = array(
  90. $map_name,
  91. $landmark,
  92. $map_feature->type_id->name,
  93. $mappos . ' ' . $position->featuremap_id->unittype_id->name,
  94. );
  95. }
  96. // the $table array contains the headers and rows array as well as other
  97. // options for controlling the display of the table. Additional
  98. // documentation can be found here:
  99. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  100. $table = array(
  101. 'header' => $headers,
  102. 'rows' => $rows,
  103. 'attributes' => array(
  104. 'id' => 'tripal_feature-table-featurepos',
  105. 'class' => 'tripal-data-table'
  106. ),
  107. 'sticky' => FALSE,
  108. 'caption' => '',
  109. 'colgroups' => array(),
  110. 'empty' => '',
  111. );
  112. // once we have our table array structure defined, we call Drupal's theme_table()
  113. // function to generate the table.
  114. print theme_table($table);
  115. // the $pager array values that control the behavior of the pager. For
  116. // documentation on the values allows in this array see:
  117. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  118. // here we add the paramter 'block' => 'features'. This is because
  119. // the pager is not on the default block that appears. When the user clicks a
  120. // page number we want the browser to re-appear with the page is loaded.
  121. // We remove the 'pane' parameter from the original query parameters because
  122. // Drupal won't reset the parameter if it already exists.
  123. $get = $_GET;
  124. unset($_GET['pane']);
  125. $pager = array(
  126. 'tags' => array(),
  127. 'element' => $featurepos_pager_id,
  128. 'parameters' => array(
  129. 'pane' => 'featurepos'
  130. ),
  131. 'quantity' => $num_results_per_page,
  132. );
  133. print theme_pager($pager);
  134. $_GET = $get;
  135. }?>