tripal_contact_relationships.tpl.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // this template does not follow the typical Tripal API. Normally
  3. // variables are expanded using the tripal_core_expand_chado_vars API
  4. // function call, but expanding the relationships table does not yeild
  5. // a meaningful order to the data. Therefore, relationships are preprocessed
  6. // into an array named 'all_relationships', which is used in the template below.
  7. $contact = $variables['node']->contact;
  8. $all_relationships = $contact->all_relationships;
  9. $object_rels = $all_relationships['object'];
  10. $subject_rels = $all_relationships['subject'];
  11. // make the contact type a bit more human readable
  12. $contact_type = preg_replace("/_/", ' ', $contact->type_id->name);
  13. if (count($object_rels) > 0 or count($subject_rels) > 0) {
  14. ?>
  15. <div id="tripal_contact-relationships-box" class="tripal_contact-info-box tripal-info-box">
  16. <div class="tripal_contact-info-box-title tripal-info-box-title">Relationships</div>
  17. <!-- <div class="tripal_contact-info-box-desc tripal-info-box-desc"></div> --><?php
  18. // first add in the subject relationships.
  19. foreach ($subject_rels as $rel_type => $rels){
  20. // make the type a bit more human readable
  21. $rel_type = preg_replace("/_/", ' ', $rel_type);
  22. $rel_type = preg_replace("/^is/", '', $rel_type);
  23. // iterate through each parent
  24. foreach ($rels as $obj_type => $objects){?>
  25. <p>This contact is a <b><?php print $rel_type ?></b> of the following contact(s):
  26. <table id="tripal_contact-relationships_as_object-table" class="tripal_contact-table tripal-table tripal-table-horz">
  27. <tr>
  28. <th>contact Name</th>
  29. </tr> <?php
  30. foreach ($objects as $object){ ?>
  31. <tr>
  32. <td><?php
  33. if ($object->nid) {
  34. print "<a href=\"" . url("node/" . $object->nid) . "\" target=\"_blank\">" . $object->name . "</a>";
  35. }
  36. else {
  37. print $object->name;
  38. } ?>
  39. </td>
  40. </tr> <?php
  41. } ?>
  42. </table>
  43. </p><br><?php
  44. }
  45. }
  46. // second add in the object relationships.
  47. foreach ($object_rels as $rel_type => $rels){
  48. // make the type more human readable
  49. $rel_type = preg_replace('/_/', ' ', $rel_type);
  50. $rel_type = preg_replace("/^is/", '', $rel_type);
  51. // iterate through the children
  52. foreach ($rels as $subject_type => $subjects){?>
  53. <p>The following contacts are a <b><?php print $rel_type ?></b> of this contact:
  54. <table id="tripal_contact-relationships_as_object-table" class="tripal_contact-table tripal-table tripal-table-horz">
  55. <tr>
  56. <th>Name</th>
  57. </tr> <?php
  58. foreach ($subjects as $subject){ ?>
  59. <tr>
  60. <td><?php
  61. if ($subject->nid) {
  62. print "<a href=\"" . url("node/" . $subject->nid) . "\" target=\"_blank\">" . $subject->name . "</a>";
  63. }
  64. else {
  65. print $subject->name;
  66. } ?>
  67. </td>
  68. </tr> <?php
  69. } ?>
  70. </table>
  71. </p><br><?php
  72. }
  73. } ?>
  74. </div> <?php
  75. }