tripal_feature_featurepos.tpl.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. $feature = $variables['node']->feature;
  3. $map_positions = array();
  4. // expand the feature 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 maps associated with this feature
  9. $options = array(
  10. 'return_array' => 1,
  11. 'order_by' => array('map_feature_id' => 'ASC'),
  12. 'pager' => array('limit' => $num_results_per_page, 'element' => $featurepos_pager_id),
  13. 'include_fk' => array(
  14. 'map_feature_id' => array(
  15. 'type_id' => 1,
  16. 'organism_id' => 1,
  17. ),
  18. 'featuremap_id' => array(
  19. 'unittype_id' => 1,
  20. ),
  21. ),
  22. );
  23. $feature = tripal_core_expand_chado_vars($feature, 'table', 'featurepos', $options);
  24. // because the featurepos table has FK relationships with map_feature_id and feature_id with the feature table
  25. // the function call above will try to expand both and will create an array of matches for each FK.
  26. // we only want to show the map that this feature belongs to
  27. $map_positions = $feature->featurepos->feature_id;
  28. // create the pager.
  29. $featurepos_pager = theme('pager', array(), $num_results_per_page, $featurepos_pager_id, array('block' => 'featurepos'));
  30. if(count($map_positions) > 0){ ?>
  31. <div id="tripal_feature-featurepos-box" class="tripal_feature-info-box tripal-info-box">
  32. <div class="tripal_feature-info-box-title tripal-info-box-title">Maps</div>
  33. <div class="tripal_feature-info-box-desc tripal-info-box-desc">This feature is contained in the following maps:</div>
  34. <table id="tripal_feature-featurepos-table" class="tripal_feature-table tripal-table tripal-table-horz">
  35. <tr>
  36. <th>Map Name</th>
  37. <th>Landmark</th>
  38. <th>Type</th>
  39. <th>Position</th>
  40. </tr> <?php
  41. $i = 0;
  42. foreach ($map_positions as $position){
  43. $map_feature = $position->map_feature_id;
  44. // check if there are any values in the featureposprop table for the start and stop
  45. $mappos = $position->mappos;
  46. $options = array(
  47. 'return_array' => 1,
  48. 'include_fk' => array(
  49. 'type_id' => 1,
  50. ),
  51. );
  52. $position = tripal_core_expand_chado_vars($position, 'table', 'featureposprop', $options);
  53. $featureposprop = $position->featureposprop;
  54. if (is_array($featureposprop)) {
  55. foreach ($featureposprop as $index => $property) {
  56. if ($property->type_id->name == 'start') {
  57. $start = $property->value;
  58. }
  59. if ($property->type_id->name == 'stop') {
  60. $stop = $property->value;
  61. }
  62. }
  63. }
  64. if ($start and $stop and $start != $stop) {
  65. $mappos = "$start-$stop";
  66. }
  67. if ($start and !$stop) {
  68. $mappos = $start;
  69. }
  70. if ($start and $stop and $start == $stop) {
  71. $mappos = $start;
  72. }
  73. $class = 'tripal_feature-table-odd-row tripal-table-odd-row';
  74. if($i % 2 == 0 ){
  75. $class = 'tripal_feature-table-even-row tripal-table-even-row';
  76. } ?>
  77. <tr class="<?php print $class ?>">
  78. <td> <?php
  79. if ($position->featuremap_id->nid) {
  80. print l($position->featuremap_id->name, 'node/' . $position->featuremap_id->nid, array('attributes' => array('target' => '_blank')));
  81. }
  82. else {
  83. print $position->featuremap_id->name;
  84. } ?>
  85. </td>
  86. <td> <?php
  87. if ($map_feature->nid) {
  88. print l($map_feature->name, 'node/' . $map_feature->nid, array('attributes' => array('target' => '_blank')));
  89. }
  90. else {
  91. print $map_feature->name;
  92. } ?>
  93. </td>
  94. <td><?php print $map_feature->type_id->name ?></td>
  95. <td><?php print $mappos ?> <?php print $position->featuremap_id->unittype_id->name ?> </td>
  96. </tr> <?php
  97. $i++;
  98. } ?>
  99. </table> <?php
  100. print $featurepos_pager ?>
  101. </div><?php
  102. }?>