tripal_feature_relationships.tpl.php 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /* Typically in a Tripal template, the data needed is retrieved using a call to
  3. * tripal_core_expand_chado_vars function. For example, to retrieve all
  4. * of the feature relationships for this node, the following function call would be made:
  5. *
  6. * $feature = tripal_core_expand_chado_vars($feature,'table','feature_relationship');
  7. *
  8. * However, this function call can be extremely slow when there are numerous relationships.
  9. * This is because the tripal_core_expand_chado_vars function is recursive and expands
  10. * all data following the foreign key relationships tree. Therefore, to speed retrieval
  11. * of data, a special variable is provided to this template:
  12. *
  13. * $feature->all_relationships;
  14. *
  15. * This variable is an array with two sub arrays with the keys 'object' and 'subject'. The array with
  16. * key 'object' contains relationships where the feature is the object, and the array with
  17. * the key 'subject' contains relationships where the feature is the subject
  18. */
  19. $feature = $variables['node']->feature;
  20. $all_relationships = $feature->all_relationships;
  21. $object_rels = $all_relationships['object'];
  22. $subject_rels = $all_relationships['subject'];
  23. if (count($object_rels) > 0 or count($subject_rels) > 0) {
  24. ?>
  25. <div id="tripal_feature-relationships-box" class="tripal_feature-info-box tripal-info-box">
  26. <div class="tripal_feature-info-box-title tripal-info-box-title">Relationships</div>
  27. <div class="tripal_feature-info-box-desc tripal-info-box-desc"></div> <?php
  28. // first add in the subject relationships.
  29. foreach ($subject_rels as $rel_type => $rels){
  30. foreach ($rels as $obj_type => $objects){?>
  31. <p>This <?php print $feature->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> feature(s):
  32. <table id="tripal_feature-relationships_as_object-table" class="tripal_feature-table tripal-table tripal-table-horz">
  33. <tr>
  34. <th>Feature Name</th>
  35. <th>Unique Name</th>
  36. <th>Species</th>
  37. <th>Type</th>
  38. </tr> <?php
  39. foreach ($objects as $object){ ?>
  40. <tr>
  41. <td><?php
  42. if ($object->record->nid) {
  43. print "<a href=\"" . url("node/" . $object->record->nid) . "\" target=\"_blank\">" . $object->record->object_id->name . "</a>";
  44. }
  45. else {
  46. print $object->record->object_id->name;
  47. } ?>
  48. </td>
  49. <td><?php print $object->record->object_id->uniquename ?></td>
  50. <td><?php print $object->record->object_id->organism_id->genus . " " . $object->record->object_id->organism_id->species; ?></td>
  51. <td><?php print $object->record->object_id->type_id->name ?></td>
  52. </tr> <?php
  53. } ?>
  54. </table>
  55. </p><br><?php
  56. }
  57. }
  58. // second add in the object relationships.
  59. foreach ($object_rels as $rel_type => $rels){
  60. foreach ($rels as $subject_type => $subjects){?>
  61. <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> feature(s) are <?php print $rel_type ?> this <?php print $feature->type_id->name;?>:
  62. <table id="tripal_feature-relationships_as_object-table" class="tripal_feature-table tripal-table tripal-table-horz">
  63. <tr>
  64. <th>Feature Name</th>
  65. <th>Unique Name</th>
  66. <th>Species</th>
  67. <th>Type</th>
  68. </tr> <?php
  69. foreach ($subjects as $subject){ ?>
  70. <tr>
  71. <td><?php
  72. if ($subject->record->nid) {
  73. print "<a href=\"" . url("node/" . $subject->record->nid) . "\" target=\"_blank\">" . $subject->record->subject_id->name . "</a>";
  74. }
  75. else {
  76. print $subject->record->subject_id->name;
  77. } ?>
  78. </td>
  79. <td><?php print $subject->record->subject_id->uniquename ?></td>
  80. <td><?php print $subject->record->subject_id->organism_id->genus . " " . $subject->record->subject_id->organism_id->species; ?></td>
  81. <td><?php print $subject->record->subject_id->type_id->name ?></td>
  82. </tr> <?php
  83. } ?>
  84. </table>
  85. </p><br><?php
  86. }
  87. }
  88. ?>
  89. </div> <?php
  90. }