tripal_contact_relationships.tpl.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 contact relationships for this node, the following function call would be made:
  5. *
  6. * $contact = tripal_core_expand_chado_vars($contact,'table','contact_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. * $contact->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 contact is the object, and the array with
  17. * the key 'subject' contains relationships where the contact is the subject
  18. */
  19. $contact = $variables['node']->contact;
  20. $all_relationships = $contact->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. <div id="tripal_contact-relationships-box" class="tripal_contact-info-box tripal-info-box">
  25. <div class="tripal_contact-info-box-title tripal-info-box-title">Relationships</div>
  26. <div class="tripal_contact-info-box-desc tripal-info-box-desc"></div> <?php
  27. // first add in the subject relationships.
  28. foreach ($subject_rels as $rel_type => $rels){
  29. foreach ($rels as $obj_type => $objects){ ?>
  30. <p>This <?php print $contact->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> contact(s): <?php
  31. // the $headers array is an array of fields to use as the colum headers.
  32. // additional documentation can be found here
  33. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  34. $headers = array('Name');
  35. // the $rows array contains an array of rows where each row is an array
  36. // of values for each column of the table in that row. Additional documentation
  37. // can be found here:
  38. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  39. $rows = array();
  40. foreach ($objects as $object){
  41. // link the contact to it's node
  42. $contact_name = $object->record->object_id->name;
  43. if (property_exists($object->record, 'nid')) {
  44. $contact_name = "<a href=\"" . url("node/" . $object->record->nid) . "\" target=\"_blank\">" . $object->record->object_id->name . "</a>";
  45. }
  46. $rows[] = array(
  47. $contact_name,
  48. );
  49. }
  50. // the $table array contains the headers and rows array as well as other
  51. // options for controlling the display of the table. Additional
  52. // documentation can be found here:
  53. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  54. $table = array(
  55. 'header' => $headers,
  56. 'rows' => $rows,
  57. 'attributes' => array(
  58. 'id' => 'tripal_contact-table-relationship-object',
  59. ),
  60. 'sticky' => FALSE,
  61. 'caption' => '',
  62. 'colgroups' => array(),
  63. 'empty' => '',
  64. );
  65. // once we have our table array structure defined, we call Drupal's theme_table()
  66. // function to generate the table.
  67. print theme_table($table); ?>
  68. </p>
  69. <br><?php
  70. }
  71. }
  72. // second add in the object relationships.
  73. foreach ($object_rels as $rel_type => $rels){
  74. foreach ($rels as $subject_type => $subjects){?>
  75. <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> contact(s) are <?php print $rel_type ?> this <?php print $contact->type_id->name;?>: <?php
  76. // the $headers array is an array of fields to use as the colum headers.
  77. // additional documentation can be found here
  78. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  79. $headers = array('Name');
  80. // the $rows array contains an array of rows where each row is an array
  81. // of values for each column of the table in that row. Additional documentation
  82. // can be found here:
  83. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  84. $rows = array();
  85. foreach ($subjects as $subject){
  86. // link the contact to it's node
  87. $contact_name = $subject->record->subject_id->name;
  88. if (property_exists($subject->record, 'nid')) {
  89. $contact_name = "<a href=\"" . url("node/" . $subject->record->nid) . "\" target=\"_blank\">" . $subject->record->subject_id->name . "</a>";
  90. }
  91. $rows[] = array(
  92. $contact_name,
  93. );
  94. }
  95. // the $table array contains the headers and rows array as well as other
  96. // options for controlling the display of the table. Additional
  97. // documentation can be found here:
  98. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  99. $table = array(
  100. 'header' => $headers,
  101. 'rows' => $rows,
  102. 'attributes' => array(
  103. 'id' => 'tripal_contact-table-relationship-subject',
  104. ),
  105. 'sticky' => FALSE,
  106. 'caption' => '',
  107. 'colgroups' => array(),
  108. 'empty' => '',
  109. );
  110. // once we have our table array structure defined, we call Drupal's theme_table()
  111. // function to generate the table.
  112. print theme_table($table); ?>
  113. </p>
  114. <br><?php
  115. }
  116. }?>
  117. </div> <?php
  118. }