tripal_feature_featurepos.tpl.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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->feature_id;
  32. // the total number of records for the paged query is stored in a session variable
  33. $total_records = $_SESSION['chado_pager'][$featurepos_pager_id]['total_records'];
  34. if(count($map_positions) > 0){ ?>
  35. <div id="tripal_feature-featurepos-box" class="tripal_feature-info-box tripal-info-box">
  36. <div class="tripal_feature-info-box-title tripal-info-box-title">Maps</div>
  37. <div class="tripal_feature-info-box-desc tripal-info-box-desc">This feature is contained in the following <?php print number_format($total_records) ?> map(s):</div><?php
  38. // the $headers array is an array of fields to use as the colum headers.
  39. // additional documentation can be found here
  40. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  41. $headers = array('Map Name', 'Landmark', 'Type', 'Position');
  42. // the $rows array contains an array of rows where each row is an array
  43. // of values for each column of the table in that row. Additional documentation
  44. // can be found here:
  45. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  46. $rows = array();
  47. // iterate through our map positions
  48. foreach ($map_positions as $position){
  49. $map_feature = $position->map_feature_id;
  50. // check if there are any values in the featureposprop table for the start and stop
  51. $mappos = $position->mappos;
  52. $options = array(
  53. 'return_array' => 1,
  54. 'include_fk' => array(
  55. 'type_id' => 1,
  56. ),
  57. );
  58. $position = tripal_core_expand_chado_vars($position, 'table', 'featureposprop', $options);
  59. $featureposprop = $position->featureposprop;
  60. $start = '';
  61. $stop = '';
  62. if (is_array($featureposprop)) {
  63. foreach ($featureposprop as $index => $property) {
  64. if ($property->type_id->name == 'start') {
  65. $start = $property->value;
  66. }
  67. if ($property->type_id->name == 'stop') {
  68. $stop = $property->value;
  69. }
  70. }
  71. }
  72. if ($start and $stop and $start != $stop) {
  73. $mappos = "$start-$stop";
  74. }
  75. if ($start and !$stop) {
  76. $mappos = $start;
  77. }
  78. if ($start and $stop and $start == $stop) {
  79. $mappos = $start;
  80. }
  81. // get the map name feature
  82. $map_name = $position->featuremap_id->name;
  83. if (property_exists($position->featuremap_id, 'nid')) {
  84. $map_name = l($map_name, 'node/' . $position->featuremap_id->nid, array('attributes' => array('target' => '_blank')));
  85. }
  86. // get the landmark
  87. $landmark = $map_feature->name;
  88. if (property_exists($map_feature, 'nid')) {
  89. $landmark = l($landmark, 'node/' . $map_feature->nid, array('attributes' => array('target' => '_blank')));
  90. }
  91. $rows[] = array(
  92. $map_name,
  93. $landmark,
  94. $map_feature->type_id->name,
  95. $mappos . ' ' . $position->featuremap_id->unittype_id->name,
  96. );
  97. }
  98. // the $table array contains the headers and rows array as well as other
  99. // options for controlling the display of the table. Additional
  100. // documentation can be found here:
  101. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  102. $table = array(
  103. 'header' => $headers,
  104. 'rows' => $rows,
  105. 'attributes' => array(
  106. 'id' => 'tripal_feature-table-featurepos',
  107. ),
  108. 'sticky' => FALSE,
  109. 'caption' => '',
  110. 'colgroups' => array(),
  111. 'empty' => '',
  112. );
  113. // once we have our table array structure defined, we call Drupal's theme_table()
  114. // function to generate the table.
  115. print theme_table($table);
  116. // the $pager array values that control the behavior of the pager. For
  117. // documentation on the values allows in this array see:
  118. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  119. // here we add the paramter 'block' => 'features'. This is because
  120. // the pager is not on the default block that appears. When the user clicks a
  121. // page number we want the browser to re-appear with the page is loaded.
  122. $pager = array(
  123. 'tags' => array(),
  124. 'element' => $featurepos_pager_id,
  125. 'parameters' => array(
  126. 'block' => 'featurepos'
  127. ),
  128. 'quantity' => $num_results_per_page,
  129. );
  130. print theme_pager($pager); ?>
  131. </div> <?php
  132. }?>