tripal_featuremap_featurepos.tpl.php 5.3 KB

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