tripal_pub_relationships.tpl.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 pub relationships for this node, the following function call would be made:
  5. *
  6. * $pub = chado_expand_var($pub,'table','pub_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. * $pub->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 pub is the object, and the array with
  17. * the key 'subject' contains relationships where the pub is the subject
  18. */
  19. $pub = $variables['node']->pub;
  20. $all_relationships = $pub->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_pub-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 $pub->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> pub(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('Publication');
  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 pub to it's node
  40. $title = $object->record->object_id->title;
  41. if (property_exists($object->record, 'nid')) {
  42. $title = l($title, "node/" . $object->record->nid, array('attributes' => array('target' => "_blank")));
  43. }
  44. // get the citation
  45. $values = array(
  46. 'pub_id' => $object->record->object_id->pub_id,
  47. 'type_id' => array(
  48. 'name' => 'Citation',
  49. ),
  50. );
  51. $citation = chado_generate_var('pubprop', $values);
  52. $citation = chado_expand_var($citation, 'field', 'pubprop.value');
  53. $rows[] = array(
  54. $title . '<br>' . htmlspecialchars($citation->value),
  55. );
  56. }
  57. // the $table array contains the headers and rows array as well as other
  58. // options for controlling the display of the table. Additional
  59. // documentation can be found here:
  60. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  61. $table = array(
  62. 'header' => $headers,
  63. 'rows' => $rows,
  64. 'attributes' => array(
  65. 'id' => 'tripal_pub-table-relationship-object',
  66. 'class' => 'tripal-data-table'
  67. ),
  68. 'sticky' => FALSE,
  69. 'caption' => '',
  70. 'colgroups' => array(),
  71. 'empty' => '',
  72. );
  73. // once we have our table array structure defined, we call Drupal's theme_table()
  74. // function to generate the table.
  75. print theme_table($table); ?>
  76. </p>
  77. <br><?php
  78. }
  79. }
  80. // second add in the object relationships.
  81. foreach ($object_rels as $rel_type => $rels){
  82. foreach ($rels as $subject_type => $subjects){?>
  83. <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> pub(s) are <?php print $rel_type ?> this <?php print $pub->type_id->name;?>: <?php
  84. // the $headers array is an array of fields to use as the colum headers.
  85. // additional documentation can be found here
  86. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  87. $headers = array('Publication');
  88. // the $rows array contains an array of rows where each row is an array
  89. // of values for each column of the table in that row. Additional documentation
  90. // can be found here:
  91. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  92. $rows = array();
  93. foreach ($subjects as $subject){
  94. // link the pub to it's node
  95. $title = $subject->record->subject_id->title;
  96. if (property_exists($subject->record, 'nid')) {
  97. $title = l($title, "node/" . $subject->record->nid, array('attributes' => array('target' => "_blank")));
  98. }
  99. // get the citation
  100. $values = array(
  101. 'pub_id' => $subject->record->subject_id->pub_id,
  102. 'type_id' => array(
  103. 'name' => 'Citation',
  104. ),
  105. );
  106. $citation = chado_generate_var('pubprop', $values);
  107. $citation = chado_expand_var($citation, 'field', 'pubprop.value');
  108. $rows[] = array(
  109. $title . '<br>' . htmlspecialchars($citation->value),
  110. );
  111. }
  112. // the $table array contains the headers and rows array as well as other
  113. // options for controlling the display of the table. Additional
  114. // documentation can be found here:
  115. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  116. $table = array(
  117. 'header' => $headers,
  118. 'rows' => $rows,
  119. 'attributes' => array(
  120. 'id' => 'tripal_pub-table-relationship-subject',
  121. 'class' => 'tripal-data-table'
  122. ),
  123. 'sticky' => FALSE,
  124. 'caption' => '',
  125. 'colgroups' => array(),
  126. 'empty' => '',
  127. );
  128. // once we have our table array structure defined, we call Drupal's theme_table()
  129. // function to generate the table.
  130. print theme_table($table); ?>
  131. </p>
  132. <br><?php
  133. }
  134. }
  135. }