tripal_example_relationships.tpl.php

1 theme call to tripal_example_relationships.tpl.php
tripal_example_node_view in tripal_example/includes/tripal_example.chado_node.inc
Implementation of hook_node_view().

File

tripal_example/theme/templates/tripal_example_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 of the example
  4. * relationships for this node, the following function call would be made:
  5. *
  6. * $example = chado_expand_var($example,'table','example_relationship');
  7. *
  8. * However, this function call can be extremely slow when there are numerous
  9. * relationships. This is because the chado_expand_var function is recursive and
  10. * expands all data following the foreign key relationships tree. Therefore, to
  11. * speed retrieval of data, a special variable is provided to this template:
  12. *
  13. * $example->all_relationships;
  14. *
  15. * This variable is an array with two sub arrays with the keys 'object' and
  16. * 'subject'. The array with key 'object' contains relationships where the
  17. * example is the object, and the array with the key 'subject' contains
  18. * relationships where the example is the subject.
  19. */
  20. $example = $variables['node']->example;
  21. $all_relationships = $example->all_relationships;
  22. $object_rels = $all_relationships['object'];
  23. $subject_rels = $all_relationships['subject'];
  24. if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
  25. <div class="tripal_example-data-block-desc tripal-data-block-desc"></div> <?php
  26. // first add in the subject relationships.
  27. foreach ($subject_rels as $rel_type => $rels){
  28. foreach ($rels as $obj_type => $objects){ ?>
  29. <p>This <?php print $example->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> example(s): <?php
  30. // the $headers array is an array of fields to use as the colum headers.
  31. // additional documentation can be found here
  32. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  33. $headers = array('Publication');
  34. // the $rows array contains an array of rows where each row is an array
  35. // of values for each column of the table in that row. Additional
  36. // documentation can be found here:
  37. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  38. $rows = array();
  39. foreach ($objects as $object){
  40. // link the example to it's node
  41. $title = $object->record->object_id->title;
  42. if (property_exists($object->record, 'nid')) {
  43. $title = l($title, "node/" . $object->record->nid, array('attributes' => array('target' => "_blank")));
  44. }
  45. // get the citation
  46. $values = array(
  47. 'example_id' => $object->record->object_id->example_id,
  48. 'type_id' => array(
  49. 'name' => 'Citation',
  50. ),
  51. );
  52. $citation = chado_generate_var('exampleprop', $values);
  53. $citation = chado_expand_var($citation, 'field', 'exampleprop.value');
  54. $rows[] = array(
  55. $title . '<br>' . htmlspecialchars($citation->value),
  56. );
  57. }
  58. // the $table array contains the headers and rows array as well as other
  59. // options for controlling the display of the table. Additional
  60. // documentation can be found here:
  61. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  62. $table = array(
  63. 'header' => $headers,
  64. 'rows' => $rows,
  65. 'attributes' => array(
  66. 'id' => 'tripal_example-table-relationship-object',
  67. 'class' => 'tripal-data-table'
  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
  75. // theme_table() 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> example(s) are <?php print $rel_type ?> this <?php print $example->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
  91. // documentation 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 example 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. 'example_id' => $subject->record->subject_id->example_id,
  103. 'type_id' => array(
  104. 'name' => 'Citation',
  105. ),
  106. );
  107. $citation = chado_generate_var('exampleprop', $values);
  108. $citation = chado_expand_var($citation, 'field', 'exampleprop.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_example-table-relationship-subject',
  122. 'class' => 'tripal-data-table'
  123. ),
  124. 'sticky' => FALSE,
  125. 'caption' => '',
  126. 'colgroups' => array(),
  127. 'empty' => '',
  128. );
  129. // once we have our table array structure defined, we call Drupal's
  130. // theme_table() function to generate the table.
  131. print theme_table($table); ?>
  132. </p>
  133. <br><?php
  134. }
  135. }
  136. }