tripal_pub_relationships.tpl.php 6.5 KB

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