tripal_feature_relationships.tpl.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. $feature = $variables['node']->feature;
  3. // expand the feature object to include the feature relationships.
  4. // since there two foreign keys (object_id and subject_id) in the
  5. // feature_relationship table, we will access each one separately
  6. $feature = tripal_core_expand_chado_vars($feature,
  7. 'table','feature_relationship', array('order_by'=>array('rank' => 'ASC')));
  8. // get the featurelocs. if only one featureloc exists then we want to convert
  9. // the object into an array, otherwise the value is an array
  10. $orelationships = $feature->feature_relationship->object_id;
  11. if (!$orelationships) {
  12. $orelationships = array();
  13. } elseif (!is_array($orelationships)) {
  14. $orelationships = array($orelationships);
  15. }
  16. // do the same for the subject relationships
  17. $srelationships = $feature->feature_relationship->subject_id;
  18. if (!$srelationships) {
  19. $srelationships = array();
  20. } elseif (!is_array($srelationships)) {
  21. $srelationships = array($srelationships);
  22. }
  23. // now combine the two
  24. $relationships = array_merge($orelationships,$srelationships);
  25. ?>
  26. <div id="tripal_feature-relationships-box" class="tripal_feature-info-box tripal-info-box">
  27. <div class="tripal_feature-info-box-title tripal-info-box-title">Relationships</div>
  28. <div class="tripal_feature-info-box-desc tripal-info-box-desc">Subject relationships</div>
  29. <?php if(count($srelationships) > 0){ ?>
  30. <table id="tripal_feature-subject_relationships-table" class="tripal_feature-table tripal-table tripal-table-horz">
  31. <tr>
  32. <th>Subject</th>
  33. <th>Type</th>
  34. <th>Relationship</th>
  35. <th>Object</th>
  36. <th>Type</th>
  37. </tr>
  38. <?php
  39. $i = 0;
  40. foreach ($srelationships as $relationship){
  41. $class = 'tripal_feature-table-odd-row tripal-table-odd-row';
  42. if($i % 2 == 0 ){
  43. $class = 'tripal_feature-table-odd-row tripal-table-even-row';
  44. }
  45. $subject_name = $relationship->subject_id->name;
  46. if(!$subject_name){
  47. $subject_name = $relationship->subject_id->uniquename;
  48. }
  49. $object_name = $relationship->object_id->name;
  50. if(!$object_name){
  51. $object_name = $relationship->object_id->uniquename;
  52. }?>
  53. <tr class="<?php print $class ?>">
  54. <td><?php print $subject_name?></td>
  55. <td><?php print $relationship->subject_id->type_id->name?></td>
  56. <td><b><?php print $relationship->type_id->name?></b></td>
  57. <td>
  58. <?php if(isset($relationship->object_id->nid)){
  59. print "<a href=\"" . url("node/".$relationship->object_id->nid) . "\">$object_name</a>";
  60. } else {
  61. print "$object_name";
  62. }?>
  63. </td>
  64. <td><?php print $relationship->object_id->type_id->name?></td>
  65. </tr>
  66. <?php } ?>
  67. </table>
  68. <?php } else {?>
  69. <div class="tripal-no-results">There are no subject relationships for this feature</div>
  70. <?php } ?>
  71. <br><br><div class="tripal_feature-info-box-desc tripal-info-box-desc">Object relationships</div>
  72. <?php if(count($orelationships) > 0){ ?>
  73. <table id="tripal_feature-object_relationships-table" class="tripal_feature-table tripal-table tripal-table-horz">
  74. <tr>
  75. <th>Subject</th>
  76. <th>Type</th>
  77. <th>Relationship</th>
  78. <th>Object</th>
  79. <th>Type</th>
  80. </tr>
  81. <?php
  82. $i = 0;
  83. foreach ($orelationships as $relationship){
  84. $class = 'tripal_feature-table-odd-row tripal-table-odd-row';
  85. if($i % 2 == 0 ){
  86. $class = 'tripal_feature-table-odd-row tripal-table-even-row';
  87. }
  88. $subject_name = $relationship->subject_id->name;
  89. if(!$subject_name){
  90. $subject_name = $relationship->subject_id->uniquename;
  91. }
  92. $object_name = $relationship->object_id->name;
  93. if(!$object_name){
  94. $object_name = $relationship->object_id->uniquename;
  95. }?>
  96. <tr class="<?php print $class ?>">
  97. <td>
  98. <?php if(isset($relationship->subject_id->nid)){
  99. print "<a href=\"" . url("node/".$relationship->subject_id->nid) . "\">$subject_name</a>";
  100. } else {
  101. print "$subject_name";
  102. }?>
  103. </td>
  104. <td><?php print $relationship->subject_id->type_id->name?></td>
  105. <td><b><?php print $relationship->type_id->name?></b></td>
  106. <td><?php print "$object_name";?> </td>
  107. <td><?php print $relationship->object_id->type_id->name?></td>
  108. </tr>
  109. <?php } ?>
  110. </table>
  111. <?php } else {?>
  112. <div class="tripal-no-results">There are no object relationships for this feature</div>
  113. <?php } ?>
  114. </div>