tripal_contact_relationships.tpl.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /* Typically in a Tripal template, the data needed is retrieved using a call to
  3. * chado_expand_var function. For example, to retrieve all
  4. * of the contact relationships for this node, the following function call would be made:
  5. *
  6. * $contact = chado_expand_var($contact,'table','contact_relationship');
  7. *
  8. * However, this function call can be extremely slow when there are numerous relationships.
  9. * This is because the chado_expand_var 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 class="tripal_contact-data-block-desc tripal-data-block-desc"></div> <?php
  25. // first add in the subject relationships.
  26. foreach ($subject_rels as $rel_type => $rels){
  27. foreach ($rels as $obj_type => $objects){ ?>
  28. <p>This <?php print strtolower($contact->type_id->name);?> <b><?php print $rel_type ?></b> with the following <?php print strtolower($obj_type) ?> contact(s): <?php
  29. // the $headers array is an array of fields to use as the colum headers.
  30. // additional documentation can be found here
  31. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  32. $headers = array('Name');
  33. // the $rows array contains an array of rows where each row is an array
  34. // of values for each column of the table in that row. Additional documentation
  35. // can be found here:
  36. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  37. $rows = array();
  38. foreach ($objects as $object){
  39. // link the contact to it's node
  40. $contact_name = $object->record->object_id->name;
  41. if (property_exists($object->record, 'nid')) {
  42. $contact_name = "<a href=\"" . url("node/" . $object->record->nid) . "\" target=\"_blank\">" . $object->record->object_id->name . "</a>";
  43. }
  44. $rows[] = array(
  45. $contact_name,
  46. );
  47. }
  48. // the $table array contains the headers and rows array as well as other
  49. // options for controlling the display of the table. Additional
  50. // documentation can be found here:
  51. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  52. $table = array(
  53. 'header' => $headers,
  54. 'rows' => $rows,
  55. 'attributes' => array(
  56. 'id' => 'tripal_contact-table-relationship-object',
  57. 'class' => 'tripal-data-table'
  58. ),
  59. 'sticky' => FALSE,
  60. 'caption' => '',
  61. 'colgroups' => array(),
  62. 'empty' => '',
  63. );
  64. // once we have our table array structure defined, we call Drupal's theme_table()
  65. // function to generate the table.
  66. print theme_table($table); ?>
  67. </p>
  68. <br><?php
  69. }
  70. }
  71. // second add in the object relationships.
  72. foreach ($object_rels as $rel_type => $rels){
  73. foreach ($rels as $subject_type => $subjects){?>
  74. <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
  75. // the $headers array is an array of fields to use as the colum headers.
  76. // additional documentation can be found here
  77. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  78. $headers = array('Name');
  79. // the $rows array contains an array of rows where each row is an array
  80. // of values for each column of the table in that row. Additional documentation
  81. // can be found here:
  82. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  83. $rows = array();
  84. foreach ($subjects as $subject){
  85. // link the contact to it's node
  86. $contact_name = $subject->record->subject_id->name;
  87. if (property_exists($subject->record, 'nid')) {
  88. $contact_name = "<a href=\"" . url("node/" . $subject->record->nid) . "\" target=\"_blank\">" . $subject->record->subject_id->name . "</a>";
  89. }
  90. $rows[] = array(
  91. $contact_name,
  92. );
  93. }
  94. // the $table array contains the headers and rows array as well as other
  95. // options for controlling the display of the table. Additional
  96. // documentation can be found here:
  97. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  98. $table = array(
  99. 'header' => $headers,
  100. 'rows' => $rows,
  101. 'attributes' => array(
  102. 'id' => 'tripal_contact-table-relationship-subject',
  103. 'class' => 'tripal-data-table'
  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. }