tripal_feature_featurepos.tpl.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 = [
  9. 'return_array' => 1,
  10. 'order_by' => [
  11. 'map_feature_id' => 'ASC',
  12. ],
  13. 'pager' => [
  14. 'limit' => $num_results_per_page,
  15. 'element' => $featurepos_pager_id,
  16. ],
  17. 'include_fk' => [
  18. 'map_feature_id' => [
  19. 'type_id' => 1,
  20. 'organism_id' => 1,
  21. ],
  22. 'featuremap_id' => [
  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
  36. feature is contained in the
  37. 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 = ['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 = [];
  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 = [
  53. 'return_array' => 1,
  54. 'include_fk' => [
  55. 'type_id' => 1,
  56. ],
  57. ];
  58. $position = chado_expand_var($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, ['attributes' => ['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, ['attributes' => ['target' => '_blank']]);
  90. }
  91. $rows[] = [
  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 = [
  103. 'header' => $headers,
  104. 'rows' => $rows,
  105. 'attributes' => [
  106. 'id' => 'tripal_feature-table-featurepos',
  107. 'class' => 'tripal-data-table',
  108. ],
  109. 'sticky' => FALSE,
  110. 'caption' => '',
  111. 'colgroups' => [],
  112. 'empty' => '',
  113. ];
  114. // once we have our table array structure defined, we call Drupal's theme_table()
  115. // function to generate the table.
  116. print theme_table($table);
  117. // the $pager array values that control the behavior of the pager. For
  118. // documentation on the values allows in this array see:
  119. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  120. // here we add the paramter 'block' => 'features'. This is because
  121. // the pager is not on the default block that appears. When the user clicks a
  122. // page number we want the browser to re-appear with the page is loaded.
  123. // We remove the 'pane' parameter from the original query parameters because
  124. // Drupal won't reset the parameter if it already exists.
  125. $get = $_GET;
  126. unset($_GET['pane']);
  127. $pager = [
  128. 'tags' => [],
  129. 'element' => $featurepos_pager_id,
  130. 'parameters' => [
  131. 'pane' => 'featurepos',
  132. ],
  133. 'quantity' => $num_results_per_page,
  134. ];
  135. print theme_pager($pager);
  136. $_GET = $get;
  137. }