tripal_pub_relationships.tpl.php

  1. 2.x tripal_pub/theme/templates/tripal_pub_relationships.tpl.php
  2. 3.x legacy/tripal_pub/theme/templates/tripal_pub_relationships.tpl.php
1 theme call to tripal_pub_relationships.tpl.php
tripal_pub_node_view in tripal_pub/includes/tripal_pub.chado_node.inc
Implements hook_node_view(). Acts on all content types.

File

tripal_pub/theme/templates/tripal_pub_relationships.tpl.php
View source
  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. }