tripal_feature_featurepos.tpl.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 = 25;
  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 = tripal_core_expand_chado_vars($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. dpm($feature);
  33. // the total number of records for the paged query is stored in a session variable
  34. $total_records = chado_pager_get_count($featurepos_pager_id);
  35. if(count($map_positions) > 0){ ?>
  36. <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
  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('Map Name', 'Landmark', 'Type', 'Position');
  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. // iterate through our map positions
  47. foreach ($map_positions as $position){
  48. $map_feature = $position->map_feature_id;
  49. // check if there are any values in the featureposprop table for the start and stop
  50. $mappos = $position->mappos;
  51. $options = array(
  52. 'return_array' => 1,
  53. 'include_fk' => array(
  54. 'type_id' => 1,
  55. ),
  56. );
  57. $position = tripal_core_expand_chado_vars($position, 'table', 'featureposprop', $options);
  58. $featureposprop = $position->featureposprop;
  59. $start = '';
  60. $stop = '';
  61. if (is_array($featureposprop)) {
  62. foreach ($featureposprop as $index => $property) {
  63. if ($property->type_id->name == 'start') {
  64. $start = $property->value;
  65. }
  66. if ($property->type_id->name == 'stop') {
  67. $stop = $property->value;
  68. }
  69. }
  70. }
  71. if ($start and $stop and $start != $stop) {
  72. $mappos = "$start-$stop";
  73. }
  74. if ($start and !$stop) {
  75. $mappos = $start;
  76. }
  77. if ($start and $stop and $start == $stop) {
  78. $mappos = $start;
  79. }
  80. // get the map name feature
  81. $map_name = $position->featuremap_id->name;
  82. if (property_exists($position->featuremap_id, 'nid')) {
  83. $map_name = l($map_name, 'node/' . $position->featuremap_id->nid, array('attributes' => array('target' => '_blank')));
  84. }
  85. // get the landmark
  86. $landmark = $map_feature->name;
  87. if (property_exists($map_feature, 'nid')) {
  88. $landmark = l($landmark, 'node/' . $map_feature->nid, array('attributes' => array('target' => '_blank')));
  89. }
  90. $rows[] = array(
  91. $map_name,
  92. $landmark,
  93. $map_feature->type_id->name,
  94. $mappos . ' ' . $position->featuremap_id->unittype_id->name,
  95. );
  96. }
  97. // the $table array contains the headers and rows array as well as other
  98. // options for controlling the display of the table. Additional
  99. // documentation can be found here:
  100. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  101. $table = array(
  102. 'header' => $headers,
  103. 'rows' => $rows,
  104. 'attributes' => array(
  105. 'id' => 'tripal_feature-table-featurepos',
  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. $pager = array(
  122. 'tags' => array(),
  123. 'element' => $featurepos_pager_id,
  124. 'parameters' => array(
  125. 'block' => 'featurepos'
  126. ),
  127. 'quantity' => $num_results_per_page,
  128. );
  129. print theme_pager($pager);
  130. }?>